Skip to content

Commit 3222da9

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 <[email protected]>
1 parent 63d09b6 commit 3222da9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 3 additions & 2 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
(

crates/lib/src/spec.rs

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

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

0 commit comments

Comments
 (0)