Skip to content

systemd-gpt-auto-generator can't find ESP because it can't detect blockdev of / if composefs is used #35017

Open

Description

@allisonkarlitskaya

systemd version the issue has been seen with

256

Used distribution

Fedora rawhide

Linux kernel version used

6.12.0-0.rc5.20241101git6c52d4da1c74.48.fc42.x86_64

CPU architectures issue was seen on

x86_64

Component

systemd-gpt-auto-generator

Expected behaviour you didn't see

According to the manpage:

This generator will only look for the root partition on the same physical disk where the EFI System Partition (ESP) is located. Note that support from the boot loader is required: the EFI variable LoaderDevicePartUUID of the 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f vendor UUID is used to determine from which partition, and hence the disk, from which the system was booted. If the boot loader does not set this variable, this generator will not be able to detect the root partition.

Similarly, this generator will only look for the other partitions on the same physical disk as the root partition. In this case, boot loader support is not required. These partitions will not be searched for on systems where the root file system is distributed on multiple disks, for example via btrfs RAID.

By my reading this sounds like systemd will look at the GPT on the physical drive where the ESP is, as told by the bootloader. The language below mentions "other partitions" and "root file system on multiple disks". This is where the logic indeed goes somewhat sideways.

I am using systemd-boot and the LoaderDevicePartUUID variable is correctly set. I also have /dev/gpt-auto-root pointing at the "real" root device that was detected in the initramfs. In the meantime, though, I've remounted a composefs on /sysroot before booting the main system. When the gpt generator runs it has this output:

[root@fedora ~]# SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/system-generators/systemd-gpt-auto-generator /tmp/x
Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy
Found container virtualization none.
Reading EFI variable /sys/firmware/efi/efivars/LoaderDevicePartUUID-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f.
Adding /: /dev/gpt-auto-root fstype=(any)
Neither root nor /usr/ file system are on a (single) block device.
Skipping automatic GPT dissection logic, root file system not backed by a (single) whole block device.

The mention of "Reading EFI variable..." is caused by this code:

        r = efi_loader_get_device_part_uuid(NULL);
        if (r == -ENOENT) {
                log_notice("EFI loader partition unknown, exiting.\n"
                           "(The boot loader did not set EFI variable LoaderDevicePartUUID.)");

which is really only checking if the variable is set, not reading/using it (note the NULL). After the variable is verified as present then the generator goes down an entirely different logical path involving trying to detect the block device of the / partition and using the GPT found on that disk. If it can't do that, it tries /usr. It'll also look at the /run/systemd/volatile-root symlink if it exists.

Importantly, if it fails to figure out the root device this way, it goes no further. It doesn't try to read the LoaderDevicePartUUID variable again (which is actually only used as a double-check after the data is read from the partition table).

By my reading of the docs, this is wrong. The docs say that the device that is searched is the one with the ESP, but in fact, it's the one that has the block device behind the mount of /. At the very least, the actual direction that this process happens in should probably be more clearly documented.

It's also a bit strange that the code in blockdev-util.c which tries to determine the root block device by looking at /, /usr/ and /run/systemd/volatile-root doesn't contain an attempt to look at /dev/gpt-auto-root, which would have worked in my case.

So I guess two asks:

  • clearer docs (would have saved me quite a bit of time tracking this down)
  • better detection for my case: it should be enough to just look directly at /dev/gpt-auto-root if it exists — in fact, this seems like the "most obvious" option if we're not gonna actually start with LoaderDevicePartUUID.

Unexpected behaviour you saw

No response

Steps to reproduce the problem

No response

Additional program output to the terminal or log subsystem illustrating the issue

No response

Activity

  1. added
    bug 🐛
    on Nov 4, 2024
  2. changed the title [-]systemd-gpt-auto-generator can't find EFI because it can't detect blockdev of /[/-] [+]systemd-gpt-auto-generator can't find ESP because it can't detect blockdev of /[/+] on Nov 4, 2024
  3. allisonkarlitskaya commented on Nov 4, 2024

    @allisonkarlitskaya
    ContributorAuthor

    I'm dealing with this for now by stat()ing /dev/gpt-auto-root and writing the /dev/block/x:y symlink to /run/systemd/volatile-root, but this is clearly just a workaround.

  4. poettering commented on Nov 5, 2024

    @poettering
    Member

    "composefs" means just another overlayfs, right?

  5. allisonkarlitskaya commented on Nov 5, 2024

    @allisonkarlitskaya
    ContributorAuthor

    More or less, ya. It's an overlayfs where the upper is a erofs image and the datadir is indeed a pointer back to the underlying "real" filesystem.

  6. poettering commented on Nov 5, 2024

    @poettering
    Member

    overlayfs doesn#t provide an API for us to query backing layers, hence the /dev/gpt-auto-root thing is currently the way to go.

  7. allisonkarlitskaya commented on Nov 6, 2024

    @allisonkarlitskaya
    ContributorAuthor

    Would you take a patch to blockdev-util.c to stat("/dev/gpt-auto-root") to get the rdev?

  8. allisonkarlitskaya commented on Nov 6, 2024

    @allisonkarlitskaya
    ContributorAuthor

    Would you take a patch to blockdev-util.c to stat("/dev/gpt-auto-root") to get the rdev?

    Even this seems like a bit of a hack, to be honest, though. What should really be happening (to match my impression from reading the docs) is not that we look at the block device backing / but we should rather look at /dev/disk/by-partuuid/${LoaderDevicePartUUID} and start the search from there...

  9. changed the title [-]systemd-gpt-auto-generator can't find ESP because it can't detect blockdev of /[/-] [+]systemd-gpt-auto-generator can't find ESP because it can't detect blockdev of / if composefs is used[/+] on Mar 14, 2025
  10. added
    RFE 🎁
    and removed
    bug 🐛
    on Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFE 🎁gpt-auto

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions