Skip to content

Commit 8b56e8f

Browse files
install/composefs: Move UKI write logic to bootc
Instead of using `write_boot_simple` from composefs-rs, have custom logic in bootc to write UKIs and Grub menuentries Signed-off-by: Johan-Liebert1 <[email protected]>
1 parent 04f048f commit 8b56e8f

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

crates/lib/src/deploy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,15 +767,15 @@ pub(crate) fn rollback_composefs_uki(current: &BootEntry, rollback: &BootEntry)
767767
// Shouldn't really happen
768768
anyhow::bail!("Verity not found for rollback deployment")
769769
};
770-
usr_cfg.write(get_user_config(&verity).as_bytes())?;
770+
usr_cfg.write(get_user_config(todo!(), &verity).as_bytes())?;
771771

772772
let verity = if let Some(composefs) = &current.composefs {
773773
composefs.verity.clone()
774774
} else {
775775
// Shouldn't really happen
776776
anyhow::bail!("Verity not found for booted deployment")
777777
};
778-
usr_cfg.write(get_user_config(&verity).as_bytes())?;
778+
usr_cfg.write(get_user_config(todo!(), &verity).as_bytes())?;
779779

780780
Ok(())
781781
}

crates/lib/src/install.rs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod osbuild;
1414
pub(crate) mod osconfig;
1515

1616
use std::collections::HashMap;
17+
use std::fmt::write;
1718
use std::fs::create_dir_all;
1819
use std::io::{Read, Write};
1920
use std::os::fd::{AsFd, AsRawFd};
@@ -50,8 +51,7 @@ use ostree_ext::composefs::{
5051
util::Sha256Digest,
5152
};
5253
use ostree_ext::composefs_boot::{
53-
bootloader::BootEntry as ComposefsBootEntry,
54-
write_boot::write_boot_simple as composefs_write_boot_simple, BootOps,
54+
bootloader::BootEntry as ComposefsBootEntry, cmdline::get_cmdline_composefs, uki, BootOps,
5555
};
5656
use ostree_ext::composefs_oci::{
5757
image::create_filesystem as create_composefs_filesystem, pull as composefs_oci_pull,
@@ -69,8 +69,8 @@ use ostree_ext::{
6969
use rustix::fs::FileTypeExt;
7070
use rustix::fs::MetadataExt as _;
7171
use rustix::path::Arg;
72-
use serde::{Deserialize, Serialize};
7372
use schemars::JsonSchema;
73+
use serde::{Deserialize, Serialize};
7474

7575
#[cfg(feature = "install-to-disk")]
7676
use self::baseline::InstallBlockDeviceOpts;
@@ -269,7 +269,9 @@ impl TryFrom<&str> for BootType {
269269
match value {
270270
"bls" => Ok(Self::Bls),
271271
"uki" => Ok(Self::Uki),
272-
unrecognized => Err(anyhow::anyhow!("Unrecognized boot option: '{unrecognized}'")),
272+
unrecognized => Err(anyhow::anyhow!(
273+
"Unrecognized boot option: '{unrecognized}'"
274+
)),
273275
}
274276
}
275277
}
@@ -1706,10 +1708,11 @@ pub fn get_esp_partition(device: &str) -> Result<(String, Option<String>)> {
17061708
Ok((esp.node, esp.uuid))
17071709
}
17081710

1709-
pub(crate) fn get_user_config(uki_id: &str) -> String {
1711+
pub(crate) fn get_user_config(boot_label: &String, uki_id: &str) -> String {
1712+
// TODO: Full EFI path here
17101713
let s = format!(
17111714
r#"
1712-
menuentry "Fedora Bootc UKI: ({uki_id})" {{
1715+
menuentry "{boot_label}: ({uki_id})" {{
17131716
insmod fat
17141717
insmod chain
17151718
search --no-floppy --set=root --fs-uuid "${{EFI_PART_UUID}}"
@@ -1779,16 +1782,34 @@ pub(crate) fn setup_composefs_uki_boot(
17791782
.args([&PathBuf::from(&esp_device), &mounted_esp.clone()])
17801783
.run()?;
17811784

1782-
composefs_write_boot_simple(
1783-
&repo,
1784-
entry,
1785-
&id,
1786-
false,
1787-
&mounted_esp,
1788-
None,
1789-
Some(&id.to_hex()),
1790-
&[],
1791-
)?;
1785+
let boot_label = match entry {
1786+
ComposefsBootEntry::Type1(..) => todo!(),
1787+
ComposefsBootEntry::UsrLibModulesUki(..) => todo!(),
1788+
ComposefsBootEntry::UsrLibModulesVmLinuz(..) => todo!(),
1789+
1790+
ComposefsBootEntry::Type2(type2_entry) => {
1791+
let uki = read_file(&type2_entry.file, &repo).context("Reading UKI")?;
1792+
let cmdline = uki::get_cmdline(&uki).context("Getting UKI cmdline")?;
1793+
let (composefs_cmdline, _) = get_cmdline_composefs::<Sha256HashValue>(cmdline)?;
1794+
1795+
let boot_label = uki::get_boot_label(&uki).context("Getting UKI boot label")?;
1796+
1797+
if composefs_cmdline != *id {
1798+
anyhow::bail!(
1799+
"The UKI has the wrong composefs= parameter (is '{composefs_cmdline:?}', should be {id:?})"
1800+
);
1801+
}
1802+
1803+
// Write the UKI to ESP
1804+
let efi_linux = mounted_esp.join("EFI/Linux");
1805+
create_dir_all(&efi_linux).context("Creating EFI/Linux")?;
1806+
1807+
let final_uki_path = efi_linux.join(format!("{}.efi", id.to_hex()));
1808+
std::fs::write(final_uki_path, uki).context("Writing UKI to final path")?;
1809+
1810+
boot_label
1811+
}
1812+
};
17921813

17931814
Task::new("Unmounting ESP", "umount")
17941815
.arg(&mounted_esp)
@@ -1826,7 +1847,7 @@ pub(crate) fn setup_composefs_uki_boot(
18261847
.with_context(|| format!("Opening {user_cfg_name}"))?;
18271848

18281849
usr_cfg.write_all(efi_uuid_source.as_bytes())?;
1829-
usr_cfg.write_all(get_user_config(&id.to_hex()).as_bytes())?;
1850+
usr_cfg.write_all(get_user_config(&boot_label, &id.to_hex()).as_bytes())?;
18301851

18311852
// root_path here will be /sysroot
18321853
for entry in std::fs::read_dir(root_path.join(STATE_DIR_RELATIVE))? {
@@ -1836,7 +1857,7 @@ pub(crate) fn setup_composefs_uki_boot(
18361857
// SAFETY: Deployment file name shouldn't containg non UTF-8 chars
18371858
let depl_file_name = depl_file_name.to_string_lossy();
18381859

1839-
usr_cfg.write_all(get_user_config(&depl_file_name).as_bytes())?;
1860+
usr_cfg.write_all(get_user_config(&boot_label, &depl_file_name).as_bytes())?;
18401861
}
18411862

18421863
return Ok(());
@@ -1868,7 +1889,7 @@ pub(crate) fn setup_composefs_uki_boot(
18681889
.with_context(|| format!("Opening {user_cfg_name}"))?;
18691890

18701891
usr_cfg.write_all(efi_uuid_source.as_bytes())?;
1871-
usr_cfg.write_all(get_user_config(&id.to_hex()).as_bytes())?;
1892+
usr_cfg.write_all(get_user_config(&boot_label, &id.to_hex()).as_bytes())?;
18721893

18731894
Ok(())
18741895
}

0 commit comments

Comments
 (0)