Skip to content

Unmount the LUKS key device before the initrd switches root - #20

Merged
maralcbr merged 2 commits into
mainfrom
fix/reset-keydev-ro-boot
Oct 8, 2026
Merged

maralcbr merged 2 commits into
mainfrom
fix/reset-keydev-ro-boot

Conversation

@maralcbr

@maralcbr maralcbr commented Oct 8, 2026

Copy link
Copy Markdown
Member

Summary

A factory-reset reboot can bring /boot up read-only, and owner setup then fails its LUKS re-key because mkinitcpio cannot write /boot/initramfs-linux-aurora.img. It is a race in the initramfs, seen in VM acceptance of omacom/omarchy#14431 while another VM shared the host.

Cause. The reset reboot (and its retry) unlocks the root with rd.luks.key=<luks>=/omarchy/luks-key:UUID=<Boot>. systemd-cryptsetup-generator then mounts the Boot partition read-only at /run/systemd/cryptsetup/keydev-root and unmounts it with keydev-root-umount.service after cryptsetup. When initrd-cleanup.service isolates to initrd-switch-root.target, the transaction starts [email protected] again, and its Requires=/Wants= queue the key-device mount and its unmount a second time. This is open upstream as systemd/systemd#28021. Nothing orders that unmount before initrd-switch-root.service, and the generated unit is Type=simple, so it counts as started at fork. Under load the root switches while the mount is in progress or before umount has run. The read-only ext4 superblock follows into the real root, and boot.mount gets mount: /boot: WARNING: source write-protected, mounted read-only.

initrd-cleanup: isolate initrd-switch-root.target
  start [email protected] (already active)
    Requires= run-systemd-cryptsetup-keydev\x2droot.mount   -> mounts Boot ro again
    Wants=    keydev-root-umount.service                    -> unmounts it (Type=simple)
  start initrd-switch-root.service                          -> no order against either

Fix. The omarchy-mac-encrypt install hook adds a drop-in for the generated unit, keydev-root-umount.service.d/omarchy-mac-encrypt.conf, with Before=initrd-switch-root.service and Type=oneshot. The switch now waits for the second unmount, which already waits for the second mount. The drop-in exists only in the initramfs, and only takes effect on boots whose command line carries rd.luks.key= (the generator creates no such unit otherwise). The unit name follows the volume name root, the same assumption the existing key-device mount drop-in makes.

Tests: mac-encrypt-test.sh checks the drop-in and its install line and runs systemd-analyze verify on a copy of the generator's unit with the drop-in; it fails without the fix. The VM harness now checks that the generic initramfs carries the drop-in, and fails a boot whose serial log shows /boot came up read-only (in owner_setup and no_emergency), naming the cause instead of a later mkinitcpio error.

Evidence

Failing run: 14431 acceptance run b, factory-reset-reboot-serial.log: second Mounting /run/systemd/cryptsetup/keydev-root at 6.90 s, Switching root at 6.95 s, vda2 mounted ro at 6.956 s, /boot: WARNING: source write-protected at 9.47 s.

Repeated initrd boots of one reset-staged disk on the M1 Pro (KVM, 4 vCPU, two guests at a time; the "load" rounds add six busy loops on the host). The only difference between the two initramfs images is the drop-in, appended to the control image's initramfs.

initramfs boots /boot read-only switch before the second unmount finished
control, two guests 30 1 7
control, two guests + host load 24 2 10
with the drop-in, two guests 30 0 0
with the drop-in, two guests + host load 24 0 0

With the drop-in every boot logs Finished keydev-root-umount.service twice before Switching root.

Full VM acceptance with omarchy-mac-boot built from this branch (2b88c06) on the #14431 test set (only omarchy-mac-boot changed), harness 14499e9, each factory-reset run in parallel with an update run: 3 of 3 factory-reset runs 13 ok / 0 not ok, 3 of 3 update runs 12 ok / 0 not ok. Each reset reboot logs two key-device mounts and two finished unmounts before Switching root, and no read-only /boot. A control factory-reset run on the unpatched set passed (13/0/0): the race is timing, which is why the boot loop above is the reproduction.

Unit tests: omarchy-mac-boot/test/all 221 ok in an Arch Linux ARM container; tools/acceptance/test/mac-image-run-test.sh passes.

Merge Danger

Door: two-way

One initramfs drop-in; reverting it and rebuilding the initramfs restores today's behaviour.

Blast Radius: small

Only Mac initramfs images built with the omarchy-mac-encrypt hook, and only boots with rd.luks.key= (reset reboot and its retry). Those boots wait for one local unmount before switching root. No x86 or desktop effect, no user-visible setting.

A boot that unlocks the root with rd.luks.key=...:UUID=<Boot> (the reset
reboot, and its retry) mounts the Boot partition read-only at
/run/systemd/cryptsetup/keydev-root. systemd-cryptsetup-generator's
keydev-root-umount.service unmounts it after cryptsetup, but the isolate
to initrd-switch-root.target starts [email protected]'s
Requires= again, so the key-device mount and its unmount are queued a
second time (systemd/systemd#28021). Nothing orders that unmount before
initrd-switch-root.service, and it is Type=simple, so under load the root
switches with the mount still in progress: the read-only ext4 superblock
follows into the real root, /boot comes up "write-protected, mounted
read-only", and owner setup's re-key fails in mkinitcpio.

A drop-in in the initramfs orders the unmount before
initrd-switch-root.service and makes it Type=oneshot, so the switch waits
until the remount is undone. The encrypt test checks the drop-in and its
install line and verifies it on the generator's unit; the VM harness now
fails a boot whose /boot came up read-only, naming the cause.
The VM harness already lists the key-device mount drop-in in the generic
initramfs it builds from the image's hooks; list the unmount drop-in too, so
an image built without it fails before any boot. grep reads the whole
listing, so lsinitcpio never sees a closed pipe under pipefail.
@maralcbr
maralcbr marked this pull request as ready for review October 8, 2026 20:54
@maralcbr
maralcbr requested a review from scottjones as a code owner October 8, 2026 20:54
@maralcbr
maralcbr merged commit 162f359 into main Oct 8, 2026
6 checks passed
@maralcbr
maralcbr deleted the fix/reset-keydev-ro-boot branch October 8, 2026 20:54
scottjones added a commit that referenced this pull request Oct 9, 2026
Brings in #18, #19, #20 and #22. The runtime pin conflicted: main pins
omacom/omarchy 4d9bdc49 (#14431), which has no platform-root fingerprint
detection, so this branch now pins omacom/omarchy#14675's head
f317ea50, the fingerprint-readers detector on #14431. Move it to the
merge commit once #14675 lands. omarchy-mac stays at #12's 0.2.0; main
is still at 0.1.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant