Repository navigation
initramfs: Point volatile-root at the partition beneath an encrypted root - #2651
krissedout wants to merge 1 commit into
Conversation
…root /run/systemd/volatile-root tells systemd-gpt-auto-generator which device the root filesystem is on, since it can't tell from the composefs overlay. We linked it to /dev/gpt-auto-root, which on an encrypted root is the unlocked dm-crypt volume. The generator takes that device as it is, unlike a real root filesystem, which it follows beneath dm-crypt, and looks for the ESP and XBOOTLDR partitions on its disk. A dm device has none, so /boot and /efi got no automounts, and systemd-bless-boot failed with "Couldn't find $BOOT partition", so an entry with a boot counter was never marked good. Follow the device's slaves in sysfs down to the partition, as systemd's get_block_device_harder() does, so LUKS, LVM and LVM on LUKS resolve to the partition they sit on. Several slaves are only followed when they are on one disk, as dm-verity's data and hash partitions can be; a device spread over more than one disk, such as RAID or LVM across disks, is linked as before. Assisted-by: AI Signed-off-by: Kristof Imeri <kristof@lanth.me>
There was a problem hiding this comment.
🟡 Changes recommended
Backing-disk discovery still fails for nested dm-verity/dm-crypt mappings on one disk, and a stale volatile-root symlink on the encrypted-root path continues to break ESP/XBOOTLDR discovery and boot blessing.
2 open issues
What changed in this PR
This PR updates composefs initramfs setup to point volatile-root at the partition beneath an encrypted or stacked root device, enabling systemd to discover ESP and XBOOTLDR partitions.
Changes:
- Traverse sysfs block-device dependencies to locate the backing partition.
- Preserve the original device when dependencies span multiple disks.
- Add table-driven tests for plain, encrypted, stacked, and multi-disk layouts.
| File | Description |
|---|---|
crates/initramfs/src/lib.rs |
Adds backing-device resolution, integrates it into the GPT workaround, and tests device topologies. |
Review effort: Balanced
| Path::new("/sys"), | ||
| &format!("{}:{}", major(rootdev.st_rdev), minor(rootdev.st_rdev)), | ||
| )?; | ||
| let target = format!("/dev/block/{device}"); |
There was a problem hiding this comment.
ostree-prepare-root and this code don't run in the same boot, one is the ostree backend and the other is composefs, so the link is only there already if something else made it on purpose, and I'd rather not overwrite that. The ostree side does have the same problem on an encrypted root, but that would be a fix in ostree-prepare-root, not here.
| let mut first: Option<(String, String)> = None; | ||
| for entry in entries { | ||
| let slave = entry?.path(); | ||
| let disk = whole_disk(&slave)?; |
There was a problem hiding this comment.
This is on purpose the same as systemd's block_device_get_originating_one(), which compares the whole disk of each direct slave and gives up with ENOTUNIQ when they differ. For verity on top of two dm-crypt volumes it gives up too, so a real root filesystem on that layout gets no ESP or XBOOTLDR discovery from systemd either. I'd keep the two matching, but I can make it look through the slaves first if you'd rather have that.


On a composefs system with an encrypted root, the ESP and XBOOTLDR partitions never get their /efi and /boot automounts. If a boot entry carries a boot counter, systemd-bless-boot then fails with "Couldn't find $BOOT partition", so the entry is never marked good and the boot loader falls back to the previous one once its tries run out. bootc doesn't add counters itself, so on its own this shows up as the missing automounts.
The initramfs links /run/systemd/volatile-root to /dev/gpt-auto-root so systemd-gpt-auto-generator knows which device the root is on (systemd/systemd#35017). With LUKS that's the unlocked dm-crypt volume. For a real root filesystem the generator follows the device beneath dm-crypt, but it takes volatile-root as it is, then looks for the ESP and XBOOTLDR partitions on that device's disk, and a dm device has none. The generator only says so at debug level ("/dev/dm-0: Couldn't identify a suitable partition table or file system."), so nothing shows up in the journal.
This follows the root device's slaves in sysfs down to the partition before linking it, the same way systemd's get_block_device_harder() does, so LUKS, LVM and LVM on LUKS all end up at the partition they sit on. Several slaves are only followed when they're on the same disk, as with dm-verity's data and hash partitions. Anything spread across disks, like RAID or LVM over two disks, is linked as before, since there's no single disk to look on. A root that's already a partition doesn't change.
cargo fmt --check, clippy with the CI flags and cargo test -p bootc-initramfs-setup pass, including a table-driven test against a fake sysfs covering a plain partition, a whole disk, LUKS, LVM on LUKS, dm-verity on one disk, LVM across two disks and LUKS on RAID across two disks. There's no tmt coverage since the test matrix doesn't install with an encrypted root.
We've carried a simpler version of this, which only followed a single slave, on encrypted composefs installs with SushiBoot, our own boot loader, which implements systemd-boot's Boot Loader Interface and boot counting. I also tested this change on bootc 1.17.4 in a VM with a LUKS root. Without it, volatile-root pointed at dm-0, nothing was automounted and systemd-bless-boot failed. With it, volatile-root points at the LUKS partition, /boot automounts, and the staged entry's counter was cleared on its first boot.
Assisted-by: AI