Skip to content

Commit ad86fc8

Browse files
composefs/boot: Fix sd-boot order on update
Grub sorts its BLS config in descending order, while sd-boot sorts the configs in ascending order. While upgrading we were always setting the new sort key to be `1` which would work for Grub but not for sd-boot. Fixes: #1777 Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 63d09b6 commit ad86fc8

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ pub(crate) fn setup_composefs_bls_boot(
474474
let boot_digest = compute_boot_digest(usr_lib_modules_vmlinuz, &repo)
475475
.context("Computing boot digest")?;
476476

477-
let default_sort_key = "1";
477+
let default_sort_key = bootloader.default_sort_key();
478+
478479
let default_title_version = (id.to_hex(), default_sort_key.to_string());
479480

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

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

545546
// This will be atomically renamed to 'loader/entries' on shutdown/reboot
546547
(
@@ -788,7 +789,7 @@ fn write_systemd_uki_config(
788789
boot_label: UKILabels,
789790
id: &Sha512HashValue,
790791
) -> Result<()> {
791-
let default_sort_key = "0";
792+
let default_sort_key = Bootloader::SYSTEMD_PRIMARY_SORT_KEY;
792793

793794
let mut bls_conf = BLSConfig::default();
794795
bls_conf

crates/lib/src/spec.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,31 @@ impl FromStr for Bootloader {
197197
}
198198
}
199199

200+
impl Bootloader {
201+
pub(crate) const SYSTEMD_PRIMARY_SORT_KEY: &str = "0";
202+
// Grub entries are sorted by their filename in reverse order
203+
pub(crate) const GRUB_PRIMARY_SORT_KEY: &str = "1";
204+
205+
pub(crate) const SYSTEMD_SECONDARY_SORT_KEY: &str = "1";
206+
pub(crate) const GRUB_SECONDARY_SORT_KEY: &str = "0";
207+
208+
/// Sort key for the primary BLS entry
209+
pub(crate) fn default_sort_key(&self) -> &str {
210+
match self {
211+
Bootloader::Grub => Self::GRUB_PRIMARY_SORT_KEY,
212+
Bootloader::Systemd => Self::SYSTEMD_PRIMARY_SORT_KEY,
213+
}
214+
}
215+
216+
/// Sort key for the secondary BLS entry
217+
pub(crate) fn secondary_sort_key(&self) -> &str {
218+
match self {
219+
Bootloader::Grub => Self::GRUB_SECONDARY_SORT_KEY,
220+
Bootloader::Systemd => Self::SYSTEMD_SECONDARY_SORT_KEY,
221+
}
222+
}
223+
}
224+
200225
/// A bootable entry
201226
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
202227
#[serde(rename_all = "camelCase")]

0 commit comments

Comments
 (0)