Repository navigation
prepare-root: create /run/systemd/volatile-root for composefs - #3608
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds logic to ostree-prepare-root.c to create a /run/systemd/volatile-root symlink pointing to the physical root device when composefs is used, enabling systemd to resolve the backing block device. Feedback on the pull request highlights that this implementation will fail on btrfs-based systems (such as Fedora Silverblue) because stat() on the mountpoint returns an anonymous device ID with a major number of 0. The reviewer suggests a robust fallback mechanism that checks /dev/gpt-auto-root first.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
systemd resolves the block device backing the root filesystem via blockdev_get_root(), which checks "/" and falls back to "/usr". With composefs enabled both are overlayfs mounts with an anonymous st_dev (and prepare-root intentionally skips the read-only /usr bind mount in that case), so the lookup finds no device. As a result systemd-gpt-auto-generator silently skips all partition discovery: the ESP is never automounted on /boot, which in turn breaks tools that expect the bootfs to be reachable, e.g. bootctl, systemd-bless-boot (boot counting) and "ostree admin status" when the loader entries live on the ESP. systemd provides a hook for exactly this situation: if the root mount has been replaced by some form of volatile file system, the original root block device is expected to be symlinked at /run/systemd/volatile-root. Create that symlink when composefs is in use. Note the target must be in the /dev/block/MAJ:MIN form since systemd parses it without ever going to disk (device_path_parse_major_minor()). The root device is resolved as follows: prefer /dev/gpt-auto-root when it exists, since on systemd-based initrds udev has already identified the root partition for us (EFI boot with LoaderDevicePartUUID set and a discoverable-partitions-spec root partition type). Otherwise fall back to stat()ing the root mountpoint, which also covers initrds without systemd (e.g. meta-updater). Since btrfs reports an anonymous st_dev (major 0) for its mounts, in that case query the backing device via BTRFS_IOC_FS_INFO/BTRFS_IOC_DEV_INFO the same way systemd's btrfs_get_block_device_fd() does, refusing multi-device filesystems just as systemd does. This matters in practice as Fedora Atomic Desktops default to composefs on btrfs. bootc solves the same problem the same way for its composefs-native backend: bootc-root-setup.service (gated on the composefs= karg) runs a gpt_workaround() that creates this exact symlink. That service is ordered after ostree-prepare-root.service, so with this change the symlink already exists by the time it runs; bootc is being updated to tolerate that instead of failing. See also the systemd discussion of gpt-auto with overlay roots: systemd/systemd#35017 Failure to create the symlink is not fatal: the system boots fine without it, only auto-discovery of auxiliary partitions is degraded. Signed-off-by: Ricardo Salveti <[email protected]>
31c3b70 to
62109dc
Compare
systemd resolves the block device backing the root filesystem via blockdev_get_root(), which checks "/" and falls back to "/usr". With composefs enabled both are overlayfs mounts with an anonymous st_dev (ostree-prepare-root intentionally skips the read-only /usr bind mount in that case), so systemd-gpt-auto-generator silently skips all partition discovery: the ESP is never automounted on /boot, breaking bootctl, systemd-bless-boot (boot counting) and "ostree admin status" when the loader entries live on the ESP. Non-composefs sota images are unaffected since /usr there is a plain bind mount of the physical root. Carry the ostree patch proposed upstream at ostreedev/ostree#3608, which makes ostree-prepare-root create the /run/systemd/volatile-root symlink - systemd's documented hook for roots replaced by a volatile filesystem - pointing at the physical root device whenever composefs is used. bootc solves the same problem with the same symlink for its composefs-native backend (gpt_workaround(), see also systemd issue #35017) and is being updated to tolerate the symlink already existing. The patch is runtime-gated to composefs, but scope it to the cfs-support override to keep non-composefs builds unchanged. Signed-off-by: Ricardo Salveti <[email protected]>
ostree-prepare-root is growing the same gpt-auto workaround for composefs roots (creating the /run/systemd/volatile-root symlink so systemd's blockdev_get_root() can resolve the backing device, see systemd/systemd#35017), proposed in ostreedev/ostree#3608. It runs before bootc-root-setup.service, so once that lands the symlink already exists by the time gpt_workaround() runs, and the unconditional symlink() call makes the service fail. Both creators point the symlink at the /dev/block/MAJ:MIN alias of the same physical root device, so simply ignore EEXIST, matching how ensure_dir() handles already-existing directories. Signed-off-by: Ricardo Salveti <[email protected]>
ostree-prepare-root is growing the same gpt-auto workaround for composefs roots (creating the /run/systemd/volatile-root symlink so systemd's blockdev_get_root() can resolve the backing device, see systemd/systemd#35017), proposed in ostreedev/ostree#3608. When it runs before composefs-setup-root, the symlink already exists by the time gpt_workaround() runs and the unconditional symlink() call fails with EEXIST. The call site discards the error ("best effort"), but an already existing symlink means the desired end state is in place, so treat it as success rather than an error. This matches the equivalent change to bootc's vendored copy of this code in bootc-dev/bootc#2276. Signed-off-by: Ricardo Salveti <[email protected]>
|
Also in bootc-dev/bootc#2402 |
|
I'm leaning a bit towards suggesting people who have regressions from this to revert this particular change. Or perhaps we make it opt-in upstream here until we've had time to sort through the implications? |
|
The regressions are caused because the feature (auto generator) is now enabled, which is a consequence of this change, but I would say more related to the way people are setting up their systems and potential issues with the generator. Maybe just document that the generator can be disabled with systemd.gpt_auto=0? |
|
Hi yes, I should be very clear I think this change is conceptually right and I appreciate you submitting it!
Yes...but changing kernel arguments (or other things, like removing the gpt-auto generator etc) can be harder to roll out; it's probably not at all obvious for folks the linkage between this ostree change and the effects it has. Perhaps we can add And we can make the default for (Very tangential but man I have to say post-2024 the acronym conflict on "GPT" is so confusing) |
Yeah, that would work, I can take a stab on it this week. |
|
One thing that's clear to me is we should likely have a recommendation to have Although I guess, the dir could get autocreated on a mutable Anyways, I will see about shipping |
|
Adding this made CentOS Stream 9 based images (and probably also RHEL 9 based images) start booting in a degraded state. Having the I have not yet tested on CentOS Stream 10 since our CI only boots in BIOS mode and c10s has systemd 257 ( I'm going to be a bit of a grump, but as someone on the "implementing" side of Since we use the It'd be nice if we can move more integration testing (and boot testing and seeing if everyone works succesfully) closer to Also; should we even be supporting conversion of container images with older bootc versions in them or can we potentially just say " |
|
Thanks it's a valid point and I think the (There's also a rather giant thing in that a lot of the CI here was and still is oriented towards CoreOS style systems that used Ignition and a whole set of stuff unrelated to image builder and the DPS rollout there has hit issues, stuff like coreos/fedora-coreos-tracker#2026) On the CI
Finally, yet another thing here is when I tried to wire up "ensure no systemd units are failing" I ran straight into the problem that actually there's continual conflicts between the rate of change in systemd (in particular) and selinux policy - nothing new there, been going on for years. Fixing that needs consistent gating of the base images and packages - doing it in upstream CI is just too late. |
Please reach out if you need and/or want help with this; we've been boot testing images in
Yea sadly I'm very familiar with this as someone who maintains a (package based) remix that uses all the new systemd stuff for cohesive linux (UKIs, systemd-sysupdate, dmverity, bladiebla) and I have to ship my own SELinux policy to make sure all the new and newly split out services work. But, having CI here is how we find those bugs and can report them :) |
|
Also xref https://bugzilla.redhat.com/show_bug.cgi?id=2520626 and bootc-dev/bootc#2402 which I think are fallout from this |
systemd resolves the block device backing the root filesystem via
blockdev_get_root(), which checks "/" and falls back to "/usr". With
composefs enabled both are overlayfs mounts with an anonymous st_dev
(and prepare-root intentionally skips the read-only /usr bind mount in
that case), so the lookup finds no device. As a result
systemd-gpt-auto-generator silently skips all partition discovery: the
ESP is never automounted on /boot, which in turn breaks tools that
expect the bootfs to be reachable, e.g. bootctl, systemd-bless-boot
(boot counting) and "ostree admin status" when the loader entries live
on the ESP.
systemd provides a hook for exactly this situation: if the root mount
has been replaced by some form of volatile file system, the original
root block device is expected to be symlinked at
/run/systemd/volatile-root. Create that symlink when composefs is in
use. Note the target must be in the /dev/block/MAJ:MIN form since
systemd parses it without ever going to disk
(device_path_parse_major_minor()).
The root device is resolved as follows: prefer /dev/gpt-auto-root when
it exists, since on systemd-based initrds udev has already identified
the root partition for us (EFI boot with LoaderDevicePartUUID set and
a discoverable-partitions-spec root partition type). Otherwise fall
back to stat()ing the root mountpoint, which also covers initrds
without systemd (e.g. meta-updater). Since btrfs reports an anonymous
st_dev (major 0) for its mounts, in that case query the backing device
via BTRFS_IOC_FS_INFO/BTRFS_IOC_DEV_INFO the same way systemd's
btrfs_get_block_device_fd() does, refusing multi-device filesystems
just as systemd does. This matters in practice as Fedora Atomic
Desktops default to composefs on btrfs.
bootc solves the same problem the same way for its composefs-native
backend: bootc-root-setup.service (gated on the composefs= karg) runs a
gpt_workaround() that creates this exact symlink. That service is
ordered after ostree-prepare-root.service, so with this change the
symlink already exists by the time it runs; bootc is being updated to
tolerate that instead of failing. See also the systemd discussion of
gpt-auto with overlay roots:
systemd/systemd#35017
Failure to create the symlink is not fatal: the system boots fine
without it, only auto-discovery of auxiliary partitions is degraded