From e106274658e66d3781b8f603eef7b486e6268992 Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 20:55:02 +1000 Subject: [PATCH 01/10] Require a Limine Mac's loader, menu and UKI on the system ESP U-Boot starts the loader on the ESP the device tree names. The boot check read Limine's files from ESP_PATH only, so a Mac whose ESP_PATH named another ESP passed with a loader U-Boot never boots. --- .../boot/bin/omarchy-apple-silicon-boot-check | 8 +++++ .../test/apple-silicon-boot-check-test.sh | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check b/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check index 1f56867d4bb0..84c5c1e89328 100755 --- a/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check +++ b/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check @@ -567,6 +567,14 @@ else fi sudo test -f "$mountpoint/m1n1/boot.bin" || fail "the system ESP ($esp) has no m1n1/boot.bin" +# U-Boot starts the loader on the system ESP, so the Limine, menu and UKI +# checked above must be the ones there. +if (( limine_mac )); then + for file in EFI/BOOT/BOOTAA64.EFI limine.conf "EFI/Linux/omarchy_$kernel.efi"; do + sudo cmp -s "$(path "$limine_esp/$file")" "$mountpoint/$file" || + fail "$limine_esp/$file is not the one on the system ESP ($esp), which U-Boot boots; point ESP_PATH in /etc/default/limine at that ESP's mountpoint, then run sudo omarchy-mac-boot-update and omarchy update" + done +fi report_running_release() { if (( pending_reboot )); then echo "Apple Silicon boot check: installed $kernel $kver boot files match; running $running_kver, reboot pending" diff --git a/packages/omarchy-mac/boot/test/apple-silicon-boot-check-test.sh b/packages/omarchy-mac/boot/test/apple-silicon-boot-check-test.sh index f0061ff3ff9f..783a2303b02f 100644 --- a/packages/omarchy-mac/boot/test/apple-silicon-boot-check-test.sh +++ b/packages/omarchy-mac/boot/test/apple-silicon-boot-check-test.sh @@ -626,6 +626,8 @@ limine_system() { local limine_esp=$1 fstab_row=$2 cmdline=$3 uki system linux-asahi mkdir -p "$root/var/lib/omarchy" "$root/etc" "$root/usr/share/limine" "$root$limine_esp/EFI/Linux" "$root$limine_esp/EFI/BOOT" + # m1n1 sits on the system ESP, which on these Macs is the one Limine uses. + [[ $limine_esp == /boot/efi ]] || mv "$esp/m1n1" "$root$limine_esp/m1n1" : >"$root/var/lib/omarchy/limine.enabled" printf 'ESP_PATH="%s"\nENABLE_UKI=yes\n' "$limine_esp" >"$root/etc/default/limine" [[ -z $fstab_row ]] || printf '%s\n' "$fstab_row" >"$root/etc/fstab" @@ -694,3 +696,32 @@ limine_system /boot/efi '' 'root=UUID=r rw quiet' run_check expect_fail "no fstab row (Omarchy's btrfs @) and no subvolume flag" "does not select rootflags=subvol=@" pass "the Limine entry's rootflags follow the root filesystem" + +# U-Boot boots the loader on the system ESP the device tree names, so the +# Limine files checked on ESP_PATH must be the ones there. +limine_on_system_esp() { + limine_system /boot/efi 'UUID=r / btrfs rw,subvol=/@ 0 0' 'root=UUID=r rw rootflags=subvol=@ quiet' + mkdir -p "$root/proc/device-tree/chosen" "$existing" + printf '%s\0' "$partuuid" >"$root/proc/device-tree/chosen/asahi,efi-system-partition" + cp -a "$esp/." "$existing/" +} +limine_on_system_esp +TEST_EXISTING_MOUNT="$existing" run_check +expect_pass "a Limine Mac whose system ESP holds the Limine files ESP_PATH names" +limine_on_system_esp +rm -rf "$existing/EFI" "$existing/limine.conf" +TEST_EXISTING_MOUNT="$existing" run_check +expect_fail "a Limine Mac whose ESP_PATH is another ESP than the system one" "/boot/efi/EFI/BOOT/BOOTAA64.EFI is not the one on the system ESP (PARTUUID=$partuuid), which U-Boot boots" +limine_on_system_esp +printf 'GRUB\n' >"$existing/EFI/BOOT/BOOTAA64.EFI" +TEST_EXISTING_MOUNT="$existing" run_check +expect_fail "a system ESP whose loader slot is not the checked Limine" "/boot/efi/EFI/BOOT/BOOTAA64.EFI is not the one on the system ESP" +limine_on_system_esp +printf 'older\n' >>"$existing/EFI/Linux/omarchy_linux-asahi.efi" +TEST_EXISTING_MOUNT="$existing" run_check +expect_fail "a system ESP with another UKI" "/boot/efi/EFI/Linux/omarchy_linux-asahi.efi is not the one on the system ESP" +limine_on_system_esp +sed -i 's/quiet$/quiet splash/' "$existing/limine.conf" +TEST_EXISTING_MOUNT="$existing" run_check +expect_fail "a system ESP with another menu" "/boot/efi/limine.conf is not the one on the system ESP" +pass "a Limine Mac boots the Limine, menu and UKI on the system ESP" From a6051c010292379d1ac97524717556c9667fefcd Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 20:55:02 +1000 Subject: [PATCH 02/10] omarchy-mac-boot: implement update-verify with the boot check The lifecycle dispatch entrypoint runs the boot check on the whole boot chain after an update, with the new kernel's reboot still to come, and on failure says not to reboot and how to rebuild the boot files. --- packages/omarchy-mac/boot/README.md | 2 +- .../boot/entrypoints/update-verify | 23 +++ packages/omarchy-mac/boot/install | 1 + .../boot/test/fixtures/limine-mac.sh | 179 ++++++++++++++++++ .../boot/test/update-verify-test.sh | 103 ++++++++++ test/shell.d/mac-boot-update-verify-test.sh | 4 + 6 files changed, 311 insertions(+), 1 deletion(-) create mode 100755 packages/omarchy-mac/boot/entrypoints/update-verify create mode 100644 packages/omarchy-mac/boot/test/fixtures/limine-mac.sh create mode 100644 packages/omarchy-mac/boot/test/update-verify-test.sh create mode 100755 test/shell.d/mac-boot-update-verify-test.sh diff --git a/packages/omarchy-mac/boot/README.md b/packages/omarchy-mac/boot/README.md index d5074b86a88a..0170b159eed4 100644 --- a/packages/omarchy-mac/boot/README.md +++ b/packages/omarchy-mac/boot/README.md @@ -2,7 +2,7 @@ This subtree is built into `omarchy-mac-boot`, separately from the kernel-neutral `omarchy-mac` hardware package. `../install` intentionally does not stage this directory. The boot recipe pins a runtime revision, the same one as the desktop candidate, and stages this subtree from it; the recipe keeps only packaging metadata and the pacman scriptlet. -`install DESTDIR` stages commands in `/usr/bin`, sourced modules/setup leaves in `/usr/lib/omarchy-mac/boot`, and the initramfs, in-place encryption and first-boot payload in `files/` at its installed paths (mkinitcpio drop-ins, initcpio hooks, units, presets, the ALPM hook and `/etc/default/update-m1n1`, which pins update-m1n1's device-tree order to the C locale). It performs no live setup. The recipe's `backup=` covers every `files/etc` path and `files/usr/lib/omarchy/initcpio`. `test/all` runs command fixtures and the payload's offline checks; `OMARCHY_DISPOSABLE_BOOT_TESTS=1` also builds real initramfs images and converts loop-device disks in privileged containers. Shared provisioning/reset integration remains covered by the runtime suite. +`install DESTDIR` stages commands in `/usr/bin`, sourced modules/setup leaves in `/usr/lib/omarchy-mac/boot`, the lifecycle dispatch entrypoints in `entrypoints/` in `/usr/lib/omarchy/mac-boot`, and the initramfs, in-place encryption and first-boot payload in `files/` at its installed paths (mkinitcpio drop-ins, initcpio hooks, units, presets, the ALPM hook and `/etc/default/update-m1n1`, which pins update-m1n1's device-tree order to the C locale). It performs no live setup. The recipe's `backup=` covers every `files/etc` path and `files/usr/lib/omarchy/initcpio`. `test/all` runs command fixtures and the payload's offline checks; `OMARCHY_DISPOSABLE_BOOT_TESTS=1` also builds real initramfs images and converts loop-device disks in privileged containers. Shared provisioning/reset integration remains covered by the runtime suite. The implementation was moved from runtime integration `e82fe3c8850b184dfa22eefd571646ad85446122`, preserving Marcelo's provenance recorded in the runtime source-port ledger. The payload in `files/` comes from the boot recipe paired with #503 (omarchy-mac/omarchy-pkgs-aarch64#65 at `617a907f99a1`) with maralcbr/omarchy-pkgs#202 applied (omarchy-mac-boot 20260921-10: the owner's keyboard layout and dock keyboards at the disk prompt). The owner wizard, recovery-slot operations, journal/retry handling and shared Limine menu/hash operations remain core code. Provisioning and reset refuse to proceed on Apple Silicon when their required package module is unavailable. diff --git a/packages/omarchy-mac/boot/entrypoints/update-verify b/packages/omarchy-mac/boot/entrypoints/update-verify new file mode 100755 index 000000000000..cfa2d1c797f2 --- /dev/null +++ b/packages/omarchy-mac/boot/entrypoints/update-verify @@ -0,0 +1,23 @@ +#!/bin/bash + +# omarchy-lifecycle-dispatch update-verify. omarchy update runs this after its +# package transaction, migrations and hooks, and neither finishes nor offers a +# reboot until it passes. The boot check proves the boot chain boots what they +# installed: the kernel and initramfs in /boot, m1n1 stage 2 with that kernel's +# device trees and U-Boot on the system ESP, and on a Limine Mac the loader, +# menu and UKI on that same ESP. The installed kernel may be newer than the +# running one until that reboot. Nothing here rebuilds a boot file. + +set -uo pipefail + +echo -e "\e[32m\nVerify the Apple Silicon boot files\e[0m" +if ! OMARCHY_BOOT_CHECK_ALLOW_PENDING_REBOOT=1 omarchy-apple-silicon-boot-check; then + cat >&2 <<'MESSAGE' + +This Mac might not boot what the update installed, so do not reboot yet. +Fix what the boot check reported above. To rebuild the initramfs, m1n1 and the boot menu: + sudo mkinitcpio -P && sudo update-m1n1 && sudo omarchy-mac-boot-update +Then run omarchy update again: it checks the boot files before it offers the reboot. +MESSAGE + exit 1 +fi diff --git a/packages/omarchy-mac/boot/install b/packages/omarchy-mac/boot/install index 0ce1e462f976..ce52855bb924 100755 --- a/packages/omarchy-mac/boot/install +++ b/packages/omarchy-mac/boot/install @@ -7,6 +7,7 @@ destination=${1:?Usage: ./install DESTDIR} for file in bin/*; do install -Dm755 "$file" "$destination/usr/bin/${file##*/}"; done for file in lib/*; do install -Dm644 "$file" "$destination/usr/lib/omarchy-mac/boot/${file##*/}"; done for file in setup/*; do install -Dm644 "$file" "$destination/usr/lib/omarchy-mac/boot/setup/${file##*/}"; done +for file in entrypoints/*; do install -Dm755 "$file" "$destination/usr/lib/omarchy/mac-boot/${file##*/}"; done # The initramfs, encryption and first-boot payload keeps its installed paths. while IFS= read -r -d '' file; do if [[ -L $file ]]; then diff --git a/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh b/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh new file mode 100644 index 000000000000..303042a63bab --- /dev/null +++ b/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh @@ -0,0 +1,179 @@ +# A Limine Mac for omarchy-apple-silicon-boot-check, as a fixture root plus the +# stubs and environment the check reads it through. Sourced by tests; +# limine_mac_init sets it up, limine_mac lays out a healthy Mac on +# linux-aurora and m1n1-aurora, and limine_mac_env prints the environment. + +limine_mac_init() { + mac_dir=$1 + mac_root=$mac_dir/root + mac_stubs=$mac_dir/stubs + mac_state=$mac_dir/state + mac_kver=6.17.0-aurora1-ARCH + mac_esp=$mac_root/boot/efi + mkdir -p "$mac_stubs" + + cat >"$mac_stubs/sudo" <<'SH' +#!/bin/bash +exec "$@" +SH + cat >"$mac_stubs/pacman" <<'SH' +#!/bin/bash +case "$*" in + -Qq) cat "$MAC_STATE/installed" ;; + "-Qlq "*) [[ -f $MAC_STATE/files-$2 ]] && cat "$MAC_STATE/files-$2" ;; + "-Qkk "*) printf '%s: 2 total files, 0 altered files\n' "$2" ;; + *) exit 1 ;; +esac +SH + cat >"$mac_stubs/lsinitcpio" <<'SH' +#!/bin/bash +[[ -f ${@: -1} ]] || exit 1 +case $1 in + -l) cat "$MAC_STATE/initramfs" ;; + -a) printf '==> Image: initramfs\n' ;; + *) exit 1 ;; +esac +SH + # Only read-only binds, of a directory standing in for the mounted ESP. + cat >"$mac_stubs/mount" <<'SH' +#!/bin/bash +[[ $1 == "--bind" && $2 == "-o" && $3 == "ro" && -d $4 ]] || exit 32 +cp -a "$4/." "$5/" +echo "$5" >>"$MAC_STATE/mounts" +SH + cat >"$mac_stubs/umount" <<'SH' +#!/bin/bash +find "$1" -mindepth 1 -delete +sed -i "\|^$1\$|d" "$MAC_STATE/mounts" +SH + cat >"$mac_stubs/findmnt" <<'SH' +#!/bin/bash +[[ $* == "-n -o VFS-OPTIONS --mountpoint "* ]] && grep -Fxq -- "${@: -1}" "$MAC_STATE/mounts" || exit 1 +echo ro,relatime +SH + cat >"$mac_stubs/lsblk" <<'SH' +#!/bin/bash +exit 0 +SH + # A fixture UKI is the kernel followed by a marker: .linux is the whole file. + cat >"$mac_stubs/objcopy" <<'SH' +#!/bin/bash +[[ $* == "-O binary --only-section=.linux "* ]] || exit 1 +cp "$4" "$5" +SH + chmod +x "$mac_stubs"/* +} + +# A device tree as update-m1n1 and the boot check see one: the flattened device +# tree magic and big-endian total size, then a body naming it. +limine_mac_dtb() { + local path=$1 body size + body="device tree ${path##*/} ${2:-}"$'\n' + size=$(( 8 + ${#body} )) + mkdir -p "$(dirname "$path")" + { + printf '\xd0\x0d\xfe\xed' + printf "$(printf '\\x%02x' $(( size >> 24 & 255 )) $(( size >> 16 & 255 )) $(( size >> 8 & 255 )) $(( size & 255 )))" + printf '%s' "$body" + } >"$path" +} + +# m1n1/boot.bin on the ESP as update-m1n1 writes it: m1n1, the given device +# trees (root-relative), gzipped U-Boot and the m1n1.conf options. +limine_mac_boot_bin() { + local m1n1=$1 dtb paths=() + shift + for dtb; do + paths+=("$mac_root$dtb") + done + { + cat "$m1n1" "${paths[@]}" + gzip -c "$mac_root/usr/lib/asahi-boot/u-boot-nodtb.bin" + printf 'display=2560x1600\n' + } >"$mac_esp/m1n1/boot.bin" +} + +# The Limine menu entry for the UKI, with the hash Limine verifies. +limine_mac_menu() { + local uki=$mac_esp/EFI/Linux/omarchy_linux-aurora.efi + printf '/+Omarchy\n //linux-aurora\n protocol: efi\n path: boot():/EFI/Linux/omarchy_linux-aurora.efi#%s\n cmdline: root=UUID=r rw rootflags=subvol=@ quiet\n' \ + "$(b2sum "$uki" | cut -d' ' -f1)" >"$mac_esp/limine.conf" +} + +limine_mac() { + local modules=$mac_root/usr/lib/modules/$mac_kver dtb + mac_dtbs=(/usr/lib/modules/$mac_kver/dtbs/t6000-j314s.dtb /usr/lib/modules/$mac_kver/dtbs/t6020-j414s.dtb /usr/lib/modules/$mac_kver/dtbs/t8103-j274.dtb) + rm -rf "$mac_root" "$mac_state" + mkdir -p "$modules/dtbs" "$mac_root/usr/lib/asahi-boot" "$mac_root/usr/bin" "$mac_root/usr/share/limine" \ + "$mac_root/etc/default" "$mac_root/var/lib/omarchy" "$mac_root/run" \ + "$mac_esp/m1n1" "$mac_esp/EFI/BOOT" "$mac_esp/EFI/Linux" "$mac_state" + : >"$mac_state/mounts" + ln -s usr/lib "$mac_root/lib" + + printf 'linux-aurora kernel %s\n' "$mac_kver" >"$modules/vmlinuz" + cp "$modules/vmlinuz" "$mac_root/boot/vmlinuz-linux-aurora" + printf 'initramfs\n' >"$mac_root/boot/initramfs-linux-aurora.img" + printf 'usr/lib/modules/%s/kernel/drivers/gpu/drm/apple/appledrm.ko.zst\nusr/bin/init\n' "$mac_kver" >"$mac_state/initramfs" + for dtb in "${mac_dtbs[@]}"; do + limine_mac_dtb "$mac_root$dtb" + done + printf 'm1n1 stage 2 from m1n1-aurora\n' >"$mac_root/usr/lib/asahi-boot/m1n1.bin" + printf 'u-boot\n' >"$mac_root/usr/lib/asahi-boot/u-boot-nodtb.bin" + printf 'display=2560x1600\n' >"$mac_root/etc/m1n1.conf" + printf 'export LC_ALL=C\n' >"$mac_root/etc/default/update-m1n1" + # update-m1n1 as asahi-scripts ships it, with the DTBS default ALARM adds. + cat >"$mac_root/usr/bin/update-m1n1" <<'SH' +#!/bin/sh +set -e +[ -e /etc/default/update-m1n1 ] && . /etc/default/update-m1n1 +[ -n "$M1N1_UPDATE_DISABLED" ] && exit 0 +: ${SOURCE:="/usr/lib/asahi-boot/"} +: ${M1N1:="$SOURCE/m1n1.bin"} +: ${U_BOOT:="$SOURCE/u-boot-nodtb.bin"} +: ${TARGET:="$1"} +: ${DTBS:=$(/bin/ls -d /lib/modules/*-ARCH | sort -rV | head -1)/dtbs/*.dtb} +: ${CONFIG:=/etc/m1n1.conf} +m1n1config=/run/m1n1.conf +if [ -e "$CONFIG" ]; then + while read line; do + case "$line" in + "") ;; + \#*) ;; + chosen.*=*|display=*|mitigations=*) + echo "$line" >> "$m1n1config" + ;; + esac + done <$CONFIG +fi +cat "$M1N1" $DTBS >"${TARGET}.new" +gzip -c "$U_BOOT" >>"${TARGET}.new" +cat "$m1n1config" >>"${TARGET}.new" +SH + limine_mac_boot_bin "$mac_root/usr/lib/asahi-boot/m1n1.bin" "${mac_dtbs[@]}" + + : >"$mac_root/var/lib/omarchy/limine.enabled" + printf 'ESP_PATH="/boot/efi"\nENABLE_UKI=yes\n' >"$mac_root/etc/default/limine" + printf 'UUID=r / btrfs rw,subvol=/@ 0 0\n' >"$mac_root/etc/fstab" + printf 'LIMINE\n' >"$mac_root/usr/share/limine/BOOTAA64.EFI" + cp "$mac_root/usr/share/limine/BOOTAA64.EFI" "$mac_esp/EFI/BOOT/BOOTAA64.EFI" + { cat "$modules/vmlinuz"; printf 'initrd\n'; } >"$mac_esp/EFI/Linux/omarchy_linux-aurora.efi" + limine_mac_menu + + printf '%s\n' linux-aurora m1n1-aurora uboot-asahi limine >"$mac_state/installed" + { + printf '/usr/\n/usr/lib/\n/usr/lib/modules/\n/usr/lib/modules/%s/\n/usr/lib/modules/%s/vmlinuz\n/usr/lib/modules/%s/dtbs/\n' "$mac_kver" "$mac_kver" "$mac_kver" + printf '%s\n' "${mac_dtbs[@]}" + } >"$mac_state/files-linux-aurora" + printf '/usr/lib/asahi-boot/\n/usr/lib/asahi-boot/m1n1.bin\n' >"$mac_state/files-m1n1-aurora" +} + +# The environment the check reads the fixture through, one export per line: +# $1 is where the boot check is, $2 the running kernel release (by default the +# installed one). +limine_mac_env() { + printf 'export %s\n' \ + "$(printf 'MAC_STATE=%q' "$mac_state")" \ + "$(printf 'OMARCHY_BOOT_CHECK_ROOT=%q' "$mac_root")" \ + "$(printf 'OMARCHY_BOOT_CHECK_UNAME=%q' "${2:-$mac_kver}")" \ + "$(printf 'PATH=%q' "$mac_stubs:$1:$PATH")" +} diff --git a/packages/omarchy-mac/boot/test/update-verify-test.sh b/packages/omarchy-mac/boot/test/update-verify-test.sh new file mode 100644 index 000000000000..621cb650bb16 --- /dev/null +++ b/packages/omarchy-mac/boot/test/update-verify-test.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +set -euo pipefail +source "$(dirname "$0")/base-test.sh" +source "$ROOT/test/fixtures/limine-mac.sh" + +require_command gzip +require_command b2sum + +# omarchy update runs update-verify through omarchy-lifecycle-dispatch once its +# packages, migrations and hooks are done. It is the boot check on the whole +# boot chain, read-only, with the reboot the update offers next still to come. +entrypoint=$ROOT/entrypoints/update-verify +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT + +bash "$ROOT/install" "$tmp/stage" +staged=$tmp/stage/usr/lib/omarchy/mac-boot/update-verify +cmp -s "$entrypoint" "$staged" && [[ $(stat -c %a "$staged") == 755 ]] || + fail "update-verify is staged as the lifecycle dispatch entrypoint /usr/lib/omarchy/mac-boot/update-verify" +pass "the package ships update-verify where omarchy-lifecycle-dispatch runs it" + +limine_mac_init "$tmp/mac" + +tree_state() { + find "$mac_root" -path "$mac_root/run" -prune -o -print0 | sort -z | xargs -0 stat -c '%n %s %Y %a' 2>/dev/null + find "$mac_root" -path "$mac_root/run" -prune -o -type f -print0 | sort -z | xargs -0 sha256sum +} + +# Runs update-verify on the fixture Mac; $1 is the running kernel release. +verify() { + tree_state >"$tmp/before" + set +e + ( + eval "$(limine_mac_env "$ROOT/bin" "${1:-}")" + bash "$entrypoint" + ) >"$tmp/out" 2>"$tmp/err" + status=$? + set -e + tree_state >"$tmp/after" + diff -q "$tmp/before" "$tmp/after" >/dev/null || fail "update-verify changes no boot file" "$(diff "$tmp/before" "$tmp/after")" + [[ ! -s $mac_state/mounts && -z $(ls -A "$mac_root/run") ]] || fail "update-verify leaves nothing mounted" +} + +expect_verified() { + (( status == 0 )) || fail "$1 passes update-verify" "status $status: $(cat "$tmp/err")" +} + +expect_refused() { + local description=$1 reason=$2 + (( status == 1 )) || fail "$description fails update-verify" "status $status: $(cat "$tmp/out" "$tmp/err")" + grep -Fq "$reason" "$tmp/err" || fail "$description is named" "$(cat "$tmp/err")" + grep -Fq "do not reboot yet" "$tmp/err" && grep -Fq "sudo mkinitcpio -P && sudo update-m1n1 && sudo omarchy-mac-boot-update" "$tmp/err" || + fail "$description says not to reboot and how to rebuild the boot files" "$(cat "$tmp/err")" +} + +limine_mac +verify +expect_verified "a Limine Mac running the installed kernel" +grep -Fq "running linux-aurora $mac_kver; installed boot files match" "$tmp/out" || fail "update-verify reports what it verified" "$(cat "$tmp/out")" +verify 6.16.0-aurora9-ARCH +expect_verified "a Limine Mac whose update installed a new kernel" +grep -Fq "running 6.16.0-aurora9-ARCH, reboot pending" "$tmp/out" || fail "update-verify says the reboot is still to come" "$(cat "$tmp/out")" +limine_mac_boot_bin "$mac_root/usr/lib/asahi-boot/m1n1.bin" "${mac_dtbs[2]}" "${mac_dtbs[0]}" "${mac_dtbs[1]}" +verify +expect_verified "an m1n1 image holding the kernel's device trees in another order" +pass "update-verify passes a coherent boot chain, before and after the reboot, whatever order the device trees are in" + +boot_bin_reason="m1n1/boot.bin on the system ESP (/boot/efi) is not m1n1, linux-aurora $mac_kver's device trees, U-Boot and /etc/m1n1.conf as installed" + +limine_mac +limine_mac_dtb "$mac_root/opt/t8103-j274.dtb" "from another kernel" +limine_mac_boot_bin "$mac_root/usr/lib/asahi-boot/m1n1.bin" "${mac_dtbs[@]:0:2}" /opt/t8103-j274.dtb +verify +expect_refused "an m1n1 image with a device tree the installed kernel does not ship" "$boot_bin_reason" + +limine_mac +printf 'm1n1 stage 2 from the previous m1n1-aurora\n' >"$tmp/m1n1.bin" +limine_mac_boot_bin "$tmp/m1n1.bin" "${mac_dtbs[@]}" +verify +expect_refused "an m1n1 image with a stale m1n1" "$boot_bin_reason" + +limine_mac +rm "$mac_esp/EFI/Linux/omarchy_linux-aurora.efi" +verify +expect_refused "a Limine Mac without its UKI" "/boot/efi/EFI/Linux/omarchy_linux-aurora.efi (the Limine UKI) is missing" + +limine_mac +printf 'the previous kernel\n' >"$mac_esp/EFI/Linux/omarchy_linux-aurora.efi" +limine_mac_menu +verify +expect_refused "a UKI carrying another kernel" "does not carry the installed $mac_kver kernel" + +limine_mac +printf 'LIMINE, previous release\n' >"$mac_esp/EFI/BOOT/BOOTAA64.EFI" +verify +expect_refused "a loader slot with another Limine" "/boot/efi/EFI/BOOT/BOOTAA64.EFI is not the installed Limine" + +limine_mac +printf 'usr/lib/modules/6.16.0-aurora9-ARCH/kernel/x.ko\n' >"$mac_state/initramfs" +verify 6.16.0-aurora9-ARCH +expect_refused "an initramfs built for the previous kernel" "does not hold the $mac_kver modules" +pass "update-verify refuses a wrong device tree, a stale m1n1, a missing or stale UKI, another Limine or a stale initramfs, and says not to reboot" diff --git a/test/shell.d/mac-boot-update-verify-test.sh b/test/shell.d/mac-boot-update-verify-test.sh new file mode 100755 index 000000000000..85b8da626a35 --- /dev/null +++ b/test/shell.d/mac-boot-update-verify-test.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -euo pipefail +source "$(dirname -- "${BASH_SOURCE[0]}")/base-test.sh" +exec bash "$ROOT/packages/omarchy-mac/boot/test/update-verify-test.sh" From d341b9f012200367186bc5036f436350423488e2 Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 20:55:02 +1000 Subject: [PATCH 03/10] Block update completion and the reboot on failed boot verification omarchy update runs update-preflight before its package changes and update-verify after them through the lifecycle dispatcher. A failed verification leaves the update unfinished, exiting non-zero without offering the reboot. Both are no-ops on platforms without a boot package, x86 included. --- bin/omarchy-update | 13 +- bin/omarchy-update-boot | 31 ++++ docs/update-process.md | 11 +- test/shell.d/update-boot-verify-test.sh | 200 ++++++++++++++++++++++++ test/shell.d/update-disk-space-test.sh | 1 + test/shell.d/update-lock-test.sh | 1 + test/shell.d/update-sequence-test.sh | 3 + 7 files changed, 257 insertions(+), 3 deletions(-) create mode 100755 bin/omarchy-update-boot create mode 100755 test/shell.d/update-boot-verify-test.sh diff --git a/bin/omarchy-update b/bin/omarchy-update index e71e808664ee..5b2be966ba44 100755 --- a/bin/omarchy-update +++ b/bin/omarchy-update @@ -39,6 +39,7 @@ if [[ ${1:-} == "-y" ]] || omarchy-update-confirm; then omarchy-update-stay-awake start omarchy-update-dev + omarchy-update-boot preflight omarchy-update-keyring # Migrations ship with the packages installed here and are written against @@ -51,6 +52,11 @@ if [[ ${1:-} == "-y" ]] || omarchy-update-confirm; then omarchy-update-mise omarchy-update-orphan-pkgs + # The update is not finished, and offers no reboot, until the boot files the + # steps above left are shown to boot the updated system. + boot_verified=true + omarchy-update-boot verify || boot_verified=false + omarchy-update-analyze-logs omarchy-update-status @@ -60,5 +66,10 @@ if [[ ${1:-} == "-y" ]] || omarchy-update-confirm; then omarchy-update-stay-awake stop trap - EXIT - omarchy-update-restart + if [[ $boot_verified == "true" ]]; then + omarchy-update-restart + else + echo -e "\e[31m\nThe update is not finished: its boot files did not pass verification (see above). Do not reboot until omarchy update completes.\e[0m" >&2 + exit 1 + fi fi diff --git a/bin/omarchy-update-boot b/bin/omarchy-update-boot new file mode 100755 index 000000000000..eb98b39cd31b --- /dev/null +++ b/bin/omarchy-update-boot @@ -0,0 +1,31 @@ +#!/bin/bash + +# omarchy:summary=Run the platform's boot checks around the update's package changes +# omarchy:args= +# omarchy:hidden=true +# omarchy:requires-sudo=true + +# preflight can refuse an update the platform could not boot afterwards, before +# any package changes. verify proves that the boot files the package steps left +# boot the updated system, and omarchy update neither finishes nor offers a +# reboot until it passes. Both are lifecycle dispatch operations: no-ops where +# the platform registers no boot package, x86 included, and the platform's own +# entrypoint says what failed. + +set -e + +case ${1:-} in + preflight | verify) operation=update-$1 ;; + *) + echo "Usage: omarchy-update-boot " >&2 + exit 2 + ;; +esac + +# Resolving as the user keeps sudo, and its password prompt, out of updates +# with nothing to run. A resolution that fails has said why, and fails the +# check. Root resolves again from its own fixed paths before anything runs. +entrypoint=$(omarchy-lifecycle-dispatch --resolve "$operation") +if [[ -n $entrypoint ]]; then + sudo omarchy-lifecycle-dispatch "$operation" +fi diff --git a/docs/update-process.md b/docs/update-process.md index efecb94c0ede..f2e28cdfec87 100644 --- a/docs/update-process.md +++ b/docs/update-process.md @@ -130,12 +130,17 @@ omarchy-update │ installed but unconfigured fails the snapshot loudly, pointing at │ install/config/snapper.sh, and the update continues without one) ├─ omarchy-update-stay-awake start - ├─ run package updates, migrations, hooks, and log analysis + ├─ omarchy-update-boot preflight + │ └─ the platform's boot package can refuse the update before packages change + ├─ run package updates, migrations and hooks + ├─ omarchy-update-boot verify + │ └─ the platform's boot package proves the boot files boot the updated system + ├─ log analysis ├─ omarchy-update-status │ └─ refresh or clear the shell update indicator ├─ omarchy-update-stay-awake stop │ └─ release the sleep inhibitor and restore shell idle state, if changed - └─ omarchy-update-restart + └─ omarchy-update-restart, only when the boot files were verified ``` Important behavior: @@ -152,6 +157,7 @@ Important behavior: `omarchy-migrate` after pacman finishes. - A failure should leave enough output in `/tmp/omarchy-update.log` and the terminal transcript to debug. +- Both boot checks are [lifecycle dispatch](lifecycle-dispatch.md) operations (`update-preflight`, `update-verify`), no-ops on platforms whose boot chain needs no handling of its own, x86 included. A refused preflight stops the update like any failed step. A failed verification lets the update finish its remaining reporting steps, then it exits non-zero without `omarchy-update-restart`: the update is not finished and offers no reboot. On Apple Silicon, `omarchy-mac-boot` verifies the kernel and initramfs in `/boot`, m1n1 stage 2 with the kernel's device trees and U-Boot on the system ESP, and Limine's loader, menu and UKI on that ESP. ## Path 2: direct `sudo pacman -Syu` attempt @@ -291,6 +297,7 @@ scripts. | `omarchy-update-mise` | Runs `MISE_MINIMUM_RELEASE_AGE=0 mise up` for mise-managed tools — the override of mise's release-age cooldown is the point. | **Keep.** Mise-managed tools are intentionally part of the blessed update path. | | `omarchy-update-orphan-pkgs` | Lists orphans and prompts before removal; noninteractive mode never removes. | **Keep for now.** Safe because it is prompt-only. | | `omarchy-update-analyze-logs` | Scans `/tmp/omarchy-update.log` for known failure patterns, currently initramfs generation. | **Keep/expand.** Useful safety net; should grow only for high-signal checks. | +| `omarchy-update-boot` | Hidden helper that runs the platform's `update-preflight` and `update-verify` lifecycle operations through `omarchy-lifecycle-dispatch`. | **Keep internal/hidden.** Keeps platform boot checks out of the pipeline and stubbable in tests. | | `omarchy-update-restart` | Prompts for reboot after kernel/Hyprland updates, restarts components with `restart-*-required` markers, and always restarts the shell. | **Keep.** Important final step; may eventually include service-restart checks. | | `omarchy-update-firmware` | Manual firmware update command using fwupd. Not part of the normal update pipeline. | **Keep separate.** Firmware is not a routine system update step. | | `omarchy-update-time` | Restarts `systemd-timesyncd`. | **Question.** Not really an update command. Consider renaming/moving under system/time maintenance. | diff --git a/test/shell.d/update-boot-verify-test.sh b/test/shell.d/update-boot-verify-test.sh new file mode 100755 index 000000000000..8fb847431b27 --- /dev/null +++ b/test/shell.d/update-boot-verify-test.sh @@ -0,0 +1,200 @@ +#!/bin/bash + +set -euo pipefail + +source "$(dirname "$0")/base-test.sh" +source "$ROOT/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh" + +require_platform_fixtures "omarchy update's boot checks on platform fixtures" +require_command gzip +require_command b2sum + +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT + +# Every step of omarchy update but its boot checks is a stub that records +# itself. The boot checks run the real omarchy-update-boot, dispatcher and +# platform detector; sudo passes the fixtures through. +steps=( + omarchy-update-lock + omarchy-update-requires-free-space + omarchy-update-confirm + omarchy-update-pkg-prune + omarchy-snapshot + omarchy-update-stay-awake + omarchy-update-dev + omarchy-update-keyring + omarchy-update-system-pkgs + omarchy-migrate + omarchy-hook + omarchy-update-aur-pkgs + omarchy-update-mise + omarchy-update-orphan-pkgs + omarchy-update-analyze-logs + omarchy-update-status + omarchy-update-restart +) +stub_bin=$tmp/bin +mkdir -p "$stub_bin" +for step in "${steps[@]}"; do + cat >"$stub_bin/$step" <<'SH' +#!/bin/bash +echo "${0##*/}" >>"$STEP_LOG" +SH +done +cat >"$stub_bin/sudo" <<'SH' +#!/bin/bash +echo "$*" >>"$SUDO_LOG" +exec "$@" +SH +chmod +x "$stub_bin"/* + +for platform in apple-silicon qualcomm generic-aarch64 generic; do + fake_platform "$tmp/$platform" "$platform" +done + +# The whole update, as the stubs record it, before this change and with it on +# a platform whose boot checks are no-ops. +all_steps() { + printf '%s\n' omarchy-update-lock omarchy-update-requires-free-space omarchy-update-pkg-prune omarchy-snapshot \ + omarchy-update-stay-awake omarchy-update-dev omarchy-update-keyring omarchy-update-system-pkgs omarchy-migrate \ + omarchy-hook omarchy-update-aur-pkgs omarchy-update-mise omarchy-update-orphan-pkgs omarchy-update-analyze-logs \ + omarchy-update-status omarchy-update-stay-awake omarchy-update-restart +} + +# omarchy update -y on platform $1, with the boot package's entrypoints in the +# lifecycle root $2. +run_update() { + local platform=$1 lifecycle=$2 + : >"$tmp/steps" + : >"$tmp/sudo" + set +e + STEP_LOG="$tmp/steps" \ + SUDO_LOG="$tmp/sudo" \ + OMARCHY_UPDATE_LOGGED=1 \ + OMARCHY_PROC_ROOT="$tmp/$platform/proc" \ + OMARCHY_LIFECYCLE_ROOT="$lifecycle" \ + PATH="$tmp/$platform/bin:$stub_bin:$ROOT/bin:$PATH" \ + bash "$ROOT/bin/omarchy-update" -y >"$tmp/out" 2>"$tmp/err" + status=$? + set -e +} + +ran() { + grep -Fxq "$1" "$tmp/steps" +} + +# A lifecycle root holding entrypoints that record themselves and exit with $2. +recording_package() { + local lifecycle=$1 code=$2 operation + rm -rf "$lifecycle" + mkdir -p "$lifecycle/usr/lib/omarchy/mac-boot" + for operation in update-preflight update-verify; do + printf '#!/bin/bash\necho %s >>%q\nexit %s\n' "$operation" "$tmp/boot-ran" "$code" >"$lifecycle/usr/lib/omarchy/mac-boot/$operation" + done + chmod -R go-w "$lifecycle" + chmod 755 "$lifecycle"/usr/lib/omarchy/mac-boot/* +} + +# omarchy-mac-boot's own update-verify, on the fixture Mac. The dispatcher runs +# entrypoints with an empty environment, so this one puts the fixture's back +# before it runs the real entrypoint and boot check. $1 is the running kernel. +mac_boot_package() { + local lifecycle=$tmp/mac-boot entrypoint=$tmp/mac-boot/usr/lib/omarchy/mac-boot/update-verify + rm -rf "$lifecycle" + mkdir -p "${entrypoint%/*}" + { + printf '#!/bin/bash\n' + limine_mac_env "$ROOT/packages/omarchy-mac/boot/bin" "${1:-}" + printf 'exec bash %q\n' "$ROOT/packages/omarchy-mac/boot/entrypoints/update-verify" + } >"$entrypoint" + chmod -R go-w "$lifecycle" + chmod 755 "$entrypoint" +} + +# x86, generic aarch64 and Qualcomm: both boot checks are no-ops, even with +# failing Mac entrypoints on disk, and the update runs and says exactly what +# it did before. +recording_package "$tmp/failing" 9 +for platform in generic generic-aarch64 qualcomm; do + rm -f "$tmp/boot-ran" + run_update "$platform" "$tmp/failing" + (( status == 0 )) || fail "$platform: an update reports success" "status $status: $(cat "$tmp/err")" + diff <(all_steps) "$tmp/steps" >"$tmp/order" || fail "$platform: the update runs the same steps as before" "$(cat "$tmp/order")" + [[ ! -s $tmp/out && ! -s $tmp/err ]] || fail "$platform: the boot checks print nothing" "$(cat "$tmp/out" "$tmp/err")" + [[ ! -e $tmp/boot-ran ]] || fail "$platform: no Mac entrypoint runs" "$(cat "$tmp/boot-ran")" + [[ ! -s $tmp/sudo ]] || fail "$platform: the boot checks ask for no root" "$(cat "$tmp/sudo")" +done +pass "x86, generic aarch64 and Qualcomm updates are unchanged: no boot check runs, nothing asks for root and the reboot is offered" + +# Apple: preflight runs before the keyring and packages change, and verify +# after the last package step, before the reboot is offered. +recording_package "$tmp/passing" 0 +rm -f "$tmp/boot-ran" +run_update apple-silicon "$tmp/passing" +(( status == 0 )) || fail "apple: an update whose boot checks pass reports success" "status $status: $(cat "$tmp/err")" +diff <(all_steps) "$tmp/steps" >"$tmp/order" || fail "apple: a verified update runs every step" "$(cat "$tmp/order")" +[[ $(cat "$tmp/boot-ran") == $'update-preflight\nupdate-verify' ]] || fail "apple: preflight and verify each run once" "$(cat "$tmp/boot-ran")" +[[ $(cat "$tmp/sudo") == $'omarchy-lifecycle-dispatch update-preflight\nomarchy-lifecycle-dispatch update-verify' ]] || + fail "apple: preflight and verify run as root" "$(cat "$tmp/sudo")" +pass "apple: preflight and verify run through the boot package and a verified update offers the reboot" + +recording_package "$tmp/refusing" 1 +rm "$tmp/refusing/usr/lib/omarchy/mac-boot/update-verify" +run_update apple-silicon "$tmp/refusing" +(( status != 0 )) || fail "apple: a refused preflight fails the update" +for step in omarchy-update-keyring omarchy-update-system-pkgs omarchy-migrate omarchy-update-restart; do + ! ran "$step" || fail "apple: a refused preflight stops the update before $step" +done +pass "apple: a refused preflight stops the update before any package changes" + +# omarchy-mac-boot's update-verify on a Limine Mac, end to end. +limine_mac_init "$tmp/mac" +limine_mac +mac_boot_package +run_update apple-silicon "$tmp/mac-boot" +(( status == 0 )) || fail "apple: an update that leaves a coherent boot chain succeeds" "status $status: $(cat "$tmp/out" "$tmp/err")" +ran omarchy-update-restart || fail "apple: a verified update offers the reboot" +grep -Fq "running linux-aurora $mac_kver; installed boot files match" "$tmp/out" || fail "apple: the update shows what it verified" "$(cat "$tmp/out")" +mac_boot_package 6.16.0-aurora9-ARCH +run_update apple-silicon "$tmp/mac-boot" +(( status == 0 )) && ran omarchy-update-restart || + fail "apple: an update that installed a new kernel is verified before its reboot" "status $status: $(cat "$tmp/out" "$tmp/err")" +pass "apple: an update that leaves a coherent boot chain passes verification and offers the reboot" + +# Injected incoherence: the update fails, says why and what to do, and does not +# offer the reboot. Everything else still runs. +blocked() { + local description=$1 reason=$2 + run_update apple-silicon "$tmp/mac-boot" + (( status == 1 )) || fail "apple: $description fails the update" "status $status: $(cat "$tmp/err")" + ! ran omarchy-update-restart || fail "apple: $description offers no reboot" + ran omarchy-update-analyze-logs && ran omarchy-update-status && (( $(grep -c '^omarchy-update-stay-awake$' "$tmp/steps") == 2 )) || + fail "apple: $description still checks the logs, refreshes the status and releases Stay Awake" "$(cat "$tmp/steps")" + grep -Fq "$reason" "$tmp/err" || fail "apple: $description is explained" "$(cat "$tmp/err")" + grep -Fq "do not reboot yet" "$tmp/err" && grep -Fq "The update is not finished" "$tmp/err" || + fail "apple: $description says the update is not finished and not to reboot" "$(cat "$tmp/err")" +} +mac_boot_package +limine_mac +limine_mac_dtb "$mac_root/opt/t8103-j274.dtb" "from another kernel" +limine_mac_boot_bin "$mac_root/usr/lib/asahi-boot/m1n1.bin" "${mac_dtbs[@]:0:2}" /opt/t8103-j274.dtb +blocked "a wrong device tree in m1n1/boot.bin" "m1n1/boot.bin on the system ESP (/boot/efi) is not m1n1, linux-aurora $mac_kver's device trees" +limine_mac +printf 'm1n1 stage 2 from the previous m1n1-aurora\n' >"$tmp/m1n1.bin" +limine_mac_boot_bin "$tmp/m1n1.bin" "${mac_dtbs[@]}" +blocked "a stale m1n1" "m1n1/boot.bin on the system ESP (/boot/efi) is not m1n1" +limine_mac +rm "$mac_esp/EFI/Linux/omarchy_linux-aurora.efi" +blocked "a missing UKI" "/boot/efi/EFI/Linux/omarchy_linux-aurora.efi (the Limine UKI) is missing" +pass "apple: a wrong device tree, a stale m1n1 or a missing UKI fails the update, explained, with no reboot offered" + +# A Mac without omarchy-mac-boot cannot prove its boot chain: preflight is +# optional, verify is not. +mkdir -p "$tmp/no-package" +run_update apple-silicon "$tmp/no-package" +(( status == 1 )) && ! ran omarchy-update-restart || fail "apple: without omarchy-mac-boot the update fails and offers no reboot" "status $status" +ran omarchy-update-system-pkgs || fail "apple: without omarchy-mac-boot the optional preflight is a no-op" +grep -Fq "update-verify on apple-silicon needs omarchy-mac-boot" "$tmp/err" && grep -Fq "The update is not finished" "$tmp/err" || + fail "apple: without omarchy-mac-boot the update names the package" "$(cat "$tmp/err")" +pass "apple: without omarchy-mac-boot the update is not finished and names the missing package" diff --git a/test/shell.d/update-disk-space-test.sh b/test/shell.d/update-disk-space-test.sh index 2c7368ea6305..f818acd0e850 100644 --- a/test/shell.d/update-disk-space-test.sh +++ b/test/shell.d/update-disk-space-test.sh @@ -75,6 +75,7 @@ for command in \ omarchy-update-aur-pkgs \ omarchy-update-mise \ omarchy-update-orphan-pkgs \ + omarchy-update-boot \ omarchy-hook \ omarchy-update-analyze-logs \ omarchy-shell \ diff --git a/test/shell.d/update-lock-test.sh b/test/shell.d/update-lock-test.sh index 65a673c6ddde..cc6d8bf1bf37 100644 --- a/test/shell.d/update-lock-test.sh +++ b/test/shell.d/update-lock-test.sh @@ -44,6 +44,7 @@ for command in \ omarchy-update-aur-pkgs \ omarchy-update-mise \ omarchy-update-orphan-pkgs \ + omarchy-update-boot \ omarchy-hook \ omarchy-update-analyze-logs \ omarchy-shell \ diff --git a/test/shell.d/update-sequence-test.sh b/test/shell.d/update-sequence-test.sh index 2dd62b6e43fb..f2c25329ae32 100755 --- a/test/shell.d/update-sequence-test.sh +++ b/test/shell.d/update-sequence-test.sh @@ -20,6 +20,7 @@ steps=( omarchy-snapshot omarchy-update-stay-awake omarchy-update-dev + omarchy-update-boot omarchy-update-keyring omarchy-update-system-pkgs omarchy-migrate @@ -67,6 +68,7 @@ expected_steps() { omarchy-snapshot \ omarchy-update-stay-awake \ omarchy-update-dev \ + omarchy-update-boot \ omarchy-update-keyring \ omarchy-update-system-pkgs \ omarchy-migrate \ @@ -74,6 +76,7 @@ expected_steps() { omarchy-update-aur-pkgs \ omarchy-update-mise \ omarchy-update-orphan-pkgs \ + omarchy-update-boot \ omarchy-update-analyze-logs \ omarchy-update-status \ omarchy-update-stay-awake \ From cb040e2e43f5b30286cc9feb5979f4b301781063 Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 21:19:30 +1000 Subject: [PATCH 04/10] Document omarchy update as the update-preflight and update-verify caller --- docs/lifecycle-dispatch.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/lifecycle-dispatch.md b/docs/lifecycle-dispatch.md index 21cc435350eb..8a495cebd57e 100644 --- a/docs/lifecycle-dispatch.md +++ b/docs/lifecycle-dispatch.md @@ -33,9 +33,9 @@ The set is fixed in the dispatcher; adding one is an upstream change. The operat | `reset-prepare` | Factory reset, before switching to the factory root | Stages the platform's boot state (unlock, command line, rebuilt boot files) for the factory root | required | ticket 34 | | `reset-verify` | Factory reset, before committing the switch | Proves the factory root boots on this boot chain (kernel, firmware and DTB coherence, loader hashes) | required | ticket 34 | | `reset-rollback` | Factory reset, when anything fails after `reset-prepare` | Restores the previous boot state | required | ticket 34 | -| `update-preflight` | Update, before the package transaction | Refuses an update the platform can't boot afterwards | optional | ticket 35 | -| `update-verify` | Update, after the package transaction | Verifies the boot chain boots the updated system. A failure blocks completion. | required | ticket 35 | -| `boot-rebuild` | Whenever upstream rebuilds boot files: owner provisioning after a factory reset left entries for another machine identity, later kernel and initramfs hooks, snapshots and command-line changes | Rebuilds the platform's boot files, after upstream has started the Limine menu over where there is one | required | `omarchy-provision-owner`; tickets 35, 36 | +| `update-preflight` | Update, before the keyring and package transaction | Refuses an update the platform can't boot afterwards. A failure stops the update. | optional | `omarchy-update-boot preflight` (`omarchy update`) | +| `update-verify` | Update, after the last package step: the transaction, migrations, the post-update hook, AUR, mise and orphans | Read-only. Verifies the boot chain boots the updated system, whose new kernel may still wait for its reboot. A failure leaves the update unfinished: it exits non-zero and offers no reboot. | required | `omarchy-update-boot verify` (`omarchy update`) | +| `boot-rebuild` | Whenever upstream rebuilds boot files: owner provisioning after a factory reset left entries for another machine identity, later kernel and initramfs hooks, snapshots and command-line changes | Rebuilds the platform's boot files, after upstream has started the Limine menu over where there is one | required | `omarchy-provision-owner`; ticket 36 | ## Platform registration @@ -69,6 +69,13 @@ A dispatch point takes one of two shapes: - After a factory reset left Limine entries for another machine identity, `refresh_boot_entries` starts the menu over from the template (core), then runs `boot-rebuild` if the platform implements it, and `limine-update` otherwise. - Everything else stays upstream: the wizard, account and login, the journal, slot retirement, the proof that the staged key opens nothing, and cleanup. +### Update (`bin/omarchy-update`) + +- `omarchy-update-boot preflight` runs after the dev checkout update and before the keyring and system packages change. A refusal stops the update like any failed step. +- `omarchy-update-boot verify` runs after the last package step. When it fails, the update still checks its log, refreshes the update indicator and releases Stay Awake, then says the update is not finished and exits 1 without `omarchy-update-restart`, so no reboot is offered. +- `omarchy-update-boot` resolves the operation as the user first and runs it with `sudo` only when it resolves to an entrypoint, so an update with nothing to run never asks for root. A failed resolution, such as a Mac without `omarchy-mac-boot`, fails the step with the dispatcher's message. +- The update path rebuilds no boot file itself: package hooks do, and `update-verify` catches what they missed. + ## Apple implementation `omarchy-mac-boot` implements the Apple operations. Draft #503 already moved the Apple boot code into `packages/omarchy-mac/boot/`, with sourced modules in `/usr/lib/omarchy-mac/boot` and commands in `/usr/bin`. Its modules become the implementation with small entrypoints around them: @@ -81,8 +88,8 @@ A dispatch point takes one of two shapes: | `stage_luks_rekey_apple` in `lib/factory-reset.sh` | `reset-prepare` | Ticket 34 | | `rebuild_next_boot_apple` (factory-kernel coherence refusal, rebuild in the factory root, `verify_limine_hashes`) | `reset-prepare`, `reset-verify` | Ticket 34 | | mx-mac's reset rollback, not yet in #503 | `reset-rollback` | Ticket 34 | -| `omarchy-mac-boot-update` | `boot-rebuild` | Thin entrypoint around the existing command. Provisioning uses it now. Ticket 35 wires the update path. | -| `omarchy-apple-silicon-boot-check` | `update-verify` | Ticket 35 | +| `omarchy-mac-boot-update` | `boot-rebuild` | Thin entrypoint around the existing command. Provisioning uses it now. | +| `omarchy-apple-silicon-boot-check` | `update-verify` | `entrypoints/update-verify` runs the check with the new kernel's reboot allowed to be pending: the kernel and initramfs in `/boot`, the device-tree set, m1n1 stage 2 and U-Boot on the system ESP, and Limine's loader, menu and UKI on that same ESP. On failure it says not to reboot and how to rebuild the boot files. | - **Packaging:** `packages/omarchy-mac/boot/install` gains one loop that installs `entrypoints/*` as `/usr/lib/omarchy/mac-boot/`, mode 755. The modules stay where #503 put them and are sourced by absolute path. - **Owner and recovery slots:** #503's `rekey_luks_apple` sequence folds into the shared journal. Its owner and recovery slot steps are core (`luks-rekey.sh`, `luks-recovery.sh`). Only its boot step is `provision-commit`. @@ -106,6 +113,7 @@ Snapdragon laptops boot Limine with unified kernel images, like x86, and `qualco - untrusted entrypoints - usage errors, and an undetermined platform - root ignoring fixture roots, `BASH_ENV` and exported functions +- `test/shell.d/update-boot-verify-test.sh` runs `omarchy update` through the real dispatcher: no-ops and no root on x86, generic aarch64 and Qualcomm; on Apple, preflight before the packages, and `omarchy-mac-boot`'s real `update-verify` and boot check on a fixture Mac, where a wrong device tree, a stale m1n1 or a missing UKI fails the update without offering the reboot. - `test/shell.d/luks-rekey-journal-test.sh` runs owner provisioning through the real dispatcher: - the crash-and-resume matrix on x86 (Limine UKI path unchanged, no Mac entrypoint runs) and on Apple with a fake boot package - setup stopping before the owner form when the boot package is missing or not ready From 52fc439b69dbcac22c95052f5de582facc90dcb0 Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 21:43:20 +1000 Subject: [PATCH 05/10] Limit update-verify to what the next boot reads The full boot check also fails a Mac that boots fine: package file drift, a second installed kernel, an extra LUKS keyslot or provisioning leftovers, and an m1n1 image its owner took over. --boot-chain leaves those to the full check, and update-verify uses it. --- .../boot/bin/omarchy-apple-silicon-boot-check | 41 ++++++++++--- .../boot/entrypoints/update-verify | 13 +++-- .../boot/test/fixtures/limine-mac.sh | 44 +++++++++++++- .../boot/test/update-verify-test.sh | 57 +++++++++++++++++++ 4 files changed, 138 insertions(+), 17 deletions(-) diff --git a/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check b/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check index 84c5c1e89328..bf9d6d03171a 100755 --- a/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check +++ b/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check @@ -1,7 +1,7 @@ #!/bin/bash # omarchy:summary=Check that the boot files match the installed Apple Silicon kernel and m1n1 -# omarchy:args=[linux-aurora|linux-asahi] +# omarchy:args=[--boot-chain] [linux-aurora|linux-asahi] # omarchy:hidden=true # omarchy:requires-sudo=true @@ -9,6 +9,13 @@ # m1n1 image with the installed package files. Read the ESP through a private # read-only mount; never regenerate boot files or mutate a release channel. # An explicit pending-reboot override checks installed boot files only. +# +# --boot-chain checks only what the next boot reads, for omarchy update's +# update-verify: the kernel, initramfs, unlock settings, device trees, m1n1 +# stage 2, U-Boot and Limine. It leaves out the installed files' mtree, a +# second installed kernel (the one whose m1n1 is installed boots), LUKS +# keyslots and provisioning leftovers, and an m1n1 image its owner took over +# with M1N1_UPDATE_DISABLED. set -euo pipefail @@ -26,10 +33,15 @@ path() { case "${1:-}" in -h | --help) - echo "Usage: omarchy-apple-silicon-boot-check [linux-aurora|linux-asahi]" + echo "Usage: omarchy-apple-silicon-boot-check [--boot-chain] [linux-aurora|linux-asahi]" exit 0 ;; esac +boot_chain=0 +if [[ ${1:-} == "--boot-chain" ]]; then + boot_chain=1 + shift +fi (( $# <= 1 )) || fail "takes at most one kernel" workdir=$(mktemp -d) @@ -52,7 +64,11 @@ kernel=${1:-} if [[ -z $kernel ]]; then kernels=() for candidate in linux-aurora linux-asahi; do - ! is_installed "$candidate" || kernels+=("$candidate") + if (( boot_chain )); then + ! is_installed "${bootloaders[$candidate]}" || kernels+=("$candidate") + else + ! is_installed "$candidate" || kernels+=("$candidate") + fi done (( ${#kernels[@]} == 1 )) || fail "cannot tell which kernel boots: ${kernels[*]:-neither linux-aurora nor linux-asahi} installed" @@ -64,14 +80,18 @@ bootloader=${bootloaders[$kernel]} for package in "$kernel" "$bootloader"; do is_installed "$package" || fail "$kernel boots with $bootloader, but $package is not installed" done -for package in linux-aurora m1n1-aurora linux-asahi m1n1; do +rivals=(linux-aurora m1n1-aurora linux-asahi m1n1) +(( ! boot_chain )) || rivals=() +for package in "${rivals[@]}"; do [[ $package == "$kernel" || $package == "$bootloader" ]] || ! is_installed "$package" || fail "$kernel boots with $bootloader, but $package is installed too" done # The mtree check, minus the depmod outputs: the kernel package ships # modules.* and the depmod hook rewrites them on every install, so their # modification times never match. Anything else altered or missing fails. -for package in "$kernel" "$bootloader"; do +mtree_packages=("$kernel" "$bootloader") +(( ! boot_chain )) || mtree_packages=() +for package in "${mtree_packages[@]}"; do set +e mtree_output=$(LC_ALL=C pacman -Qkk "$package" 2>&1) mtree_status=$? @@ -199,7 +219,7 @@ if (( has_crypttab_root )); then # First-boot window: throwaway keyfile and rd.luks.key= are allowed until # owner provisioning finishes (v3 item 1e). After that both must be gone, # the throwaway keyslot retired, and encrypt.state phase=finished. - if [[ ! -f $(path /var/lib/omarchy/provisioning/luks-key) && ! -f $(path /var/lib/omarchy/mac-first-boot/pending) ]]; then + if (( ! boot_chain )) && [[ ! -f $(path /var/lib/omarchy/provisioning/luks-key) && ! -f $(path /var/lib/omarchy/mac-first-boot/pending) ]]; then (( limine_mac )) || ! sudo grep -q 'rd.luks.key=' "$grub_cfg" || fail "/boot/grub/grub.cfg still has rd.luks.key= after provisioning" [[ ! -e $(path /boot/omarchy/luks-key) ]] || @@ -323,7 +343,7 @@ if (( limine_mac )); then mapper_uuid=$(sudo blkid -o value -s UUID /dev/mapper/root 2>/dev/null || true) [[ -z $mapper_uuid || ${limine_root#root=UUID=} == "$mapper_uuid" ]] || fail "the Limine $kernel entry root=UUID= does not name the filesystem on /dev/mapper/root" - if [[ ! -f $(path /var/lib/omarchy/provisioning/luks-key) && ! -f $(path /var/lib/omarchy/mac-first-boot/pending) ]]; then + if (( ! boot_chain )) && [[ ! -f $(path /var/lib/omarchy/provisioning/luks-key) && ! -f $(path /var/lib/omarchy/mac-first-boot/pending) ]]; then grep -q 'rd.luks.key=' <<<"$limine_cmdline" && fail "the Limine $kernel entry still has rd.luks.key= after provisioning" fi @@ -386,7 +406,7 @@ if [[ -e $config_file ]]; then esac done <"$workdir/config" fi -[[ -z $disabled ]] || +[[ -z $disabled ]] || (( boot_chain )) || fail "M1N1_UPDATE_DISABLED is set in /etc/default/update-m1n1, so m1n1 does not follow the kernel and its device trees cannot be vouched for; remove it, run sudo update-m1n1, then omarchy update" # ls -d prints what matches, and nothing at all when nothing does. @@ -582,6 +602,11 @@ report_running_release() { echo "Apple Silicon boot check: running $kernel $kver; installed boot files match" fi } +if [[ -n $disabled ]]; then + echo "Apple Silicon boot check: M1N1_UPDATE_DISABLED is set in /etc/default/update-m1n1, so m1n1/boot.bin is its owner's and is not checked" + report_running_release + exit 0 +fi if sudo cmp -s "$workdir/boot.bin" "$mountpoint/m1n1/boot.bin"; then report_running_release exit 0 diff --git a/packages/omarchy-mac/boot/entrypoints/update-verify b/packages/omarchy-mac/boot/entrypoints/update-verify index cfa2d1c797f2..2832e55e5daa 100755 --- a/packages/omarchy-mac/boot/entrypoints/update-verify +++ b/packages/omarchy-mac/boot/entrypoints/update-verify @@ -2,16 +2,17 @@ # omarchy-lifecycle-dispatch update-verify. omarchy update runs this after its # package transaction, migrations and hooks, and neither finishes nor offers a -# reboot until it passes. The boot check proves the boot chain boots what they -# installed: the kernel and initramfs in /boot, m1n1 stage 2 with that kernel's -# device trees and U-Boot on the system ESP, and on a Limine Mac the loader, -# menu and UKI on that same ESP. The installed kernel may be newer than the -# running one until that reboot. Nothing here rebuilds a boot file. +# reboot until it passes. The boot check, limited to the boot chain, proves the +# next boot reads what they installed: the kernel, initramfs and unlock +# settings, m1n1 stage 2 with that kernel's device trees and U-Boot on the +# system ESP, and on a Limine Mac the loader, menu and UKI on that same ESP. +# The installed kernel may be newer than the running one until that reboot. +# Nothing here rebuilds a boot file. set -uo pipefail echo -e "\e[32m\nVerify the Apple Silicon boot files\e[0m" -if ! OMARCHY_BOOT_CHECK_ALLOW_PENDING_REBOOT=1 omarchy-apple-silicon-boot-check; then +if ! OMARCHY_BOOT_CHECK_ALLOW_PENDING_REBOOT=1 omarchy-apple-silicon-boot-check --boot-chain; then cat >&2 <<'MESSAGE' This Mac might not boot what the update installed, so do not reboot yet. diff --git a/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh b/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh index 303042a63bab..d83d1364d9ed 100644 --- a/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh +++ b/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh @@ -21,7 +21,14 @@ SH case "$*" in -Qq) cat "$MAC_STATE/installed" ;; "-Qlq "*) [[ -f $MAC_STATE/files-$2 ]] && cat "$MAC_STATE/files-$2" ;; - "-Qkk "*) printf '%s: 2 total files, 0 altered files\n' "$2" ;; + "-Qkk "*) + if [[ -e $MAC_STATE/drift-$2 ]]; then + printf 'warning: %s: /usr/lib/modules/x/kernel/drift.ko.zst (Size mismatch)\n' "$2" >&2 + printf '%s: 2 total files, 1 altered files\n' "$2" + exit 1 + fi + printf '%s: 2 total files, 0 altered files\n' "$2" + ;; *) exit 1 ;; esac SH @@ -54,6 +61,15 @@ SH cat >"$mac_stubs/lsblk" <<'SH' #!/bin/bash exit 0 +SH + cat >"$mac_stubs/blkid" <<'SH' +#!/bin/bash +exit 2 +SH + cat >"$mac_stubs/cryptsetup" <<'SH' +#!/bin/bash +[[ $1 == luksDump && -f $MAC_STATE/luks-dump ]] || exit 1 +cat "$MAC_STATE/luks-dump" SH # A fixture UKI is the kernel followed by a marker: .linux is the whole file. cat >"$mac_stubs/objcopy" <<'SH' @@ -96,13 +112,14 @@ limine_mac_boot_bin() { # The Limine menu entry for the UKI, with the hash Limine verifies. limine_mac_menu() { local uki=$mac_esp/EFI/Linux/omarchy_linux-aurora.efi - printf '/+Omarchy\n //linux-aurora\n protocol: efi\n path: boot():/EFI/Linux/omarchy_linux-aurora.efi#%s\n cmdline: root=UUID=r rw rootflags=subvol=@ quiet\n' \ - "$(b2sum "$uki" | cut -d' ' -f1)" >"$mac_esp/limine.conf" + printf '/+Omarchy\n //linux-aurora\n protocol: efi\n path: boot():/EFI/Linux/omarchy_linux-aurora.efi#%s\n cmdline: %s\n' \ + "$(b2sum "$uki" | cut -d' ' -f1)" "$mac_cmdline" >"$mac_esp/limine.conf" } limine_mac() { local modules=$mac_root/usr/lib/modules/$mac_kver dtb mac_dtbs=(/usr/lib/modules/$mac_kver/dtbs/t6000-j314s.dtb /usr/lib/modules/$mac_kver/dtbs/t6020-j414s.dtb /usr/lib/modules/$mac_kver/dtbs/t8103-j274.dtb) + mac_cmdline="root=UUID=r rw rootflags=subvol=@ quiet" rm -rf "$mac_root" "$mac_state" mkdir -p "$modules/dtbs" "$mac_root/usr/lib/asahi-boot" "$mac_root/usr/bin" "$mac_root/usr/share/limine" \ "$mac_root/etc/default" "$mac_root/var/lib/omarchy" "$mac_root/run" \ @@ -167,6 +184,27 @@ SH printf '/usr/lib/asahi-boot/\n/usr/lib/asahi-boot/m1n1.bin\n' >"$mac_state/files-m1n1-aurora" } +# Makes the fixture an encrypted Mac whose owner setup finished: crypttab, the +# Limine entry's rd.luks.name=, a systemd initramfs with the cryptsetup +# generator, and the owner and recovery keyslots. $1 adds keyslots beyond those. +limine_mac_luks() { + local uuid=0422663f-9969-4953-900f-b342703b7e84 slot + printf '/dev/mapper/root / btrfs rw,subvol=/@ 0 0\n' >"$mac_root/etc/fstab" + printf 'root UUID=%s none luks\n' "$uuid" >"$mac_root/etc/crypttab" + printf 'usr/lib/modules/%s/kernel/drivers/gpu/drm/apple/appledrm.ko.zst\nusr/bin/init\nusr/bin/systemd-cryptsetup\nusr/lib/systemd/system-generators/systemd-cryptsetup-generator\n' \ + "$mac_kver" >"$mac_state/initramfs" + mkdir -p "$mac_root/boot/omarchy" + printf 'format=1\nphase=finished\npartition=p\nluks_uuid=%s\nowner_slot=0\nrecovery_slot=1\n' "$uuid" >"$mac_root/boot/omarchy/encrypt.state" + { + printf 'LUKS header information\nKeyslots:\n' + for (( slot = 0; slot < 2 + ${1:-0}; slot++ )); do + printf ' %s: luks2\n' "$slot" + done + } >"$mac_state/luks-dump" + mac_cmdline="root=UUID=r rw rootflags=subvol=@ rd.luks.name=$uuid=root quiet" + limine_mac_menu +} + # The environment the check reads the fixture through, one export per line: # $1 is where the boot check is, $2 the running kernel release (by default the # installed one). diff --git a/packages/omarchy-mac/boot/test/update-verify-test.sh b/packages/omarchy-mac/boot/test/update-verify-test.sh index 621cb650bb16..460165565c7e 100644 --- a/packages/omarchy-mac/boot/test/update-verify-test.sh +++ b/packages/omarchy-mac/boot/test/update-verify-test.sh @@ -101,3 +101,60 @@ printf 'usr/lib/modules/6.16.0-aurora9-ARCH/kernel/x.ko\n' >"$mac_state/initramf verify 6.16.0-aurora9-ARCH expect_refused "an initramfs built for the previous kernel" "does not hold the $mac_kver modules" pass "update-verify refuses a wrong device tree, a stale m1n1, a missing or stale UKI, another Limine or a stale initramfs, and says not to reboot" + +# update-verify checks only what the next boot reads. What the full boot check +# also holds against a Mac, the next boot does not read, so it never fails an +# update: the full check still refuses it. +full_check() { + set +e + ( + eval "$(limine_mac_env "$ROOT/bin")" + bash "$ROOT/bin/omarchy-apple-silicon-boot-check" + ) >"$tmp/full-out" 2>"$tmp/full-err" + full_status=$? + set -e +} + +beyond_boot_chain() { + local description=$1 reason=$2 + full_check + (( full_status == 1 )) && grep -Fq "$reason" "$tmp/full-err" || + fail "the full boot check refuses $description" "status $full_status: $(cat "$tmp/full-err")" + verify + expect_verified "$description" +} + +limine_mac +limine_mac_luks +full_check +(( full_status == 0 )) || fail "the full boot check passes an encrypted Limine Mac" "$(cat "$tmp/full-err")" +verify +expect_verified "an encrypted Limine Mac" +limine_mac_luks 1 +beyond_boot_chain "an encrypted Mac with a third LUKS keyslot" "throwaway LUKS keyslot still present" +limine_mac +printf 'M1N1_UPDATE_DISABLED=1\n' >>"$mac_root/etc/default/update-m1n1" +printf 'built by its owner\n' >>"$mac_esp/m1n1/boot.bin" +beyond_boot_chain "an m1n1 image its owner took over" "M1N1_UPDATE_DISABLED is set" +grep -Fq "m1n1/boot.bin is its owner's and is not checked" "$tmp/out" || fail "update-verify says it left m1n1 to its owner" "$(cat "$tmp/out")" +limine_mac +printf 'linux-asahi\n' >>"$mac_state/installed" +beyond_boot_chain "a Mac with a second kernel installed" "cannot tell which kernel boots" +grep -Fq "running linux-aurora $mac_kver" "$tmp/out" || fail "update-verify checks the kernel whose m1n1 is installed" "$(cat "$tmp/out")" +limine_mac +: >"$mac_state/drift-linux-aurora" +beyond_boot_chain "a kernel package file that drifted from its mtree" "linux-aurora files do not match the package mtree" +pass "update-verify passes a healthy Mac with an extra keyslot, an owner-built m1n1, a second kernel or drifted package files" + +limine_mac +limine_mac_luks +printf 'usr/lib/modules/%s/kernel/x.ko\nusr/bin/init\n' "$mac_kver" >"$mac_state/initramfs" +verify +expect_refused "an encrypted Mac whose initramfs cannot unlock the root" "does not contain sd-encrypt" +limine_mac +limine_mac_luks +mac_cmdline="root=UUID=r rw rootflags=subvol=@ quiet" +limine_mac_menu +verify +expect_refused "an encrypted Mac whose Limine entry does not unlock the root" "does not set rd.luks.name= for the encrypted root" +pass "update-verify still refuses an encrypted Mac whose next boot cannot unlock its root" From 7fab251909dc02728a87a34aa442918491ba86e2 Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 21:43:20 +1000 Subject: [PATCH 06/10] Name an installed boot package that lacks a required operation The dispatcher said the package was not installed when an older copy was. It now names the installed version and asks for its update, and exits 3 only when the package is missing altogether. --- bin/omarchy-lifecycle-dispatch | 21 ++++++++++++++++++++- test/shell.d/lifecycle-dispatch-test.sh | 21 +++++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/bin/omarchy-lifecycle-dispatch b/bin/omarchy-lifecycle-dispatch index 86cde25a1bd9..75339cbeee69 100755 --- a/bin/omarchy-lifecycle-dispatch +++ b/bin/omarchy-lifecycle-dispatch @@ -113,10 +113,29 @@ trusted() { entrypoint=$root$implementation/$operation +# The package's own pacman record tells a machine without it from one whose +# copy predates the operation. +installed_version() { + local record + for record in "$root/var/lib/pacman/local/$package"-[0-9]*/; do + [[ -d $record ]] || continue + record=${record%/} + printf '%s\n' "${record##*/"$package"-}" + return 0 + done + return 1 +} + +# 3 is a machine without the platform's boot package at all, which a caller may +# tell apart from a failure; 1 is everything else. if [[ ! -e $entrypoint && ! -L $entrypoint ]]; then if listed "$operation" "${required[@]}"; then + if version=$(installed_version); then + echo "Error: $operation on $platform needs $implementation/$operation, which $package $version does not provide; update $package" >&2 + exit 1 + fi echo "Error: $operation on $platform needs $package, which provides $implementation/$operation; it is not installed" >&2 - exit 1 + exit 3 fi exit 0 fi diff --git a/test/shell.d/lifecycle-dispatch-test.sh b/test/shell.d/lifecycle-dispatch-test.sh index 696ce2d58199..c03b0ff9a2e1 100755 --- a/test/shell.d/lifecycle-dispatch-test.sh +++ b/test/shell.d/lifecycle-dispatch-test.sh @@ -97,16 +97,29 @@ for operation in "${operations[@]}"; do output=$(on apple-silicon "$empty" --resolve "$operation" 2>&1) && [[ -z $output ]] || fail "apple: optional $operation resolves to nothing without the boot package" "$output" else - (( status == 1 )) || fail "apple: required $operation fails without the boot package" "status: $status" + (( status == 3 )) || fail "apple: required $operation fails with status 3 without the boot package" "status: $status" [[ $output == "Error: $operation on apple-silicon needs omarchy-mac-boot, which provides /usr/lib/omarchy/mac-boot/$operation; it is not installed" ]] || fail "apple: required $operation names the missing package and entrypoint" "$output" - if on apple-silicon "$empty" --resolve "$operation" >/dev/null 2>&1; then - fail "apple: required $operation does not resolve without the boot package" - fi + status=0 + on apple-silicon "$empty" --resolve "$operation" >/dev/null 2>&1 || status=$? + (( status == 3 )) || fail "apple: required $operation does not resolve without the boot package" "status: $status" fi done pass "apple: without omarchy-mac-boot required operations fail with a clear message and optional ones are no-ops" +# An installed omarchy-mac-boot that predates an operation is named with its +# version, as an update away rather than missing. +older=$tmp/older +mkdir -p "$older/usr/lib/omarchy/mac-boot" "$older/var/lib/pacman/local/omarchy-mac-boot-20260921-10" +for operation in "${operations[@]}"; do + [[ " ${apple_optional[*]} " == *" $operation "* ]] && continue + status=0 + output=$(on apple-silicon "$older" "$operation" 2>&1) || status=$? + (( status == 1 )) && [[ $output == "Error: $operation on apple-silicon needs /usr/lib/omarchy/mac-boot/$operation, which omarchy-mac-boot 20260921-10 does not provide; update omarchy-mac-boot" ]] || + fail "apple: an omarchy-mac-boot without $operation is named with its version" "status $status: $output" +done +pass "apple: an installed omarchy-mac-boot that lacks a required operation fails asking for its update" + # An entrypoint anyone but root could have changed never runs, optional or not. untrusted() { local description=$1 operation=$2 From 01c40a89b3ee483eefa4c561f94516c1454ab816 Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 21:43:20 +1000 Subject: [PATCH 07/10] Warn instead of blocking an update on a Mac without omarchy-mac-boot Such a Mac predates the package and boots a chain it does not manage, so verification cannot vouch for it and blocking would fail every update until its migration installs the package. An omarchy-mac-boot too old to ship update-verify still blocks. --- bin/omarchy-update-boot | 18 ++++++++++++++---- docs/lifecycle-dispatch.md | 7 ++++--- docs/update-process.md | 2 +- test/shell.d/update-boot-verify-test.sh | 23 ++++++++++++++++------- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/bin/omarchy-update-boot b/bin/omarchy-update-boot index eb98b39cd31b..db97cd596423 100755 --- a/bin/omarchy-update-boot +++ b/bin/omarchy-update-boot @@ -23,9 +23,19 @@ case ${1:-} in esac # Resolving as the user keeps sudo, and its password prompt, out of updates -# with nothing to run. A resolution that fails has said why, and fails the -# check. Root resolves again from its own fixed paths before anything runs. -entrypoint=$(omarchy-lifecycle-dispatch --resolve "$operation") -if [[ -n $entrypoint ]]; then +# with nothing to run. Root resolves again from its own fixed paths before +# anything runs. +status=0 +resolved=$(omarchy-lifecycle-dispatch --resolve "$operation" 2>&1) || status=$? + +# 3: the platform's boot package is not installed at all. Such a machine +# predates it and boots a chain the package does not manage, so verification +# warns instead of failing every update until its migration installs it. +if (( status == 3 )) && [[ $operation == "update-verify" ]]; then + echo -e "\e[33m\n${resolved#Error: }\nThe boot files were not verified. This machine predates its platform's boot package; updates verify them once its migration installs it.\e[0m" >&2 +elif (( status != 0 )); then + echo "$resolved" >&2 + exit "$status" +elif [[ -n $resolved ]]; then sudo omarchy-lifecycle-dispatch "$operation" fi diff --git a/docs/lifecycle-dispatch.md b/docs/lifecycle-dispatch.md index 8a495cebd57e..5bcb258f27f9 100644 --- a/docs/lifecycle-dispatch.md +++ b/docs/lifecycle-dispatch.md @@ -15,7 +15,8 @@ The first form runs the operation. `--resolve` prints the entrypoint the operati | --- | --- | --- | | The platform registers no boot package (`generic`, `generic-aarch64`, and `qualcomm` today) | no-op, exit 0 | prints nothing, exit 0 | | The entrypoint exists and passes the trust rules | execs it; its exit status is the result | prints its path | -| A required operation has no entrypoint | exit 1: `Error: on needs , which provides ; it is not installed` | same error | +| A required operation has no entrypoint, and the package is not installed | exit 3: `Error: on needs , which provides ; it is not installed` | same error | +| A required operation has no entrypoint, but the package is installed (its pacman record says so) | exit 1: `Error: on needs , which does not provide; update ` | same error | | An optional operation has no entrypoint | no-op, exit 0 | prints nothing, exit 0 | | The entrypoint fails the trust rules | exit 1: `Error: refusing : ...` (optional operations too) | same error | | `omarchy-hw-platform` can't settle the platform | exit 1 | exit 1 | @@ -73,7 +74,7 @@ A dispatch point takes one of two shapes: - `omarchy-update-boot preflight` runs after the dev checkout update and before the keyring and system packages change. A refusal stops the update like any failed step. - `omarchy-update-boot verify` runs after the last package step. When it fails, the update still checks its log, refreshes the update indicator and releases Stay Awake, then says the update is not finished and exits 1 without `omarchy-update-restart`, so no reboot is offered. -- `omarchy-update-boot` resolves the operation as the user first and runs it with `sudo` only when it resolves to an entrypoint, so an update with nothing to run never asks for root. A failed resolution, such as a Mac without `omarchy-mac-boot`, fails the step with the dispatcher's message. +- `omarchy-update-boot` resolves the operation as the user first and runs it with `sudo` only when it resolves to an entrypoint, so an update with nothing to run never asks for root. A failed resolution fails the step with the dispatcher's message, except one: `update-verify` on a machine without its platform's boot package at all (exit 3) warns that the boot files were not verified and lets the update finish. Such a machine predates the package and boots a chain it does not manage; its migration installs the package, and from then on a failed verification blocks. A package too old to ship `update-verify` blocks, since the fix is one package update away. - The update path rebuilds no boot file itself: package hooks do, and `update-verify` catches what they missed. ## Apple implementation @@ -89,7 +90,7 @@ A dispatch point takes one of two shapes: | `rebuild_next_boot_apple` (factory-kernel coherence refusal, rebuild in the factory root, `verify_limine_hashes`) | `reset-prepare`, `reset-verify` | Ticket 34 | | mx-mac's reset rollback, not yet in #503 | `reset-rollback` | Ticket 34 | | `omarchy-mac-boot-update` | `boot-rebuild` | Thin entrypoint around the existing command. Provisioning uses it now. | -| `omarchy-apple-silicon-boot-check` | `update-verify` | `entrypoints/update-verify` runs the check with the new kernel's reboot allowed to be pending: the kernel and initramfs in `/boot`, the device-tree set, m1n1 stage 2 and U-Boot on the system ESP, and Limine's loader, menu and UKI on that same ESP. On failure it says not to reboot and how to rebuild the boot files. | +| `omarchy-apple-silicon-boot-check` | `update-verify` | `entrypoints/update-verify` runs the check limited to the boot chain (`--boot-chain`), with the new kernel's reboot allowed to be pending: the kernel and initramfs in `/boot`, the device-tree set, m1n1 stage 2 and U-Boot on the system ESP, and Limine's loader, menu and UKI on that same ESP. It leaves out what the next boot does not read: package file drift, a second installed kernel, LUKS keyslots and provisioning leftovers, and an m1n1 image its owner took over with `M1N1_UPDATE_DISABLED`. On failure it says not to reboot and how to rebuild the boot files. | - **Packaging:** `packages/omarchy-mac/boot/install` gains one loop that installs `entrypoints/*` as `/usr/lib/omarchy/mac-boot/`, mode 755. The modules stay where #503 put them and are sourced by absolute path. - **Owner and recovery slots:** #503's `rekey_luks_apple` sequence folds into the shared journal. Its owner and recovery slot steps are core (`luks-rekey.sh`, `luks-recovery.sh`). Only its boot step is `provision-commit`. diff --git a/docs/update-process.md b/docs/update-process.md index f2e28cdfec87..57339822898d 100644 --- a/docs/update-process.md +++ b/docs/update-process.md @@ -157,7 +157,7 @@ Important behavior: `omarchy-migrate` after pacman finishes. - A failure should leave enough output in `/tmp/omarchy-update.log` and the terminal transcript to debug. -- Both boot checks are [lifecycle dispatch](lifecycle-dispatch.md) operations (`update-preflight`, `update-verify`), no-ops on platforms whose boot chain needs no handling of its own, x86 included. A refused preflight stops the update like any failed step. A failed verification lets the update finish its remaining reporting steps, then it exits non-zero without `omarchy-update-restart`: the update is not finished and offers no reboot. On Apple Silicon, `omarchy-mac-boot` verifies the kernel and initramfs in `/boot`, m1n1 stage 2 with the kernel's device trees and U-Boot on the system ESP, and Limine's loader, menu and UKI on that ESP. +- Both boot checks are [lifecycle dispatch](lifecycle-dispatch.md) operations (`update-preflight`, `update-verify`), no-ops on platforms whose boot chain needs no handling of its own, x86 included. A refused preflight stops the update like any failed step. A failed verification lets the update finish its remaining reporting steps, then it exits non-zero without `omarchy-update-restart`: the update is not finished and offers no reboot. On Apple Silicon, `omarchy-mac-boot` verifies what the next boot reads: the kernel, initramfs and unlock settings, m1n1 stage 2 with the kernel's device trees and U-Boot on the system ESP, and Limine's loader, menu and UKI on that ESP. A Mac without `omarchy-mac-boot` at all predates it: the update warns that its boot files were not verified and finishes. ## Path 2: direct `sudo pacman -Syu` attempt diff --git a/test/shell.d/update-boot-verify-test.sh b/test/shell.d/update-boot-verify-test.sh index 8fb847431b27..cfc0c326b492 100755 --- a/test/shell.d/update-boot-verify-test.sh +++ b/test/shell.d/update-boot-verify-test.sh @@ -189,12 +189,21 @@ rm "$mac_esp/EFI/Linux/omarchy_linux-aurora.efi" blocked "a missing UKI" "/boot/efi/EFI/Linux/omarchy_linux-aurora.efi (the Limine UKI) is missing" pass "apple: a wrong device tree, a stale m1n1 or a missing UKI fails the update, explained, with no reboot offered" -# A Mac without omarchy-mac-boot cannot prove its boot chain: preflight is -# optional, verify is not. +# A Mac without omarchy-mac-boot at all predates it and boots a chain it does +# not manage: preflight is optional, and verify warns instead of blocking. mkdir -p "$tmp/no-package" run_update apple-silicon "$tmp/no-package" -(( status == 1 )) && ! ran omarchy-update-restart || fail "apple: without omarchy-mac-boot the update fails and offers no reboot" "status $status" -ran omarchy-update-system-pkgs || fail "apple: without omarchy-mac-boot the optional preflight is a no-op" -grep -Fq "update-verify on apple-silicon needs omarchy-mac-boot" "$tmp/err" && grep -Fq "The update is not finished" "$tmp/err" || - fail "apple: without omarchy-mac-boot the update names the package" "$(cat "$tmp/err")" -pass "apple: without omarchy-mac-boot the update is not finished and names the missing package" +(( status == 0 )) && ran omarchy-update-system-pkgs && ran omarchy-update-restart || + fail "apple: without omarchy-mac-boot the update finishes and offers the reboot" "status $status: $(cat "$tmp/err")" +grep -Fq "update-verify on apple-silicon needs omarchy-mac-boot" "$tmp/err" && grep -Fq "The boot files were not verified" "$tmp/err" || + fail "apple: without omarchy-mac-boot the update says the boot files were not verified" "$(cat "$tmp/err")" +[[ ! -s $tmp/sudo ]] || fail "apple: without omarchy-mac-boot nothing asks for root" "$(cat "$tmp/sudo")" +pass "apple: without omarchy-mac-boot the update warns that the boot files were not verified" + +# An omarchy-mac-boot from before update-verify is one package update away. +mkdir -p "$tmp/older/usr/lib/omarchy/mac-boot" "$tmp/older/var/lib/pacman/local/omarchy-mac-boot-20260921-10" +run_update apple-silicon "$tmp/older" +(( status == 1 )) && ! ran omarchy-update-restart || fail "apple: an omarchy-mac-boot without update-verify fails the update and offers no reboot" "status $status" +grep -Fq "update-verify on apple-silicon needs /usr/lib/omarchy/mac-boot/update-verify, which omarchy-mac-boot 20260921-10 does not provide; update omarchy-mac-boot" "$tmp/err" && + grep -Fq "The update is not finished" "$tmp/err" || fail "apple: an omarchy-mac-boot without update-verify is named with its version" "$(cat "$tmp/err")" +pass "apple: an omarchy-mac-boot without update-verify fails the update and asks for its update" From 978c992751db1e396918c8348b82939cb1c6b39a Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 21:52:25 +1000 Subject: [PATCH 08/10] Check the kernel the boot menu starts, and the boot files' sources With two kernels installed, --boot-chain picked the one whose m1n1 was installed, which is not what boots: it now checks the menu's first kernel. It also holds the kernel image, device trees and m1n1 against their package mtree again, leaving out only the rest of the package's files. --- .../boot/bin/omarchy-apple-silicon-boot-check | 58 +++++++++++++------ .../test/apple-silicon-boot-check-test.sh | 5 ++ .../boot/test/fixtures/limine-mac.sh | 3 +- .../boot/test/update-verify-test.sh | 42 ++++++++++++-- 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check b/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check index bf9d6d03171a..3f88e9d4ade0 100755 --- a/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check +++ b/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check @@ -12,10 +12,11 @@ # # --boot-chain checks only what the next boot reads, for omarchy update's # update-verify: the kernel, initramfs, unlock settings, device trees, m1n1 -# stage 2, U-Boot and Limine. It leaves out the installed files' mtree, a -# second installed kernel (the one whose m1n1 is installed boots), LUKS -# keyslots and provisioning leftovers, and an m1n1 image its owner took over -# with M1N1_UPDATE_DISABLED. +# stage 2, U-Boot and Limine. It holds only the kernel image, device trees and +# m1n1 against their package mtree, checks the kernel the boot menu starts +# first when both kernels are installed, and leaves out LUKS keyslots and +# provisioning leftovers and an m1n1 image its owner took over with +# M1N1_UPDATE_DISABLED. set -euo pipefail @@ -60,19 +61,38 @@ installed=$(pacman -Qq) || fail "cannot list the installed packages" is_installed() { grep -Fxq -- "$1" <<<"$installed" } +# The ESP Limine's tooling writes to: ESP_PATH, /boot/efi or on older +# installs /boot. +limine_esp_path() { + sudo sed -n -E 's/^[[:space:]]*ESP_PATH=("([^"]*)"|'\''([^'\'']*)'\''|([^[:space:]#"'\'']*)).*/\2\3\4/p' "$(path /etc/default/limine)" | tail -n 1 +} + +# The kernel the boot menu starts: the first kernel entry in Limine's menu, +# where the tool writes the Omarchy block first, else GRUB's first entry. +menu_kernel() { + if [[ -e $(path /var/lib/omarchy/limine.enabled) && -f $(path /etc/default/limine) ]]; then + sudo awk '{ sub(/^[[:space:]]+/, "") } /^\/\/linux-(aurora|asahi)$/ { print substr($0, 3); exit }' \ + "$(path "$(limine_esp_path)/limine.conf")" 2>/dev/null + else + sudo grep -Eo 'vmlinuz-linux-(aurora|asahi)' "$(path /boot/grub/grub.cfg)" 2>/dev/null | sed -n '1s/^vmlinuz-//p' + fi +} + kernel=${1:-} if [[ -z $kernel ]]; then kernels=() for candidate in linux-aurora linux-asahi; do - if (( boot_chain )); then - ! is_installed "${bootloaders[$candidate]}" || kernels+=("$candidate") - else - ! is_installed "$candidate" || kernels+=("$candidate") - fi + ! is_installed "$candidate" || kernels+=("$candidate") done - (( ${#kernels[@]} == 1 )) || - fail "cannot tell which kernel boots: ${kernels[*]:-neither linux-aurora nor linux-asahi} installed" - kernel=${kernels[0]} + if (( boot_chain && ${#kernels[@]} == 2 )); then + kernel=$(menu_kernel || true) + [[ -n $kernel ]] || + fail "cannot tell which kernel boots: linux-aurora and linux-asahi are installed, and the boot menu starts neither" + else + (( ${#kernels[@]} == 1 )) || + fail "cannot tell which kernel boots: ${kernels[*]:-neither linux-aurora nor linux-asahi} installed" + kernel=${kernels[0]} + fi fi [[ -n ${bootloaders[$kernel]:-} ]] || fail "$kernel is not a kernel this check knows; it checks linux-aurora with m1n1-aurora and linux-asahi with m1n1" @@ -89,9 +109,7 @@ done # The mtree check, minus the depmod outputs: the kernel package ships # modules.* and the depmod hook rewrites them on every install, so their # modification times never match. Anything else altered or missing fails. -mtree_packages=("$kernel" "$bootloader") -(( ! boot_chain )) || mtree_packages=() -for package in "${mtree_packages[@]}"; do +for package in "$kernel" "$bootloader"; do set +e mtree_output=$(LC_ALL=C pacman -Qkk "$package" 2>&1) mtree_status=$? @@ -100,9 +118,15 @@ for package in "${mtree_packages[@]}"; do altered=$(grep -Ev ' altered files$' <<<"$mtree_output" | grep -Ev "^warning: database file for '[^']+' does not exist" | grep -Ev '^warning: [^:]+: /usr/lib/modules/[^/]+/modules\.[A-Za-z.]+ \(Modification time mismatch\)$' || true) + # --boot-chain holds only the files the boot files are built from: the + # kernel image, its device trees and m1n1. + if (( boot_chain )); then + altered=$(grep -E '^warning: [^:]+: /usr/lib/(modules/[^/]+/(vmlinuz|dtbs/)|asahi-boot/)' <<<"$altered" || true) + fi [[ -z $altered ]] || fail "installed $package files do not match the package mtree: $(head -n 1 <<<"$altered")" # pacman exits 1 for the depmod lines alone; any other failure is one. (( mtree_status == 0 )) || grep -Fq '(Modification time mismatch)' <<<"$mtree_output" || + { (( boot_chain )) && grep -q '^warning: ' <<<"$mtree_output"; } || fail "pacman -Qkk $package failed" done @@ -262,9 +286,7 @@ fi # the LUKS mapping) the system needs, and the U-Boot slot must hold the # installed Limine. if (( limine_mac )); then - # The ESP Limine's tooling writes to: ESP_PATH, /boot/efi or on older - # installs /boot. - limine_esp=$(sudo sed -n -E 's/^[[:space:]]*ESP_PATH=("([^"]*)"|'\''([^'\'']*)'\''|([^[:space:]#"'\'']*)).*/\2\3\4/p' "$(path /etc/default/limine)" | tail -n 1) + limine_esp=$(limine_esp_path) [[ $limine_esp == /* ]] || fail "/etc/default/limine names no ESP_PATH" limine_cfg=$(path "$limine_esp/limine.conf") limine_uki=$(path "$limine_esp/EFI/Linux/omarchy_$kernel.efi") diff --git a/packages/omarchy-mac/boot/test/apple-silicon-boot-check-test.sh b/packages/omarchy-mac/boot/test/apple-silicon-boot-check-test.sh index 783a2303b02f..1c948053f114 100644 --- a/packages/omarchy-mac/boot/test/apple-silicon-boot-check-test.sh +++ b/packages/omarchy-mac/boot/test/apple-silicon-boot-check-test.sh @@ -724,4 +724,9 @@ limine_on_system_esp sed -i 's/quiet$/quiet splash/' "$existing/limine.conf" TEST_EXISTING_MOUNT="$existing" run_check expect_fail "a system ESP with another menu" "/boot/efi/limine.conf is not the one on the system ESP" +limine_on_system_esp +printf 'M1N1_UPDATE_DISABLED=1\n' >"$root/etc/default/update-m1n1" +printf 'GRUB\n' >"$existing/EFI/BOOT/BOOTAA64.EFI" +TEST_EXISTING_MOUNT="$existing" run_check --boot-chain +expect_fail "an m1n1 left to its owner beside another loader on the system ESP" "/boot/efi/EFI/BOOT/BOOTAA64.EFI is not the one on the system ESP" pass "a Limine Mac boots the Limine, menu and UKI on the system ESP" diff --git a/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh b/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh index d83d1364d9ed..910d17f30d82 100644 --- a/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh +++ b/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh @@ -22,8 +22,9 @@ case "$*" in -Qq) cat "$MAC_STATE/installed" ;; "-Qlq "*) [[ -f $MAC_STATE/files-$2 ]] && cat "$MAC_STATE/files-$2" ;; "-Qkk "*) + # drift- names the file that drifted. if [[ -e $MAC_STATE/drift-$2 ]]; then - printf 'warning: %s: /usr/lib/modules/x/kernel/drift.ko.zst (Size mismatch)\n' "$2" >&2 + printf 'warning: %s: %s (Size mismatch)\n' "$2" "$(cat "$MAC_STATE/drift-$2")" >&2 printf '%s: 2 total files, 1 altered files\n' "$2" exit 1 fi diff --git a/packages/omarchy-mac/boot/test/update-verify-test.sh b/packages/omarchy-mac/boot/test/update-verify-test.sh index 460165565c7e..21b0c4f24de0 100644 --- a/packages/omarchy-mac/boot/test/update-verify-test.sh +++ b/packages/omarchy-mac/boot/test/update-verify-test.sh @@ -137,14 +137,46 @@ printf 'M1N1_UPDATE_DISABLED=1\n' >>"$mac_root/etc/default/update-m1n1" printf 'built by its owner\n' >>"$mac_esp/m1n1/boot.bin" beyond_boot_chain "an m1n1 image its owner took over" "M1N1_UPDATE_DISABLED is set" grep -Fq "m1n1/boot.bin is its owner's and is not checked" "$tmp/out" || fail "update-verify says it left m1n1 to its owner" "$(cat "$tmp/out")" +# A second kernel, older, with its own entry after the one the menu starts. +second_kernel() { + local asahi=6.14.8-asahi1-1-ARCH + mkdir -p "$mac_root/usr/lib/modules/$asahi/dtbs" + printf 'linux-asahi kernel\n' >"$mac_root/usr/lib/modules/$asahi/vmlinuz" + printf 'linux-asahi\n' >>"$mac_state/installed" + printf '/usr/lib/modules/%s/vmlinuz\n' "$asahi" >"$mac_state/files-linux-asahi" +} limine_mac -printf 'linux-asahi\n' >>"$mac_state/installed" +second_kernel +printf ' //linux-asahi\n protocol: efi\n path: boot():/EFI/Linux/omarchy_linux-asahi.efi#0\n cmdline: quiet\n' >>"$mac_esp/limine.conf" beyond_boot_chain "a Mac with a second kernel installed" "cannot tell which kernel boots" -grep -Fq "running linux-aurora $mac_kver" "$tmp/out" || fail "update-verify checks the kernel whose m1n1 is installed" "$(cat "$tmp/out")" +grep -Fq "running linux-aurora $mac_kver" "$tmp/out" || fail "update-verify checks the kernel the menu starts" "$(cat "$tmp/out")" +limine_mac +printf '/usr/lib/modules/%s/kernel/drivers/gpu/drm/apple/appledrm.ko.zst\n' "$mac_kver" >"$mac_state/drift-linux-aurora" +beyond_boot_chain "a kernel module that drifted from its mtree" "linux-aurora files do not match the package mtree" +pass "update-verify passes a healthy Mac with an extra keyslot, an owner-built m1n1, a second kernel or a drifted module" + +# What the boot files are built from still has to match its package. +for drifted in "/usr/lib/modules/$mac_kver/vmlinuz" "${mac_dtbs[0]}"; do + limine_mac + printf '%s\n' "$drifted" >"$mac_state/drift-linux-aurora" + verify + expect_refused "a drifted ${drifted##*/}" "installed linux-aurora files do not match the package mtree: warning: linux-aurora: $drifted" +done limine_mac -: >"$mac_state/drift-linux-aurora" -beyond_boot_chain "a kernel package file that drifted from its mtree" "linux-aurora files do not match the package mtree" -pass "update-verify passes a healthy Mac with an extra keyslot, an owner-built m1n1, a second kernel or drifted package files" +printf '/usr/lib/asahi-boot/m1n1.bin\n' >"$mac_state/drift-m1n1-aurora" +verify +expect_refused "a drifted m1n1" "installed m1n1-aurora files do not match the package mtree" +# With two kernels, the one the menu starts is checked, and it must boot. +limine_mac +second_kernel +{ + printf '/+Omarchy\n //linux-asahi\n protocol: efi\n path: boot():/EFI/Linux/omarchy_linux-asahi.efi#0\n cmdline: quiet\n' + sed 1d "$mac_esp/limine.conf" +} >"$tmp/limine.conf" +cp "$tmp/limine.conf" "$mac_esp/limine.conf" +verify +expect_refused "a Mac whose menu starts the second kernel first" "linux-asahi boots with m1n1, but m1n1 is not installed" +pass "update-verify still refuses a drifted kernel image, device tree or m1n1, and checks the kernel the menu starts" limine_mac limine_mac_luks From 3b1d2e490bce9956dc9090d6005f0a72e7d57531 Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 21:52:25 +1000 Subject: [PATCH 09/10] Keep stderr out of the boot helper's decision to use sudo A warning on stderr from a successful resolution counted as an entrypoint, so an x86 update could still call sudo. --- bin/omarchy-update-boot | 8 +++++--- docs/lifecycle-dispatch.md | 4 ++-- test/shell.d/update-boot-verify-test.sh | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/omarchy-update-boot b/bin/omarchy-update-boot index db97cd596423..c9271170193f 100755 --- a/bin/omarchy-update-boot +++ b/bin/omarchy-update-boot @@ -25,16 +25,18 @@ esac # Resolving as the user keeps sudo, and its password prompt, out of updates # with nothing to run. Root resolves again from its own fixed paths before # anything runs. +errors=$(mktemp) +trap 'rm -f "$errors"' EXIT status=0 -resolved=$(omarchy-lifecycle-dispatch --resolve "$operation" 2>&1) || status=$? +resolved=$(omarchy-lifecycle-dispatch --resolve "$operation" 2>"$errors") || status=$? # 3: the platform's boot package is not installed at all. Such a machine # predates it and boots a chain the package does not manage, so verification # warns instead of failing every update until its migration installs it. if (( status == 3 )) && [[ $operation == "update-verify" ]]; then - echo -e "\e[33m\n${resolved#Error: }\nThe boot files were not verified. This machine predates its platform's boot package; updates verify them once its migration installs it.\e[0m" >&2 + echo -e "\e[33m\n$(sed 's/^Error: //' "$errors")\nThe boot files were not verified. This machine predates its platform's boot package; updates verify them once its migration installs it.\e[0m" >&2 elif (( status != 0 )); then - echo "$resolved" >&2 + cat "$errors" >&2 exit "$status" elif [[ -n $resolved ]]; then sudo omarchy-lifecycle-dispatch "$operation" diff --git a/docs/lifecycle-dispatch.md b/docs/lifecycle-dispatch.md index 5bcb258f27f9..d1dcdec0e9b9 100644 --- a/docs/lifecycle-dispatch.md +++ b/docs/lifecycle-dispatch.md @@ -15,7 +15,7 @@ The first form runs the operation. `--resolve` prints the entrypoint the operati | --- | --- | --- | | The platform registers no boot package (`generic`, `generic-aarch64`, and `qualcomm` today) | no-op, exit 0 | prints nothing, exit 0 | | The entrypoint exists and passes the trust rules | execs it; its exit status is the result | prints its path | -| A required operation has no entrypoint, and the package is not installed | exit 3: `Error: on needs , which provides ; it is not installed` | same error | +| A required operation has no entrypoint, and the package is not installed | exit 3 (an entrypoint's own status could also be 3; with `--resolve` it is only this): `Error: on needs , which provides ; it is not installed` | same error | | A required operation has no entrypoint, but the package is installed (its pacman record says so) | exit 1: `Error: on needs , which does not provide; update ` | same error | | An optional operation has no entrypoint | no-op, exit 0 | prints nothing, exit 0 | | The entrypoint fails the trust rules | exit 1: `Error: refusing : ...` (optional operations too) | same error | @@ -90,7 +90,7 @@ A dispatch point takes one of two shapes: | `rebuild_next_boot_apple` (factory-kernel coherence refusal, rebuild in the factory root, `verify_limine_hashes`) | `reset-prepare`, `reset-verify` | Ticket 34 | | mx-mac's reset rollback, not yet in #503 | `reset-rollback` | Ticket 34 | | `omarchy-mac-boot-update` | `boot-rebuild` | Thin entrypoint around the existing command. Provisioning uses it now. | -| `omarchy-apple-silicon-boot-check` | `update-verify` | `entrypoints/update-verify` runs the check limited to the boot chain (`--boot-chain`), with the new kernel's reboot allowed to be pending: the kernel and initramfs in `/boot`, the device-tree set, m1n1 stage 2 and U-Boot on the system ESP, and Limine's loader, menu and UKI on that same ESP. It leaves out what the next boot does not read: package file drift, a second installed kernel, LUKS keyslots and provisioning leftovers, and an m1n1 image its owner took over with `M1N1_UPDATE_DISABLED`. On failure it says not to reboot and how to rebuild the boot files. | +| `omarchy-apple-silicon-boot-check` | `update-verify` | `entrypoints/update-verify` runs the check limited to the boot chain (`--boot-chain`), with the new kernel's reboot allowed to be pending: the kernel and initramfs in `/boot`, the device-tree set, m1n1 stage 2 and U-Boot on the system ESP, and Limine's loader, menu and UKI on that same ESP. It holds only the kernel image, device trees and m1n1 against their packages, checks the kernel the boot menu starts first when both kernels are installed, and leaves out LUKS keyslots, provisioning leftovers and an m1n1 image its owner took over with `M1N1_UPDATE_DISABLED`. On failure it says not to reboot and how to rebuild the boot files. | - **Packaging:** `packages/omarchy-mac/boot/install` gains one loop that installs `entrypoints/*` as `/usr/lib/omarchy/mac-boot/`, mode 755. The modules stay where #503 put them and are sourced by absolute path. - **Owner and recovery slots:** #503's `rekey_luks_apple` sequence folds into the shared journal. Its owner and recovery slot steps are core (`luks-rekey.sh`, `luks-recovery.sh`). Only its boot step is `provision-commit`. diff --git a/test/shell.d/update-boot-verify-test.sh b/test/shell.d/update-boot-verify-test.sh index cfc0c326b492..6ece8ed9edca 100755 --- a/test/shell.d/update-boot-verify-test.sh +++ b/test/shell.d/update-boot-verify-test.sh @@ -125,6 +125,10 @@ for platform in generic generic-aarch64 qualcomm; do [[ ! -e $tmp/boot-ran ]] || fail "$platform: no Mac entrypoint runs" "$(cat "$tmp/boot-ran")" [[ ! -s $tmp/sudo ]] || fail "$platform: the boot checks ask for no root" "$(cat "$tmp/sudo")" done +# Warnings on stderr, such as bash's for a locale it cannot load, are not an +# entrypoint to run as root. +LC_ALL=xx_XX.UTF-8 run_update generic "$tmp/failing" +(( status == 0 )) && [[ ! -s $tmp/sudo ]] || fail "generic: stderr noise asks for no root" "status $status: $(cat "$tmp/sudo" "$tmp/err")" pass "x86, generic aarch64 and Qualcomm updates are unchanged: no boot check runs, nothing asks for root and the reboot is offered" # Apple: preflight runs before the keyring and packages change, and verify From 29c74af6daf8daaa7c83878f42598f4df59283a9 Mon Sep 17 00:00:00 2001 From: Marcelo Alcantara Date: Fri, 25 Sep 2026 23:18:48 +1000 Subject: [PATCH 10/10] Fail --boot-chain on any pacman report that is not left-out file drift A fresh image's database warnings made any failing pacman -Qkk pass once its own diagnostics were filtered out. Only drift in files the boot files are not built from is left out now. --- .../boot/bin/omarchy-apple-silicon-boot-check | 16 ++++++++++------ .../omarchy-mac/boot/test/fixtures/limine-mac.sh | 7 +++++++ .../omarchy-mac/boot/test/update-verify-test.sh | 11 ++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check b/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check index 3f88e9d4ade0..e32c54574b64 100755 --- a/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check +++ b/packages/omarchy-mac/boot/bin/omarchy-apple-silicon-boot-check @@ -68,7 +68,9 @@ limine_esp_path() { } # The kernel the boot menu starts: the first kernel entry in Limine's menu, -# where the tool writes the Omarchy block first, else GRUB's first entry. +# where the tool writes the Omarchy block first and Omarchy's default_entry +# points, else GRUB's first entry. A default_entry or GRUB_DEFAULT pointed +# elsewhere is not followed. menu_kernel() { if [[ -e $(path /var/lib/omarchy/limine.enabled) && -f $(path /etc/default/limine) ]]; then sudo awk '{ sub(/^[[:space:]]+/, "") } /^\/\/linux-(aurora|asahi)$/ { print substr($0, 3); exit }' \ @@ -118,15 +120,17 @@ for package in "$kernel" "$bootloader"; do altered=$(grep -Ev ' altered files$' <<<"$mtree_output" | grep -Ev "^warning: database file for '[^']+' does not exist" | grep -Ev '^warning: [^:]+: /usr/lib/modules/[^/]+/modules\.[A-Za-z.]+ \(Modification time mismatch\)$' || true) - # --boot-chain holds only the files the boot files are built from: the - # kernel image, its device trees and m1n1. + # --boot-chain holds only the files the boot files are built from against + # the mtree: the kernel image, its device trees and m1n1. Drift in any other + # file of the package is left out; everything else pacman reports counts. if (( boot_chain )); then - altered=$(grep -E '^warning: [^:]+: /usr/lib/(modules/[^/]+/(vmlinuz|dtbs/)|asahi-boot/)' <<<"$altered" || true) + altered=$(awk '!/^warning: [^:]+: \// || /^warning: [^:]+: \/usr\/lib\/(modules\/[^\/]+\/(vmlinuz|dtbs\/)|asahi-boot\/)/' <<<"$altered") fi [[ -z $altered ]] || fail "installed $package files do not match the package mtree: $(head -n 1 <<<"$altered")" - # pacman exits 1 for the depmod lines alone; any other failure is one. + # pacman exits 1 for the depmod lines alone, and with --boot-chain for the + # file drift it leaves out; any other failure is one. (( mtree_status == 0 )) || grep -Fq '(Modification time mismatch)' <<<"$mtree_output" || - { (( boot_chain )) && grep -q '^warning: ' <<<"$mtree_output"; } || + { (( boot_chain )) && grep -Eq '^warning: [^:]+: /' <<<"$mtree_output"; } || fail "pacman -Qkk $package failed" done diff --git a/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh b/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh index 910d17f30d82..469c7d84d972 100644 --- a/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh +++ b/packages/omarchy-mac/boot/test/fixtures/limine-mac.sh @@ -22,6 +22,13 @@ case "$*" in -Qq) cat "$MAC_STATE/installed" ;; "-Qlq "*) [[ -f $MAC_STATE/files-$2 ]] && cat "$MAC_STATE/files-$2" ;; "-Qkk "*) + # A fresh image has no sync databases; pacman warns about each. + [[ ! -e $MAC_STATE/fresh-image ]] || printf "warning: database file for 'core' does not exist (use '-Sy' to download)\n" >&2 + # report- is a diagnostic that is not about one file. + if [[ -e $MAC_STATE/report-$2 ]]; then + cat "$MAC_STATE/report-$2" >&2 + exit 1 + fi # drift- names the file that drifted. if [[ -e $MAC_STATE/drift-$2 ]]; then printf 'warning: %s: %s (Size mismatch)\n' "$2" "$(cat "$MAC_STATE/drift-$2")" >&2 diff --git a/packages/omarchy-mac/boot/test/update-verify-test.sh b/packages/omarchy-mac/boot/test/update-verify-test.sh index 21b0c4f24de0..7fcc68d3162b 100644 --- a/packages/omarchy-mac/boot/test/update-verify-test.sh +++ b/packages/omarchy-mac/boot/test/update-verify-test.sh @@ -176,7 +176,16 @@ second_kernel cp "$tmp/limine.conf" "$mac_esp/limine.conf" verify expect_refused "a Mac whose menu starts the second kernel first" "linux-asahi boots with m1n1, but m1n1 is not installed" -pass "update-verify still refuses a drifted kernel image, device tree or m1n1, and checks the kernel the menu starts" +# A fresh image's database warnings explain nothing else pacman reports. +limine_mac +: >"$mac_state/fresh-image" +printf '/usr/lib/modules/%s/kernel/drivers/gpu/drm/apple/appledrm.ko.zst\n' "$mac_kver" >"$mac_state/drift-linux-aurora" +verify +expect_verified "a fresh image with a drifted module" +printf 'error: linux-aurora: could not read the mtree\n' >"$mac_state/report-linux-aurora" +verify +expect_refused "a package pacman cannot check, on a fresh image" "installed linux-aurora files do not match the package mtree: error: linux-aurora: could not read the mtree" +pass "update-verify still refuses a drifted kernel image, device tree or m1n1, or a package pacman cannot check, and checks the kernel the menu starts" limine_mac limine_mac_luks