Skip to content

efi: use a mounted ESP only for itself when other ESPs are written - #1195

Draft
LorbusChris wants to merge 5 commits into
coreos:mainfrom
LorbusChris:esp-mount-per-device
Draft

LorbusChris wants to merge 5 commits into
coreos:mainfrom
LorbusChris:esp-mount-per-device

Conversation

@LorbusChris

@LorbusChris LorbusChris commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1194; only the last commit is new here.

On a system with an ESP on each disk, such as an mdadm RAID1 root, bootupd goes through the ESPs one by one: in install (once per device), update, adoption, validate, and when writing the ESP's state file. For each one, though, mount_esp_device() and ensure_mounted_esp() first looked for an ESP mounted at boot/efi, efi or boot under the root, and used it whatever device they were asked for. With disk A's ESP mounted at /boot/efi, on a booted system or in an installer that mounts the target's /boot/efi before running bootupctl backend install, A's ESP was written once per disk, and B's was never written or checked. Installs without a mounted ESP, such as bootc's, weren't affected.

Checking only whether the mounted ESP is on the device asked for would break layouts that work today. So the choice now looks at all the ESPs being written to: those behind the root, or for install, those of the devices it was given.

Mounted ESP is… It is used for The other ESPs Layout
none – each through its own temporary mount bootc's installs, FCOS (unchanged)
one of the ESPs that ESP through temporary mounts an ESP per disk: fixed
an md array of the ESPs, or a partition of one all of them – md RAID1 of ESP partitions (unchanged)
the array partition the lookup finds that ESP – firmware RAID such as VROC/RST (unchanged)
none of the ESPs all of them – an ESP from another disk; multipath with path partitions (unchanged)
  • Matching. A mounted ESP is an ESP if its device number is the ESP partition's, or that of an array holding it (from /sys/dev/block/MAJ:MIN/holders), or of a partition of such an array.
  • Never bypassing an array. An ESP that lsblk reports as a RAID member is never mounted on its own, even after it dropped out of its array. Neither is an ESP whose device can't be inspected: the mounted ESP is used for those, as before.
  • ESPs bootupd used to skip. On systems installed before this, bootupd only ever wrote the mounted ESP; the others may be empty, unformatted, stale, or another system's. For an ESP mounted on its own beside the mounted one:
    • update, adoption, validate and the state file skip it, with a warning once per ESP, if it can't be mounted or holds none of the installed files outside EFI/BOOT;
    • update brings all of it up to date, not just the files that changed in this update, so that a stale copy converges. Until the next update, validate reports what an older update left there;
    • install, which fills it, falls back to the mounted ESP, as before, if it can't be mounted.
  • Left as before: after install's fallback, that disk's boot entry still points at its own ESP, which holds nothing. And a synced ESP keeps files that only versions older than the recorded one had, since bootupd has no record of them.
  • install runs once per device, so the per-device loop in bootupd.rs hands it the ESPs of all devices first. Without them, a mounted ESP is used as before.
  • The state file is still read from a mounted ESP if there is one, as before.

Testing

  • Unit tests:

    • the holder lookup, against a fake sysfs with relative symlinks like the real one (members of an md array, a partition of the array, an array inside a device-mapper device, no holders);
    • the choice for each layout above, including a member that dropped out of its array;
    • the fallback for a device that can't be inspected;
    • what counts as an ESP bootupd installed to;
    • bringing a stale, partial copy of the installed files up to date, keeping another system's files.

    Breaking the RAID-member rule, the partition match or the EFI/BOOT exclusion each fails a test.

  • With real devices: two vfat loop devices, A mounted at <root>/efi.

    • Asked for A, with A and B being written to: A's mount is used.
    • Asked for B, with A and B being written to: B is mounted on its own. That mount failed with EPERM, only because the test ran unprivileged. Updating or validating then skips B with a warning instead of failing.
    • Asked for B, with only B being written to: A's mount is used, as before.
  • fmt, test and clippy pass. All changed call sites are under cfg(efi_arch), so s390x and ppc64le are unaffected.

  • Not tested: md RAID1 and firmware RAID arrays on real hardware, and the full update and install flows on two disks.

Related: #1059 (with firmware RAID, a member disk was mounted instead of the array's ESP partition), #1076.

Assisted-by: LLM

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
Pre-merge checks: Passed 1

Check name Status Explanation
Commit Message Convention Passed The check applies to every non-merge commit in the PR. The first local checkout was shallow and showed only the head commit. After a deepen fetch, git log main..HEAD listed four non-merge commits. E…
Full details: Commit Message Convention

Explanation

The check applies to every non-merge commit in the PR. The first local checkout was shallow and showed only the head commit. After a deepen fetch, git log main..HEAD listed four non-merge commits. Each subject follows the subsystem: lowercase description format: - 9ca14c1 efi: use a mounted ESP only for itself when other ESPs are written - 5ab2326 install: write the static GRUB configs to every ESP - 7bd9e59 efi: keep a firmware boot entry for every ESP - b5c92c9 install: install to an ESP that several devices share only once Each subsystem is a component name (efi or install). Each description starts with a lowercase letter, uses an imperative verb (use, write, keep, install), and has no trailing period. The stacked #1194 commits (5ab2326, 7bd9e59, b5c92c9) are included in the PR range and conform too. No merge commits appeared in the range. The PR metadata's "Original commit subjects: Unavailable" was superseded by the git history evidence.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@openshift-ci

openshift-ci Bot commented Dec 3, 2026

Copy link
Copy Markdown

Hi @LorbusChris. Thanks for your PR.

I'm waiting for a coreos member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

LorbusChris and others added 5 commits December 3, 2026 22:54
The EFI component is installed to every given device that has an ESP.
The disks of a firmware RAID array, such as Intel VROC, share one ESP
on the array, which find_partition_of_esp() finds from each of them,
so install copied the payload to it once for each disk.

Install to each ESP once, from the first device that leads to it. Move
the choice of devices into a function to test it, with lsblk output
from bootc's blockdev crate for a firmware RAID array and for a
software RAID1 root whose disks have an ESP each.

Assisted-by: LLM
With --update-firmware, install updates the firmware's boot entries for
each ESP it installs to: it deletes the entries labelled with the
product name, then creates one for that ESP. With an ESP on each of two
disks, the second ESP's update deleted the first ESP's entry, so the
firmware could only boot from the last disk.

Delete the old entries only before the first ESP's entry, so that every
ESP keeps one and the firmware can fall back to another disk. A later
install still replaces all of them.

Assisted-by: LLM
On a system with an ESP on each disk, such as one with a RAID1 root,
install copies shim and GRUB to every ESP, but wrote
EFI/<vendor>/grub.cfg and bootuuid.cfg only into the ESP that the EFI
component had mounted last. GRUB booted from any other disk found no
config and dropped to its rescue shell.

Write the static configs in /boot once, before installing the
components, and the EFI ones into each ESP right after installing the
EFI component there, while it is mounted. /boot is synced again after
all components, as before, for what grub2-install writes there.
grubconfigs::install() now leaves the EFI ones to
StaticConfigs::install_efi(), which takes the ESP's EFI directory. That
also fixes adopt-and-update --with-static-config, which since 883c7a8
passed EFI/<vendor> where the ESP's root was expected, and so failed,
trying to write EFI/<vendor>/EFI/<vendor>/grub.cfg.

On x86_64, /boot/grub2 is now created by bootupd with mode 0700, as on
the other architectures and as CentOS Stream 10's grub2-common ships it,
rather than by grub2-install with 0755.

The static configs are still not tracked, so an update does not repair
an ESP that lacks them.

Based on coreos#1077.

Fixes: coreos#1076
Co-authored-by: ckyrouac <ckyrouac@redhat.com>
Assisted-by: LLM
install writes GRUB's static configs to each ESP inside its per-device
loop, which no test ran: bootc-e2e installs to one disk. Install the EFI
component onto two loopback disks with an ESP each and the root on the
first, and check that both ESPs get shim, grub.cfg and a bootuuid.cfg
naming the root's filesystem.

Only the legs without grub-cc run it, as the static configs are GRUB's.

Assisted-by: LLM
On a system with an ESP on each disk, install, update, adoption,
validation and the ESP's state file go through the ESPs one by one, but
each turn used whichever ESP was mounted at boot/efi, efi or boot under
the root, whatever device it was for. With the first disk's ESP mounted
at /boot/efi, that ESP was written once per disk, and the other disks'
ESPs were never written or checked.

Decide from all the ESPs being written to: those behind the root, or
for install, those of the devices it was given.

- The mounted ESP is used for the ESP it is: the same device, an array
  holding it, as with an md RAID1 array of ESP partitions, whose members
  are what the ESP lookup finds, or a partition of such an array.
- Another of the ESPs is mounted on its own, unless it is a RAID member,
  which is never mounted bypassing its array.
- If the mounted ESP is none of them, it is used for all of them, as
  before: the system uses an ESP from elsewhere, such as another disk.
- An ESP that can't be checked, because its device or sysfs can't be
  inspected, counts as the mounted one, as before.

ESPs that bootupd used to skip this way may be empty, stale, or another
system's. So, for an ESP mounted on its own:

- Update, adoption, validation and the state file skip it, with a
  warning, if it can't be mounted or read, or holds none of the
  installed files outside EFI/BOOT. For the state file, those are the
  files it records, or without them, any EFI directory.
- Update writes every file of the update that the ESP lacks or has
  otherwise, not just those that changed, and removes those the update
  drops. Until then, validation reports what an older update left.
- Install, which fills it, falls back to the mounted ESP, as before, if
  it can't be mounted.

Install runs once per device, so the per-device loop hands it the ESPs
of all devices; without them, a mounted ESP is used as before. The
state file is still read from a mounted ESP if there is one.

Assisted-by: LLM

@prestist prestist 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.

This looks right to me, but I'll hold the approval until it's out of draft. I
traced the layouts in the table through MountedEsp::of and
is_held_by, and the update, validate, adoption and state-file loops all
unmount between ESPs, so the choice is recomputed for each one. CI is green at
3479bbd and the tests pass locally.

Two things:

  1. The helper tests cover the matching and sync_diff_to, but
    mount_installed_esp's skip path and install's per-device choice are only
    covered by the loop-device checks. Could that be a unit test, or is real
    mounting the blocker?

  2. mount_installed_esp trusts ensure_mounted_esp's early return: if a
    mountpoint is already set, it returns it without re-running the MountedEsp
    decision, and beside_mounted_esp can be stale. The current callers unmount
    between ESPs, so it is fine today, but should it assert that the mountpoint
    belongs to the ESP it was asked for?

Nit: the skip check looks at file names only, so an ESP holding another system's
EFI/<vendor> files looks like ours and gets updated. I assume that is
deliberate given find_colocated_esps limits the ESPs to the root's disks, but
it is worth saying.

Assisted-by: AI tooling

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants