Skip to content

Commit 628e3b3

Browse files
bls_conf: Support 'uki' keyword
Systemd >= v258 supports 'uki' key in bls configs. Update BLSConfig struct to reflect the same. We still support the 'efi' key for backwards compatibility During writing of the BLSConfig files we check for systemd version and use the appropriate key GrubCC does not support the 'uki' key right now See: #2268 Closes: #2263 Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 3d6f071 commit 628e3b3

7 files changed

Lines changed: 174 additions & 37 deletions

File tree

crates/lib/src/bootc_composefs/backwards_compat/bcompat_boot.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_TYPE, STATE_DIR_RELATIVE, TYPE1_BOOT_DIR_PREFIX,
1717
TYPE1_ENT_PATH_STAGED, UKI_NAME_PREFIX, USER_CFG_STAGED,
1818
},
19-
parsers::bls_config::{BLSConfig, BLSConfigType},
19+
parsers::bls_config::{BLSConfig, BLSConfigType, EFIKey},
2020
spec::BootloaderKind,
2121
store::Storage,
2222
};
@@ -214,12 +214,16 @@ fn stage_bls_entry_changes(
214214
.collect();
215215
}
216216

217-
BLSConfigType::EFI { efi, .. } => {
217+
BLSConfigType::EFI { key, .. } => {
218218
// boot_dir in case of UKI is the ESP
219219
plan_efi_binary_renames(&boot_dir, &digest, &mut rename_transaction)?;
220-
*efi = Utf8PathBuf::from("/")
220+
let new_path = Utf8PathBuf::from("/")
221221
.join(BOOTC_UKI_DIR)
222222
.join(get_uki_name(&digest));
223+
*key = match key {
224+
EFIKey::Efi(_) => EFIKey::Efi(new_path),
225+
EFIKey::Uki(_) => EFIKey::Uki(new_path),
226+
};
223227
}
224228

225229
_ => anyhow::bail!("Unknown BLS config type"),

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ use crate::bootc_composefs::state::{get_booted_bls, write_composefs_state};
9797
use crate::bootc_composefs::status::ComposefsCmdline;
9898
use crate::bootc_kargs::compute_new_kargs;
9999
use crate::composefs_consts::{TYPE1_BOOT_DIR_PREFIX, TYPE1_ENT_PATH, TYPE1_ENT_PATH_STAGED};
100-
use crate::parsers::bls_config::{BLSConfig, BLSConfigType};
100+
use crate::parsers::bls_config::{BLSConfig, BLSConfigType, EFIKey};
101101
use crate::spec::BootloaderKind;
102102
use crate::task::Task;
103103
use crate::{bootc_composefs::repo::open_composefs_repo, store::Storage};
@@ -1002,6 +1002,7 @@ fn write_systemd_uki_config(
10021002
setup_type: &BootSetupType,
10031003
boot_label: UKIInfo,
10041004
id: &Sha512HashValue,
1005+
bootloader: &Bootloader,
10051006
) -> Result<()> {
10061007
let os_id = boot_label.os_id.as_deref().unwrap_or("bootc");
10071008
let primary_sort_key = primary_sort_key(os_id);
@@ -1010,7 +1011,10 @@ fn write_systemd_uki_config(
10101011
bls_conf
10111012
.with_title(boot_label.boot_label)
10121013
.with_cfg(BLSConfigType::EFI {
1013-
efi: format!("/{BOOTC_UKI_DIR}/{}", get_uki_name(&id.to_hex())).into(),
1014+
key: EFIKey::for_bootloader(
1015+
format!("/{BOOTC_UKI_DIR}/{}", get_uki_name(&id.to_hex())).into(),
1016+
bootloader,
1017+
),
10141018
})
10151019
.with_sort_key(primary_sort_key.clone())
10161020
.with_version(boot_label.version.unwrap_or_else(|| id.to_hex()));
@@ -1174,7 +1178,7 @@ pub(crate) fn setup_composefs_uki_boot(
11741178
}
11751179

11761180
BootloaderKind::BLSCompatible => {
1177-
write_systemd_uki_config(&esp_mount.fd, &setup_type, uki_info, id)?
1181+
write_systemd_uki_config(&esp_mount.fd, &setup_type, uki_info, id, &bootloader)?
11781182
}
11791183
};
11801184

crates/lib/src/bootc_composefs/delete.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
COMPOSEFS_STAGED_DEPLOYMENT_FNAME, COMPOSEFS_TRANSIENT_STATE_DIR, STATE_DIR_RELATIVE,
1515
TYPE1_ENT_PATH, TYPE1_ENT_PATH_STAGED, USER_CFG_STAGED,
1616
},
17-
parsers::bls_config::{BLSConfigType, parse_bls_config},
17+
parsers::bls_config::{BLSConfigType, EFIKey, parse_bls_config},
1818
spec::{BootEntry, BootloaderKind, DeploymentEntry},
1919
status::Slot,
2020
store::{BootedComposefs, Storage},
@@ -54,8 +54,11 @@ fn delete_type1_conf_file(
5454
let bls_config = parse_bls_config(&cfg)?;
5555

5656
match &bls_config.cfg_type {
57-
BLSConfigType::EFI { efi } => {
58-
if !efi.as_str().contains(&depl.deployment.verity) {
57+
BLSConfigType::EFI { key } => {
58+
let path = match key {
59+
EFIKey::Efi(path) | EFIKey::Uki(path) => path,
60+
};
61+
if !path.as_str().contains(&depl.deployment.verity) {
5962
continue;
6063
}
6164

crates/lib/src/bootc_composefs/state.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::bootc_composefs::boot::BootType;
2929
use crate::bootc_composefs::status::{
3030
ComposefsCmdline, StagedDeployment, get_sorted_type1_boot_entries,
3131
};
32-
use crate::parsers::bls_config::BLSConfigType;
32+
use crate::parsers::bls_config::{BLSConfigType, EFIKey};
3333
use crate::store::{BootedComposefs, Storage};
3434
use crate::{
3535
composefs_consts::{
@@ -69,8 +69,11 @@ pub(crate) fn get_booted_bls(boot_dir: &Dir, booted_cfs: &BootedComposefs) -> Re
6969

7070
for entry in sorted_entries {
7171
match &entry.cfg_type {
72-
BLSConfigType::EFI { efi } => {
73-
if efi.as_str().contains(&*booted_cfs.cmdline.digest) {
72+
BLSConfigType::EFI { key } => {
73+
let path = match key {
74+
EFIKey::Efi(path) | EFIKey::Uki(path) => path,
75+
};
76+
if path.as_str().contains(&*booted_cfs.cmdline.digest) {
7477
return Ok(entry);
7578
}
7679
}

crates/lib/src/bootc_composefs/status.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
},
2323
install::EFI_LOADER_INFO,
2424
parsers::{
25-
bls_config::{BLSConfig, BLSConfigType, parse_bls_config},
25+
bls_config::{BLSConfig, BLSConfigType, EFIKey, parse_bls_config},
2626
grub_menuconfig::{MenuEntry, parse_grub_menuentry_file},
2727
},
2828
spec::{BootEntry, BootOrder, BootloaderKind, Host, HostSpec, ImageStatus},
@@ -980,8 +980,11 @@ async fn composefs_deployment_status_from(
980980

981981
let is_rollback_queued = match &bls_config.cfg_type {
982982
// For UKI boot
983-
BLSConfigType::EFI { efi } => {
984-
efi.as_str().contains(booted_composefs_digest.as_ref())
983+
BLSConfigType::EFI { key } => {
984+
let path = match key {
985+
EFIKey::Efi(path) | EFIKey::Uki(path) => path,
986+
};
987+
path.as_str().contains(booted_composefs_digest.as_ref())
985988
}
986989

987990
// For boot entry Type1

crates/lib/src/bootloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub(crate) fn install_systemd_boot(
326326
}
327327

328328
#[context("Querying bootctl version")]
329-
fn bootctl_systemd_version() -> Result<u32> {
329+
pub(crate) fn bootctl_systemd_version() -> Result<u32> {
330330
let out = Command::new("bootctl").arg("--version").run_get_string()?;
331331
parse_systemd_version(&out)
332332
}

0 commit comments

Comments
 (0)