Skip to content

Use the ESP we booted from via LoaderDevicePartUUID - #2555

Open
Johan-Liebert1 wants to merge 4 commits into
bootc-dev:mainfrom
Johan-Liebert1:multi-esp-fix
Open

Johan-Liebert1 wants to merge 4 commits into
bootc-dev:mainfrom
Johan-Liebert1:multi-esp-fix

Conversation

@Johan-Liebert1

@Johan-Liebert1 Johan-Liebert1 commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

utils: Strip efivarfs attribute header and NUL when reading EFI vars

read_uefi_var() decoded the entire contents of the efivarfs file as
UTF-16LE.

efivarfs prepends a 4-byte little-endian u32 of the variable's attributes,
and EFI string variables are NUL-terminated.

As a result the returned string was wrapped in invisible characters and
incorrect string matches with UTF-8 encoded Strings

Skip the 4-byte attribute header before decoding and trim trailing
NUL and surrounding whitespace from the result.


store: Select the booted ESP via LoaderDevicePartUUID

On dual-booted systems, walking up to the root disk(s) and picking the
first colocated ESP can return the wrong one, since there may be
multiple ESPs.

Instead, read the LoaderDevicePartUUID EFI variable set
by the boot loader and match it against the partuuid of the candidate
partitions, so we operate on the ESP we actually booted from.

The install paths still use find_first_colocated_esp(), since at that
point we are not booted into a bootc system and the EFI variable does
not describe the target system.

Fixes: #2554


esp: Handle non-BLS bootloaders

Older versions of Grub, the one in c10s and c9s, don't fully implement
the BLS spec, which means we don't get the efivar
LoaderDevicePartUUID-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f.

In such a case, go through all the ESPs and try to find bootc owned BLS
config file in ESP/loader/entries

read_uefi_var() decoded the entire contents of the efivarfs file as
UTF-16LE.

efivarfs prepends a 4-byte little-endian u32 of the variable's attributes,
and EFI string variables are NUL-terminated.

As a result the returned string was wrapped in invisible characters and
incorrect string matches with UTF-8 encoded Strings

Skip the 4-byte attribute header before decoding and trim trailing
NUL and surrounding whitespace from the result.

Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
@bootc-bot
bootc-bot Bot requested a review from jeckersb October 8, 2026 05:39
@Johan-Liebert1 Johan-Liebert1 changed the title Use the ESP we booted from Use the ESP we booted from via LoaderDevicePartUUID Oct 8, 2026
@Johan-Liebert1

Copy link
Copy Markdown
Member Author

I've tested this locally and it works fine. Unfortunately, adding integration tests for this is going to be a little bit hacky

On dual-booted systems, walking up to the root disk(s) and picking the
first colocated ESP can return the wrong one, since there may be
multiple ESPs.

Instead, read the LoaderDevicePartUUID EFI variable set
by the boot loader and match it against the partuuid of the candidate
partitions, so we operate on the ESP we actually booted from.

The install paths still use find_first_colocated_esp(), since at that
point we are not booted into a bootc system and the EFI variable does
not describe the target system.

Fixes: bootc-dev#2554

Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
Older versions of Grub, the one in c10s and c9s, don't fully implement
the BLS spec, which means we don't get the efivar
LoaderDevicePartUUID-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f.

In such a case, go through all the ESPs and try to find bootc owned BLS
config file in `ESP/loader/entries`

Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
@cgwalters

Copy link
Copy Markdown
Collaborator

Unfortunately, adding integration tests for this is going to be a little bit hacky

I think we can change our bcvk wrapper tooling to support provisioning block devices to the VM (bcvk supports it), then it's just a matter of adding varoius different ESP partitions, spread across various disks or so.

Comment thread crates/lib/src/utils.rs Outdated
Comment thread crates/lib/src/utils.rs Outdated
AssistedBy: LLM

Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

composefs: bootc status/upgrade/switch use the first ESP on the disk instead of the one the system booted from (dual-boot with Windows)

2 participants