Build a failed initramfs again, and don't offer a reboot until it builds

When mkinitcpio fails during an update or install, run it once more. If
that fails too, say why (a full /boot, a hook or module that isn't
installed) and don't offer a reboot. The install now logs its upgrade and
checks the build before finish-install offers one, and nvidia.sh's rebuild
no longer stops the install. A failed build is carried into the next
update's log, so it's rebuilt and checked until it builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 07:34:51 -07:00
co-authored by Claude Opus 5.5
parent 16e5a9c79d
commit d456e31192
8 changed files with 230 additions and 23 deletions
+26
View File
@@ -98,3 +98,29 @@ answer() {
[[ "$output" != *"Reboot now?"* ]]
not_called systemctl
}
@test "finish-install doesn't offer a reboot while the initramfs doesn't build" {
KERNEL=0.0.0-not-installed
mkdir -p "$HOME/.local/state/coredesktop"
printf '%s\n' "(3/4) Updating linux initcpios..." "==> ERROR: module not found: 'nvidia'" \
> "$HOME/.local/state/coredesktop/pacman-update.log"
stub systemctl
answer y
run bash "$REPO/system/finish-install.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"CoreDesktop is installed."*"Don't reboot yet"*"Once it builds"* ]]
[[ "$output" != *"Reboot now?"* ]]
not_called systemctl
}
@test "finish-install still offers configure while the initramfs doesn't build, if the kernel is current" {
needs_modules
ITEMS="to do core Federated Core"
mkdir -p "$HOME/.local/state/coredesktop"
printf '%s\n' "(3/4) Updating linux initcpios..." "==> ERROR: module not found: 'nvidia'" \
> "$HOME/.local/state/coredesktop/pacman-update.log"
run bash "$REPO/system/finish-install.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Don't reboot yet"*"configure connects"* ]]
[[ "$output" != *"no reboot needed"* ]]
}
+85
View File
@@ -275,6 +275,91 @@ pacman_log() {
[ "$status" -eq 0 ]
}
@test "initramfs_build_failed reads only the last build: a rebuild that worked clears it" {
pacman_log "(3/4) Updating linux initcpios..." \
"==> ERROR: Hook 'sd-plymouth' cannot be found" \
"==> CoreDesktop: rebuilding the initramfs (mkinitcpio -P)" \
"==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'" \
"==> Image generation successful"
run initramfs_build_failed
[ "$status" -ne 0 ]
}
@test "initramfs_build_failed is true when the rebuild failed too" {
pacman_log "(3/4) Updating linux initcpios..." \
"==> Image generation successful" \
"==> CoreDesktop: rebuilding the initramfs (mkinitcpio -P)" \
"==> ERROR: module not found: 'nvidia'"
run initramfs_build_failed
[ "$status" -eq 0 ]
}
@test "new_pacman_log carries a failed build over, and only a failed one" {
pacman_log "(3/4) Updating linux initcpios..." "==> ERROR: module not found: 'nvidia'"
new_pacman_log
initramfs_build_failed
[ "$(wc -l < "$PACMAN_UPDATE_LOG")" -eq 1 ]
# Carried over again by the next update that builds nothing
new_pacman_log
initramfs_build_failed
pacman_log "(3/4) Updating linux initcpios..." \
"==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'" \
"==> Image generation successful"
new_pacman_log
[ ! -s "$PACMAN_UPDATE_LOG" ]
}
# mkinitcpio -P through a fake sudo: it builds unless $MKINITCPIO_FAILS is set
fake_mkinitcpio() {
stub sudo 'echo "==> Building image from preset: /etc/mkinitcpio.d/linux.preset: '"'"'default'"'"'"
if [ -n "$MKINITCPIO_FAILS" ]; then echo "$MKINITCPIO_FAILS"; exit 1; fi
echo "==> Image generation successful"'
stub df 'printf "Avail\n%sM\n" "${BOOT_FREE:-500}"'
}
@test "check_initramfs does nothing when the build worked" {
pacman_log "(3/4) Updating linux initcpios..." \
"==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'" \
"==> Image generation successful"
fake_mkinitcpio
run check_initramfs
[ "$status" -eq 0 ]
not_called sudo
}
@test "check_initramfs builds it again, and is fine when that works" {
pacman_log "(3/4) Updating linux initcpios..." "==> ERROR: module not found: 'nvidia'"
fake_mkinitcpio
run check_initramfs
[ "$status" -eq 0 ]
[[ "$output" == *"Trying again"*"built this time"* ]]
called sudo mkinitcpio -P
refute initramfs_build_failed
}
@test "check_initramfs names a missing hook when building again fails too" {
pacman_log "(3/4) Updating linux initcpios..." "==> ERROR: Hook 'sd-plymouth' cannot be found"
fake_mkinitcpio
export MKINITCPIO_FAILS="==> ERROR: Hook 'sd-plymouth' cannot be found"
run check_initramfs
[ "$status" -eq 1 ]
[[ "$output" == *"Don't reboot until it's fixed"* ]]
[[ "$output" == *"HOOKS lists 'sd-plymouth'"* ]]
[[ "$output" != *"/boot is nearly full"* ]]
initramfs_build_failed
}
@test "explain_initramfs_failure says when /boot is full, and names a missing module" {
pacman_log "(3/4) Updating linux initcpios..." \
"==> ERROR: module not found: 'nvidia'" \
"cp: error writing '/boot/initramfs-linux.img': No space left on device"
fake_mkinitcpio
BOOT_FREE=3 run explain_initramfs_failure
[[ "$output" == *"/boot is nearly full (3 MB free)"* ]]
[[ "$output" == *"MODULES lists 'nvidia'"* ]]
}
# --- mirrors ----------------------------------------------------------------
setup_mirrors() {