Skip to content

prepare-root: create /run/systemd/volatile-root for composefs - #3608

Merged
cgwalters merged 1 commit into
ostreedev:mainfrom
ricardosalveti:volatile-root-composefs
Jul 31, 2026
Merged

cgwalters merged 1 commit into
ostreedev:mainfrom
ricardosalveti:volatile-root-composefs

Conversation

@ricardosalveti

@ricardosalveti ricardosalveti commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the area/prepare-root Issue relates to ostree-prepare-root label Jul 3, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/switchroot/ostree-prepare-root.c Resolved
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]>
@ricardosalveti
ricardosalveti force-pushed the volatile-root-composefs branch from 31c3b70 to 62109dc Compare July 3, 2026 03:01
ricardosalveti added a commit to ricardosalveti/meta-updater-1 that referenced this pull request Jul 3, 2026
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]>
cgwalters pushed a commit to cgwalters/bootc that referenced this pull request Jul 8, 2026
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]>
cgwalters pushed a commit to cgwalters/composefs-rs that referenced this pull request Jul 9, 2026
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]>
@cgwalters
cgwalters merged commit 883cd75 into ostreedev:main Jul 31, 2026
39 checks passed
@cgwalters

Copy link
Copy Markdown
Member

@cgwalters

Copy link
Copy Markdown
Member

Also in bootc-dev/bootc#2402

@cgwalters

Copy link
Copy Markdown
Member

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?

@ricardosalveti

Copy link
Copy Markdown
Contributor Author

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?

@cgwalters

Copy link
Copy Markdown
Member

Hi yes, I should be very clear I think this change is conceptually right and I appreciate you submitting it!

Maybe just document that the generator can be disabled with systemd.gpt_auto=0?

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 ostree.enable_gpt=0|1 on our side (and actually also make this a config option for ostree-prepare-root so one can change the config file in the initramfs).

And we can make the default for enable_gpt configurable upstream?

(Very tangential but man I have to say post-2024 the acronym conflict on "GPT" is so confusing)

@ricardosalveti

Copy link
Copy Markdown
Contributor Author

Perhaps we can add ostree.enable_gpt=0|1 on our side (and actually also make this a config option for ostree-prepare-root so one can change the config file in the initramfs).

Yeah, that would work, I can take a stab on it this week.

@cgwalters

Copy link
Copy Markdown
Member

One thing that's clear to me is we should likely have a recommendation to have /efi in base images. However, at the time of this writing none of Fedora, Debian or Ubuntu at least have that by default in their base images.

Although I guess, the dir could get autocreated on a mutable /, so it's more an ostree/composefs related issue where we take the concept that / is the OS, not just /usr by default.

Anyways, I will see about shipping /efi on Fedora derivatives at least.

@supakeen

supakeen commented Oct 2, 2026

Copy link
Copy Markdown

Adding this made CentOS Stream 9 based images (and probably also RHEL 9 based images) start booting in a degraded state.

Having the /run/volatile-root be available means systemd-gpt-auto-generator (from systemd 252) starts actually finding the backing device and thus starts generating automounts based on it. Since efi.automount tries to create / before local-fs.target but / is ro this fails and while it doesn't prevent the boot it's also not very nice.

I have not yet tested on CentOS Stream 10 since our CI only boots in BIOS mode and c10s has systemd 257 (systemd-gpt-auto-generator was largely rewritten in systemd 256) and thus systemd-gpt-auto-generator does not try to inject automounts there if the system isn't booted through EFI there (as opposed to c9s).


I'm going to be a bit of a grump, but as someone on the "implementing" side of bootc / ostree we have been dealing with a bunch of fallout of the mountain of changes in those stacks and their dependencies (mostly bootupd) over the previous months.

Since we use the bootc / ostree / etc executables from within the container we really have no way to tell if we should be writing an fstab, mount units, or be relying on systemd-gpt-auto-generator to be working; with systemd >= 256 that likely also includes the intended boot mode of the system which is a runtime decision at this point and thus we can't know.

It'd be nice if we can move more integration testing (and boot testing and seeing if everyone works succesfully) closer to bootc / ostree / etc as I have been spending a decent chunk of time on debugging these issues and figuring out "whodunnit". We're always ready to fix up new behaviors (or drop code, in this case) but being behind these new behaviors is a bit grating.

Also; should we even be supporting conversion of container images with older bootc versions in them or can we potentially just say "bootc version not new enough"? :)

@cgwalters

Copy link
Copy Markdown
Member

Thanks it's a valid point and I think the #1 item on the plan to fix it: We need coverage of using image-builder in upstream CI here and on bootc - there is some but only build and not booting.

(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.

@supakeen

supakeen commented Oct 2, 2026

Copy link
Copy Markdown

Thanks it's a valid point and I think the #1 item on the plan to fix it: We need coverage of using image-builder in upstream CI here and on bootc - there is some but only build and not booting.

Please reach out if you need and/or want help with this; we've been boot testing images in image-builder's CI for quite a while, it might not mesh well with the CI setups for bootc but if it does it saves a bunch of duplication :)

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.

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 :)

@cgwalters

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/prepare-root Issue relates to ostree-prepare-root

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants