Skip to content

Conversation

Johan-Liebert1
Copy link
Collaborator

Fix Grub boot error caused by #1541. Introduce a --bootloader cli option to --composefs-native. Depending upon the type of bootloader passed in we write BLS configs respectively

Johan-Liebert1 and others added 26 commits August 29, 2025 17:05
Signed-off-by: Pragyan Poudyal <[email protected]>
Signed-off-by: Colin Walters <[email protected]>
Parse the Grub menuentry file, `boot/grub2/user.cfg` to get a list of
bootable UKIs and figure out if a rollback is currently queued.

Signed-off-by: Johan-Liebert1 <[email protected]>
Returning a local reference to a `&str` is quite tricky with rust.
Update `title` and `chainloader`, the two dynamic fields in the grub
menuentry, to be `String` instead of `&str`

Signed-off-by: Johan-Liebert1 <[email protected]>
We parse the grub menuentries, get the rollback deployment then perform
the rollback, which basically consists of writing a new .staged
menuentry file then atomically swapping the staged and the current
menuentry.

Rollback while there is a staged deployment is still to be handled.

Signed-off-by: Johan-Liebert1 <[email protected]>
If two deployments have the same VMLinuz + Initrd then, we can use the
same binaries for both the deployments.

Before writing the BLS entries to disk we calculate the SHA256Sum
of VMLinuz + Initrd combo, then test if any other deployment has the
same SHA256Sum for the binaries. Store the hash in the origin file under
`boot -> hash` for future lookups.

Signed-off-by: Johan-Liebert1 <[email protected]>
Centralize all constants in a separate file

Signed-off-by: Johan-Liebert1 <[email protected]>
Instead of `/sysroot/state/os/fedora` use `/sysroot/state/os/default` as
the default state directory.

Signed-off-by: Johan-Liebert1 <[email protected]>
Instaed of writing all present menuentries, only write the menuentry for
switch/upgrade and the menuentry for the currently booted deployment.

Signed-off-by: Johan-Liebert1 <[email protected]>
This allows for easier testing

Signed-off-by: Pragyan Poudyal <[email protected]>
Add tests for functions `get_sorted_bls_boot_entries` and
`get_sorted_uki_boot_entries`

Signed-off-by: Pragyan Poudyal <[email protected]>
Signed-off-by: Colin Walters <[email protected]>
The duplication between this and composefs-boot is high
and we need to squash it; an important step there
would probably be lowering the karg parsing.

Signed-off-by: Colin Walters <[email protected]>
Signed-off-by: Robert Sturla <[email protected]>

install: create temporary directory for ESP bls mount

Plus additional review comments:
- Created constant for EFI/LINUX
- Switched from Task to Command
- Create efi_dir as Utf8PathBuf

Signed-off-by: Robert Sturla <[email protected]>
- Use `read_file` from `composefs::fs`
- Always define `mod parsers`
- Re-alphabetize/group module definitions

Signed-off-by: John Eckersberg <[email protected]>
Fill `version` field in generated BLS config

Signed-off-by: Johan-Liebert1 <[email protected]>
composefs/install/bls: Fix empty version in config
For bind mounting /etc we copy the contents of the EROFS' /etc to the
deployment's state directory

Mounting the EORFS requires help from the initramfs crate, so we also
turn it into a library crate.

Signed-off-by: Johan-Liebert1 <[email protected]>
composefs/install: Copy /etc contents to state
@bootc-bot bootc-bot bot requested a review from cgwalters September 1, 2025 11:55
Copy link
Contributor

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

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 introduces support for both systemd-boot and grub by adding a --bootloader option, which is a great enhancement. The changes are well-structured, particularly the use of the BLSEntryPath struct to handle bootloader-specific paths. I've identified a critical issue with temporary directory handling that could lead to resource leaks, and a high-severity issue regarding backward compatibility for existing deployments. Addressing these will make the implementation more robust.

Fix Grub boot error caused by
bootc-dev#1541. Introduce a `--bootloader`
cli option to `--composefs-native`. Depending upon the type of
bootloader passed in we write BLS configs respectively

Signed-off-by: Johan-Liebert1 <[email protected]>

Add guard again tempdir drop

Signed-off-by: Johan-Liebert1 <[email protected]>
} else {
write_bls_boot_entries_to_disk(&efi_dir, id, usr_lib_modules_vmlinuz, &repo)?;
write_bls_boot_entries_to_disk(
Copy link
Contributor

@p5 p5 Sep 1, 2025

Choose a reason for hiding this comment

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

Apologies for breaking GRUB in the previous PR. From reading through various docs (Fedora change requests) and issues in the repo, it sounded like GRUB was able to work in a (mostly) BLS-compliant way. My understanding must have not been correct.

I also think my understanding was further enforced through the function names - write_**bls**_boot_... - which made me think we were trying to achieve full BLS compliance in the Composefs backend.


I greatly appreciate you fixing the implementation rather than reverting the PR!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Grub doesn't fully support the BLS spec, that's why we have to jump over hoops to support it, which is unfortunate.

I greatly appreciate you fixing the implementation rather than reverting the PR!

We want to support systemd-boot eventually :)

@@ -19,6 +19,8 @@ pub(crate) const ORIGIN_KEY_BOOT: &str = "boot";
pub(crate) const ORIGIN_KEY_BOOT_TYPE: &str = "boot_type";
/// Key to store the SHA256 sum of vmlinuz + initrd for a deployment
pub(crate) const ORIGIN_KEY_BOOT_DIGEST: &str = "digest";
/// Bootloader, Grub or Systemd
pub(crate) const ORIGIN_KEY_BOOTLOADER: &str = "bootloader";
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can very reliably detect if systemd-boot is in use by looking at the EFI variables it sets, or parsing bootctl --json or so...I'm not excited by carrying a stateful thing for this.

Also this heavily overlaps with what bootupd is doing. For the bootupd case of course since it installs the bootloader it may need some explicit configuration.


This heavily relates to my comment in ostreedev/ostree#3359 (comment)

Basically though, since we require bootc to manage some out of band config files for grub, how about we default to systemd boot, but query /boot and if we detect our own grub config files then we use that?

If we did need a config knob, see also #1532 which changed the install config.

Copy link
Collaborator

Choose a reason for hiding this comment

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

how about we default to systemd boot,

Really I mean, default to the Boot Loader Spec...and detect grub by looking for the config files we currently need.

So the enum would be

enum Bootloader {
 BLS,
 Grub
}

or so

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It makes sense to default to systemd when we have full support for it in bootupd. Right now, since we don't have it, I think it makes sense to keep Grub as the default. When we do have full support, it's just a matter of updating the code to change the default

Making it stateless is definitely cleaner than relying on the origin file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Making it stateless is definitely cleaner than relying on the origin file.

Right, can we do that here please?

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.

4 participants