diff --git a/install.sh b/install.sh index 8657b7f..68e68a9 100755 --- a/install.sh +++ b/install.sh @@ -145,7 +145,11 @@ ensure_federated_repo # Bring the system fully up to date before installing anything new echo "Updating system..." -sudo pacman -Sy --needed --noconfirm archlinux-keyring +# kernel-modules-hook first, in a transaction of its own so its hooks are loaded +# for the upgrade: if the upgrade replaces the kernel, it keeps the running +# kernel's modules, which the rest of the install (Docker, the firewall) needs +# until the reboot it ends with +sudo pacman -Sy --needed --noconfirm archlinux-keyring kernel-modules-hook # Logged for check_initramfs, before finish-install offers a reboot. Not # through script(1): this file is usually piped into bash, and script would # read the rest of it from stdin. diff --git a/packages.conf b/packages.conf index 077c18f..ab19f39 100644 --- a/packages.conf +++ b/packages.conf @@ -111,6 +111,9 @@ MAINTENANCE=( gnome-extra gnome-keyring pacman-contrib + # Keeps the running kernel's modules after a kernel upgrade, until a reboot + # (install.sh installs it before anything else) + kernel-modules-hook # Keeps the mirrorlist on up-to-date mirrors (system/mirrors.sh) reflector ) @@ -164,6 +167,8 @@ SERVICES=( cups.service fwupd-refresh.timer gdm.service + # kernel-modules-hook's: removes the old kernel's kept modules after a reboot + linux-modules-cleanup.service NetworkManager.service reflector.timer sshd.service diff --git a/system/finish-install.sh b/system/finish-install.sh index 6a671be..26fcce3 100644 --- a/system/finish-install.sh +++ b/system/finish-install.sh @@ -15,20 +15,20 @@ CONFIGURE_HINT="configure connects to your Federated Core, sets up backups and s echo echo -e "\e[32mCoreDesktop is installed.\e[0m" -# If the running kernel's modules are gone, a newer kernel was installed during -# this run. configure waits for the reboot: until then, modules it needs, such -# as Tailscale's tun and davfs2's fuse, can't be loaded. The reboot waits for -# the initramfs to build. +# If a newer kernel was installed during this run, configure waits for the +# reboot: until then, the modules it needs (Tailscale's tun, davfs2's fuse) are +# at best kernel-modules-hook's temporary copy. The reboot waits for the +# initramfs to build. if initramfs_build_failed; then # check_initramfs (install.sh) has said why; offering a reboot now could # leave the computer unable to start echo -e "\e[31mDon't reboot yet: the initramfs doesn't build (see above, or $PACMAN_UPDATE_LOG).\e[0m" - if [ ! -d "/usr/lib/modules/$(uname -r)" ]; then + if newer_kernel_installed; then echo "Once it builds (sudo mkinitcpio -P), reboot, then run: configure" echo "$CONFIGURE_HINT" exit 0 fi -elif [ ! -d "/usr/lib/modules/$(uname -r)" ]; then +elif newer_kernel_installed; then echo "A newer kernel has been installed. Reboot, then run: configure" echo "$CONFIGURE_HINT" # The same as the system menu's restart: an active desktop session needs no password diff --git a/tests/finish-install.bats b/tests/finish-install.bats index 9c0eddf..99160c5 100644 --- a/tests/finish-install.bats +++ b/tests/finish-install.bats @@ -51,6 +51,16 @@ answer() { not_called configure } +@test "finish-install asks for a reboot when the running kernel's modules are only kernel-modules-hook's copy" { + export COREDESKTOP_MODULES_DIR="$BATS_TEST_TMPDIR/modules" + KERNEL=0.0.0-kept-by-hook + mkdir -p "$COREDESKTOP_MODULES_DIR/$KERNEL" + run bash "$REPO/system/finish-install.sh" + [ "$status" -eq 0 ] + [[ "$output" == *"A newer kernel has been installed. Reboot, then run: configure"* ]] + not_called configure +} + @test "finish-install says the install worked before offering configure" { needs_modules ITEMS="to do core Federated Core" diff --git a/tests/reboot-check.bats b/tests/reboot-check.bats new file mode 100644 index 0000000..b77e3c2 --- /dev/null +++ b/tests/reboot-check.bats @@ -0,0 +1,37 @@ +#!/usr/bin/env bats + +load test_helper + +# updates.d/99-reboot-check.sh, with a fake /usr/lib/modules and pacman + +setup() { + common_setup + mkdir -p "$HOME/.local/share" + ln -s "$REPO" "$HOME/.local/share/coredesktop" + export COREDESKTOP_MODULES_DIR="$BATS_TEST_TMPDIR/modules" + RUNNING="$COREDESKTOP_MODULES_DIR/$(uname -r)" + NEEDED="$HOME/.local/state/coredesktop/reboot-needed" + # pacman -Qo: the running kernel's modules belong to linux, unless OWNED is empty + export OWNED=linux + stub pacman '[ "$1" = -Qqo ] && [ -n "$OWNED" ] && echo "$OWNED"' +} + +@test "reboot check: nothing to do when the running kernel's modules are the installed kernel's" { + mkdir -p "$RUNNING" + run bash "$REPO/updates.d/99-reboot-check.sh" + [ "$status" -eq 0 ] + [ ! -e "$NEEDED" ] +} + +@test "reboot check: a reboot is needed when the running kernel's modules are gone" { + run bash "$REPO/updates.d/99-reboot-check.sh" + [[ "$output" == *"Please reboot"*"a newer kernel was installed"* ]] + [ "$(cat "$NEEDED")" = "a newer kernel was installed" ] +} + +@test "reboot check: a reboot is needed when they're only kernel-modules-hook's copy" { + mkdir -p "$RUNNING" + OWNED="" + run bash "$REPO/updates.d/99-reboot-check.sh" + [ "$(cat "$NEEDED")" = "a newer kernel was installed" ] +} diff --git a/tests/test_helper.bash b/tests/test_helper.bash index 65b491d..eb99c2b 100644 --- a/tests/test_helper.bash +++ b/tests/test_helper.bash @@ -18,7 +18,7 @@ common_setup() { # Set when the tests run inside a smoketest (a pre-push hook's checks, say), # where they would point the smoketest tests at the real VM unset VM_GIT_SSH VM_GIT_URL SMOKETEST_REPO SMOKETEST_RESULTS SMOKETEST_SHARED \ - SMOKETEST_REF SMOKETEST_VM_DIR IMAGE_REF VARIANT + SMOKETEST_REF SMOKETEST_VM_DIR SMOKETEST_CHAIN_FILE IMAGE_REF VARIANT } # A test file that needs more setup defines its own setup that calls this first diff --git a/updates.d/99-reboot-check.sh b/updates.d/99-reboot-check.sh index 14c4ef1..4add94f 100755 --- a/updates.d/99-reboot-check.sh +++ b/updates.d/99-reboot-check.sh @@ -17,8 +17,7 @@ fi reasons=() -# If the running kernel's modules are gone, a newer kernel was installed -if [ ! -d "/usr/lib/modules/$(uname -r)" ]; then +if newer_kernel_installed; then reasons+=("a newer kernel was installed") fi diff --git a/utils.sh b/utils.sh index 6c6e3ca..e9592cd 100755 --- a/utils.sh +++ b/utils.sh @@ -187,6 +187,15 @@ run_migrations() { done } +# True if a newer kernel was installed since this one booted: the running +# kernel's modules are gone, or are only kernel-modules-hook's copy of them, +# which no package owns +newer_kernel_installed() { + local modules + modules="${COREDESKTOP_MODULES_DIR:-/usr/lib/modules}/$(uname -r)" + [ ! -d "$modules" ] || ! pacman -Qqo "$modules" &> /dev/null +} + # Output of the last update's pacman -Su, written by updates.d/10-pacman.sh PACMAN_UPDATE_LOG="$HOME/.local/state/coredesktop/pacman-update.log" diff --git a/version b/version index 4881796..0fd0cfd 100755 --- a/version +++ b/version @@ -121,8 +121,7 @@ case "$kernel" in *) kernel_pkg="${kernel_pkg:-linux}" ;; esac -# If the running kernel's modules are gone, a newer kernel was installed -if [ ! -d "/usr/lib/modules/$kernel" ]; then +if newer_kernel_installed; then kernel="$kernel (newer kernel installed, reboot to use it)" fi if latest="$(newer_package "$kernel_pkg")"; then