Skip to content

Be a bit nicer when images with ESP on /boot/efi - #30994

Closed
fbuihuu wants to merge 5 commits into
systemd:mainfrom
fbuihuu:dissect-esp-boot-efi
Closed

fbuihuu wants to merge 5 commits into
systemd:mainfrom
fbuihuu:dissect-esp-boot-efi

Conversation

@fbuihuu

@fbuihuu fbuihuu commented Jan 18, 2024

Copy link
Copy Markdown
Contributor

/boot/efi is not recommended for ESP but it's still commonly used and therefore systemd-dissect at least shouldn't choke on them.

@github-actions github-actions Bot added util-lib please-review PR is ready for (re-)review by a maintainer labels Jan 18, 2024
@YHNdnzj

YHNdnzj commented Jan 18, 2024 •

Copy link
Copy Markdown
Member

We generally want to keep the behavior of gpt-auto and dissect-image in sync, and that doesn't use /boot/efi/ either. TBH, I don't think this change makes much sense. In most cases, people who are still using legacy setups don't make use of DDI anyway. IOW, changing the ESP mountpoint from /boot/efi/ to /efi/ is fairly trivial, and we should really encourage that instead.

@YHNdnzj

YHNdnzj commented Jan 18, 2024

Copy link
Copy Markdown
Member

Also, creating /efi/ if rw mounted and fail otherwise is very much consistent behavior to me.

@YHNdnzj YHNdnzj added needs-discussion 🤔 reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks gpt-auto and removed please-review PR is ready for (re-)review by a maintainer labels Jan 18, 2024
Comment thread src/shared/dissect-image.c Resolved
Comment thread src/shared/dissect-image.c Resolved
@YHNdnzj

YHNdnzj commented Jan 18, 2024

Copy link
Copy Markdown
Member

Note that if the ESP is listed in fstab, no matter where it is mounted, the gpt-auto logic will be skipped. See fstab_has_node call above. So the last two changes really make no sense.

Comment thread src/shared/dissect-image.c Resolved
Comment thread src/shared/dissect-image.c Resolved
Comment thread src/shared/dissect-image.c Resolved
@poettering

Copy link
Copy Markdown
Member

sorry, i seldom do this, but here it's necessary: hard NAK. nesting the ESP inside of /boot/ is just wrong. people should stop doing that, and we should not just silently accept this.

I think it's ok to look for stuff in /boot/efi I think, if other set it up like this, but we should never set things up like this on our own.

sorry, but no.

please split out the 2nd commit, it makes sense on its own.

@fbuihuu

fbuihuu commented Jan 18, 2024

Copy link
Copy Markdown
Contributor Author

Note that if the ESP is listed in fstab, no matter where it is mounted, the gpt-auto logic will be skipped. See fstab_has_node call above. So the last two changes really make no sense.

I see. I was confused by the fact that, in my testing case, the call to fstab_has_node() is not working with DM devices (simply because there's no by-diskseq symlinks for this type of devices) hence I incorrectly assumed that the logic afterwards could be used as extra safety checks. So the proper fix is probably to not used diskseq symlinks with DM devices.

BTW how can you make sure that the call to fstab_has_node() from this generator is always reliable ?

AFAICS this function assumes that udev is running but since this code is called from a generator, this assumption might be not true (think about initrdless systems).

@fbuihuu

fbuihuu commented Jan 18, 2024

Copy link
Copy Markdown
Contributor Author

We generally want to keep the behavior of gpt-auto and dissect-image in sync, and that doesn't use /boot/efi/ either. TBH, I don't think this change makes much sense. In most cases, people who are still using legacy setups don't make use of DDI anyway.

When ESP is on /boot/efi and an entry in fstab exists, DPS says that the image is compliant.

Therefore:

  • gpt-auto-generator shouldn't interfer and create an automount unit for /efi
  • dissect-image should not modify such images by creating /efi and incorrectly forcing ESP on /efi if the image is mounted RW.
  • dissect-image should not fail if the image is mounted RO since the image is compliant.

IOW, changing the ESP mountpoint from /boot/efi/ to /efi/ is fairly trivial, and we should really encourage that instead.

Just to be clear I'm not arguing for ESP on /boot/efi. I'm just trying to prevent systemd from behaving badly when it encounters cases where ESP is on top /boot/efi

@fbuihuu

fbuihuu commented Jan 18, 2024

Copy link
Copy Markdown
Contributor Author

Also, creating /efi/ if rw mounted and fail otherwise is very much consistent behavior to me.

Not if the image specifies a different path for ESP (other than /boot/ or /efi/) in fstab. At least the DPS seems to support this case.

Also I'm wondering if silently modifying the image (by creating the missing mount points) is a good idea. At least by default I wouldn't do that.

@fbuihuu
fbuihuu force-pushed the dissect-esp-boot-efi branch from c84b392 to eacb2f2 Compare January 19, 2024 16:50
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Jan 19, 2024
Otherwise systemd-dissect happily mounts ESP on top of the root fs.
Even if not recommended, images with ESP on /boot/efi are not uncommon and are
valid DDIs as long as the path is specified in fstab.

Therefore dissecting such images:

 - should not modify it by creating /efi and incorrectly forcing ESP on /efi
   when the image is mounted RW.

 - should not fail if the image is mounted RO since the images are compliant
   with DPS.

The patch also makes the code fails when XBOOTLDR cannot be mounted on /boot
because the directory is not empty.
To allow callers of dissected_image_mount() to make sure that the image won't
be modified even if it's mounted RW.

No functional change.
It's not expected that introspecting images modifies them, even for creating
missing mount point dirs, at least by default.

This is especially important when dissecting DDI images with ESP on /boot/efi
otherwise it creates a wrong mount point dir at /efi.
@fbuihuu

fbuihuu commented Jan 26, 2024

Copy link
Copy Markdown
Contributor Author

@poettering, can we try to make a trade-off ?

Encouraging distros to move ESP to /efi by explaining the advantages like https://0pointer.net/blog/linux-boot-partitions.html does is good. However shipping tools that misbehave when ESP is on /boot/efi (very common) is not, especially if they're still considered as valid DDIs by DPS

Regarding systemd-gpt-auto-generator, it seems ok to skip setups using /boot/efi but it should do that reliably. Apparently the decision to skip ESP is based only on the presence of ESP device in fstab. However it might get tricky to get correct results (e.g. root device on multipath device). But maybe more importantly, the generator assumes that udev has/is run/running and can rely on udev symlinks. As far as generators are concerned this assumption is incorrect unless systemd doesn't support initrd-less boots but it's not the case AFAIK. Simply checking the presence of the typical ESP paths in fstab might be more reliable actually. Maybe the gpt-auto generator should also require the existence of the mount point directories to avoid creating unwanted directories afterwards.

Regarding systemd-dissect, it's a tool for introspecting DDI images. As such it makes less sense to not support all kind of DDIs. In any cases allowing the tool to modify images to create incorrect mount point directories is wrong regardless of whether /boot/efi should be supported or not. I added two patches to prevent systemd-dissect from doing that (a tool for introspecting images is not allowed to modify the images by default, is it ?).

Comment thread src/shared/dissect-image.c Resolved
Comment thread src/shared/dissect-image.c Resolved
* by default) will be created when mounting ESP. If that fails again then the
* directories exist but are not empty. */
again:
FOREACH_STRING(dir, "/boot", "/efi", "/boot/efi") {

@poettering poettering Jan 30, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nope. we'll not add new support for /boot/efi in 2024. Sorry.

Comment thread src/shared/dissect-image.c Resolved
Comment thread src/core/namespace.c
DISSECT_IMAGE_FSCK |
DISSECT_IMAGE_USR_NO_ROOT |
DISSECT_IMAGE_GROWFS |
DISSECT_IMAGE_MKDIR_MOUNTPOINTS |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what's the usecase for this? when would we ever not set this?

if people want immutable images they should set the r/o flag

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As explained in the commit messages, dissect is an introspecting tool and as such it should not modify the introspected images by default. If anything is missing to properly mount the image it should complain and exit (regardless of whether if it's mounted ro or rw).

If modifying the image is wanted then passing a specific option to allow that (--mkdir-mountpoints or such) seems a better approach.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

but the modes where it just introspects the image all set the r/o flag, hence the mkdir doesn't work anyway? so why is any new flag required here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See the use case I provided below with --mount. This mode, by default, modifies the image to create /efi if it doesn't exist. You will argue that --read-only could be passed but the fact that the user wants to mount the image RW doesn't mean that the tool is allowed to do various image modifications. And the man page doesn't say anything about that.

@poettering

Copy link
Copy Markdown
Member

@poettering, can we try to make a trade-off ?

Encouraging distros to move ESP to /efi by explaining the advantages like https://0pointer.net/blog/linux-boot-partitions.html does is good. However shipping tools that misbehave when ESP is on /boot/efi (very common) is not, especially if they're still considered as valid DDIs by DPS

Regarding systemd-gpt-auto-generator, it seems ok to skip setups using /boot/efi but it should do that reliably. Apparently the decision to skip ESP is based only on the presence of ESP device in fstab. However it might get tricky to get correct results (e.g. root device on multipath device). But maybe more importantly, the generator assumes that udev has/is run/running and can rely on udev symlinks. As far as generators are concerned this assumption is incorrect unless systemd doesn't support initrd-less boots but it's not the case AFAIK. Simply checking the presence of the typical ESP paths in fstab might be more reliable actually. Maybe the gpt-auto generator should also require the existence of the mount point directories to avoid creating unwanted directories afterwards.

gpt-auto-generator is run on any kind of set up, we need to be more defensive there.

Regarding systemd-dissect, it's a tool for introspecting DDI images. As such it makes less sense to not support all kind of DDIs. In any cases allowing the tool to modify images to create incorrect mount point directories is wrong regardless of whether /boot/efi should be supported or not. I added two patches to prevent systemd-dissect from doing that (a tool for introspecting images is not allowed to modify the images by default, is it ?).

Sorry, I am strictly against adding support for /boot/efi. That's just a broken idea, we are not going to make that magically happen. Not in 2024.

You could convince me to add:

  1. If /boot is found to not be used for XBOOTLDR but for something else then we refrain from mounting the ESP to /efi, and instead cleanly refuse with a clear error, as the image is some legacy stuff then.
  2. Add an env var that allows disabling mounting certain dirs. i.e. SYSTEMD_DISSECT_EXCLUDE_ESP=1 or so would disable mounting the esp.

@poettering poettering added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Jan 30, 2024
@fbuihuu

fbuihuu commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

gpt-auto-generator is run on any kind of set up, we need to be more defensive there.

But how ?

The only way I can see is to explicitly check for the presence of the paths in /etc/fstab but you and @YHNdnzj shot my first attempt which actually did that...

@fbuihuu

fbuihuu commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

Sorry, I am strictly against adding support for /boot/efi. That's just a broken idea, we are not going to make that magically happen. Not in 2024.

I can only repeat myself: systemd-dissect is an introspecting tool that is supposed to operate on DDIs. And images with ESP on /boot/efi are compliant DDIs. systemd-dissect could warn about the fact that such images are considered obsolete but refusing to introspect them is wrong .

@poettering

Copy link
Copy Markdown
Member

I can only repeat myself: systemd-dissect is an introspecting tool that is supposed to operate on DDIs. And images with ESP on /boot/efi are compliant DDIs. systemd-dissect could warn about the fact that such images are considered obsolete but refusing to introspect them is wrong .

I am not sure I grok what you mean by "compliant"? the discoverable partitions spec never mentions /boot/efi at all, and it doesn't actually say anything about mount point dirs that must or must not exist in the image, hence I am not sure why you insist so much that such an image was "compliant"? the only ways I can describe the situation is at best "spec doesn't say" and at worse "not compliant".

@poettering

Copy link
Copy Markdown
Member

Can you precisely describe an image that you think is currently mishandled by systemd-dissect and also provide the precise command line that does it wrong?

@fbuihuu

fbuihuu commented Feb 1, 2024 •

Copy link
Copy Markdown
Contributor Author

I am not sure I grok what you mean by "compliant"? the discoverable partitions spec never mentions /boot/efi at all

Excerpt taken from https://uapi-group.org/specifications/specs/discoverable_partitions_specification/#suggested-mode-of-operation:

If the EFI partition shall not be mounted to /efi/ or /boot/, it must create /etc/fstab entries for them.

Indeed it doesn't mention /boot/efi explicitly but the use case we're debating here falls into this category nevertheless, doesn't it ?

We can't realistically supports any fancy paths, I agree, but /boot/efi was/is used enough [1] that pretending that it never existed is well... not compliant.

[1] At least it's commonly used enough that some other parts of systemd does support it: bootctl reports it as a valid ESP, kernel-install happily installs its stuff in /boot/efi, etc...

@poettering

Copy link
Copy Markdown
Member

Indeed it doesn't mention /boot/efi explicitly but but the use case we're debating here falls to this category nevertheless, doesn't it ?

Not sure it does. I think checking fstab makes sense for the gpt-auto generator thingy, but for the offline dissect logic it simply doesn't. Slightly different rules apply on that I am sure, as the systemd-gpt-auto stuff runs on every boot for regular, traditional users, but when you use systemd-dissect then that's done explicitly, never implicitly and thus we can make stricter requirements.

We can't realistically supports any fancy paths, I agree, but /boot/efi was/is used enough [1] that pretending that it never existed is well... not compliant.

I am not pretending it never existed. I was fine with making bootctl work with it if things are explicitly set up like this. All I am saying is that we never should set things up like that automatically, because it's broken.

It's the difference between consuming a manual setup and setting up an automatic setup. Former is fine, latter is not I am sure.

[1] At least it's commonly used enough that some other parts of systemd does support it: bootctl reports it as a valid ESP, kernel-install happily installs its stuff in /boot/efi, etc...

@poettering

Copy link
Copy Markdown
Member

If you buy into the concept of DDIs, i.e. disk images that follow the discoverable partition spec and are shipped for sysexts, confexts, portable services, containers, then I think it's not too much to ask to do so without legacy crap.

I am happy to update the spec btw, to say explicitly which mount point dirs must exist in compliant DDIs.

@fbuihuu

fbuihuu commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

Can you precisely describe an image that you think is currently mishandled by systemd-dissect and also provide the precise command line that does it wrong?

Sure.

Consider a disk image with the following partitions:

Device        Start    End Sectors Size Type
/dev/loop0p1   2048  67583   65536  32M EFI System
/dev/loop0p3 133120 198655   65536  32M Linux swap
/dev/loop0p4 198656 264191   65536  32M Linux root (x86-64)
/dev/loop0p5 264192 329727   65536  32M Linux home

The root partition have the following directory layout:

/mnt/
├── boot
│   └── efi
├── etc
│   ├── fstab
│   └── os-release
├── home
└── lost+found

and /etc/fstab contains an entry for ESP to be mounted on /boot/efi. So AFAIK the disk image is "compliant".

Here are 2 cases where systemd-dissect is misbehaving (maybe there're more, I haven't tested it exhaustively)

# systemd-dissect --list test-gpt-image-256M.raw 
Failed to mount image: No such file or directory

At the very least the message is misleading and it should say that the image doesn't support ESP other than "/boot" and "/efi". But as said previously I believe it would be wrong. (Also not sure why the command hangs for about 5 sec... might be due to the fact that when dissected_image_mount() fails in the middle it doesn't do its cleanup job properly).

# systemd-dissect --mount test-gpt-image-256M.raw /mnt
# tree /mnt
/mnt
├── boot
│   └── efi
├── efi
│   └── it-is-esp
├── etc
│   ├── fstab
│   └── os-release
├── home
│   ├── it-is-home
│   └── lost+found
└── lost+found

10 directories, 2 files

Here it created /efi and mounted ESP on this directory. The image is silently modified by defaut (/efi created) and ESP is mounted at the wrong place.

@poettering

Copy link
Copy Markdown
Member

systemd-dissect --list test-gpt-image-256M.raw

Failed to mount image: No such file or directory

Ah, nice you even get an OKish error message for images like this.

Anyway, I am very sure that systemd-dissect should not consult fstab

Frankly, I see this is a request to update the spec, i.e. say explicitly that implementations may:

  1. honour fstab preferably, for "online" cases, (but don't have to for "offline" cases such as DDI)
  2. may or may not create missing mountpoints

Also, I think we should fail rather than fall back to /efi if /boot exists and is populated like it is in your case.

@fbuihuu

fbuihuu commented Feb 2, 2024

Copy link
Copy Markdown
Contributor Author

I am not pretending it never existed. I was fine with making bootctl work with it if things are explicitly set up like this. All I am saying is that we never should set things up like that automatically, because it's broken.

Don't get this, the problem here is actually that both systemd-dissect and gpt-auto-generator dont follow the same rules as the ones followed by bootctl. They both ignore the fact that the image is already set up with ESP on a path other than /efi.

And with the patch, both tools create /efi and use that as mount point dir when things are not yet set up.

@fbuihuu

fbuihuu commented Feb 2, 2024

Copy link
Copy Markdown
Contributor Author

Frankly, I see this is a request to update the spec, i.e. say explicitly that implementations may:

  1. honour fstab preferably, for "online" cases, (but don't have to for "offline" cases such as DDI)
  2. may or may not create missing mountpoints

Please make sure to discuss this with a broader audience given that you're willing to adapt a specification.

@fbuihuu

fbuihuu commented Feb 2, 2024

Copy link
Copy Markdown
Contributor Author

gpt-auto-generator is run on any kind of set up, we need to be more defensive there.

Since you didn't say how this can be done I dared to resubmit my initial proposal but with more comments: #31181.

Feel free to shoot again but then please suggest the way you think it should be done.

@YHNdnzj

YHNdnzj commented Feb 2, 2024

Copy link
Copy Markdown
Member

gpt-auto-generator is run on any kind of set up, we need to be more defensive there.

But how ?

The only way I can see is to explicitly check for the presence of the paths in /etc/fstab but you and @YHNdnzj shot my first attempt which actually did that...

My understanding is that the current logic IS ALREADY defensive, i.e. we skip things if fstab_has_node(esp).

I don't really care about systems without initrd. I assume people with such a "restricted" setup won't be using gpt-auto anyway.

@YHNdnzj

YHNdnzj commented Feb 2, 2024

Copy link
Copy Markdown
Member

When #28894 is implemented we should even switch most of the gpt-auto logic to using those symlinks, rather than doing dissect on its own.

@lnussel

lnussel commented Feb 5, 2024

Copy link
Copy Markdown
Contributor

Chiming in here. The issue on openSUSE side is that, well, we're coming from a grown general purpose distro. We would really like to integrate systemd stuff as much as possible. We can only do that step by step though. The existing grub based setup has to stay in a working condition. I don't see it going away anytime soon. Even worse, /boot/efi is hardcoded in other packages like u-boot as well. So this takes time to develop tooling that works for both grub and sd-boot and adjust all packages. Meanwhile those of us who work on systemd stuff would like to use the fancy tools already. So as Franck said, even if /boot/efi is considered legacy, dealing with it in a graceful way would be most appreciated by those who are actually actively working on getting rid of it :-)

@daandemeyer

Copy link
Copy Markdown
Collaborator

Let's close this one. The gpt-auto part landed separately in #31181, and
mounting the ESP to /boot/efi in systemd-dissect was rejected above.
A PR that makes dissect refuse with a clear error, instead of falling back to
creating /efi when /boot/ is populated with something else, would still be
welcome.

@github-actions github-actions Bot removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks needs-discussion 🤔 labels Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants