Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/lib/src/bootc_composefs/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ pub(crate) fn setup_composefs_bls_boot(
let boot_digest = compute_boot_digest(usr_lib_modules_vmlinuz, &repo)
.context("Computing boot digest")?;

let default_sort_key = "1";
let default_sort_key = bootloader.default_sort_key();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm I think it'd be cleaner if computed all the BLS entries without writing them, and then walk over all of them and reverse the order if we detect 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.

That is kind of what we're doing, but in a bit of a weird way. This might be good for a cleanup. I'll pick it up


let default_title_version = (id.to_hex(), default_sort_key.to_string());

let osrel_res = osrel_title_and_version(fs, &repo)?;
Expand Down Expand Up @@ -540,7 +541,7 @@ pub(crate) fn setup_composefs_bls_boot(
let boot_dir = Dir::open_ambient_dir(&entry_paths.config_path, ambient_authority())?;

let mut booted_bls = get_booted_bls(&boot_dir)?;
booted_bls.sort_key = Some("0".into()); // entries are sorted by their filename in reverse order
booted_bls.sort_key = Some(bootloader.secondary_sort_key().into());

// This will be atomically renamed to 'loader/entries' on shutdown/reboot
(
Expand Down Expand Up @@ -788,7 +789,7 @@ fn write_systemd_uki_config(
boot_label: UKILabels,
id: &Sha512HashValue,
) -> Result<()> {
let default_sort_key = "0";
let default_sort_key = Bootloader::SYSTEMD_PRIMARY_SORT_KEY;

let mut bls_conf = BLSConfig::default();
bls_conf
Expand Down
25 changes: 25 additions & 0 deletions crates/lib/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,31 @@ impl FromStr for Bootloader {
}
}

impl Bootloader {
pub(crate) const SYSTEMD_PRIMARY_SORT_KEY: &str = "0";
// Grub entries are sorted by their filename in reverse order
pub(crate) const GRUB_PRIMARY_SORT_KEY: &str = "1";

pub(crate) const SYSTEMD_SECONDARY_SORT_KEY: &str = "1";
pub(crate) const GRUB_SECONDARY_SORT_KEY: &str = "0";

/// Sort key for the primary BLS entry
pub(crate) fn default_sort_key(&self) -> &str {
Copy link
Collaborator

@cgwalters cgwalters Nov 18, 2025

Choose a reason for hiding this comment

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

How about

sorting_keys(&self) -> impl Iterator<Item=&'static str> {
  let r = ["0", "1"]
  match self {
    Systemd => r
    Grub => r.rev()
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We use the secondary keys when upgrading/switching, so this doesn't quite work for that case

match self {
Bootloader::Grub => Self::GRUB_PRIMARY_SORT_KEY,
Bootloader::Systemd => Self::SYSTEMD_PRIMARY_SORT_KEY,
}
}

/// Sort key for the secondary BLS entry
pub(crate) fn secondary_sort_key(&self) -> &str {
match self {
Bootloader::Grub => Self::GRUB_SECONDARY_SORT_KEY,
Bootloader::Systemd => Self::SYSTEMD_SECONDARY_SORT_KEY,
}
}
}

/// A bootable entry
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "camelCase")]
Expand Down