diff --git a/crates/lib/src/bootc_composefs/boot.rs b/crates/lib/src/bootc_composefs/boot.rs index fd4c71981..b0a101675 100644 --- a/crates/lib/src/bootc_composefs/boot.rs +++ b/crates/lib/src/bootc_composefs/boot.rs @@ -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(); + let default_title_version = (id.to_hex(), default_sort_key.to_string()); let osrel_res = osrel_title_and_version(fs, &repo)?; @@ -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 ( @@ -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 diff --git a/crates/lib/src/spec.rs b/crates/lib/src/spec.rs index 83fd0b3ab..43752bd16 100644 --- a/crates/lib/src/spec.rs +++ b/crates/lib/src/spec.rs @@ -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 { + 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")]