Skip to content

Commit fd2796a

Browse files
install/composefs: Write boot entries
Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent abb214d commit fd2796a

File tree

1 file changed

+77
-2
lines changed

1 file changed

+77
-2
lines changed

lib/src/install.rs

Lines changed: 77 additions & 2 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::fs::create_dir_all;
1718
use std::io::Write;
1819
use std::os::fd::{AsFd, AsRawFd};
1920
use std::os::unix::process::CommandExt;
@@ -41,9 +42,11 @@ use fn_error_context::context;
4142
use ostree::gio;
4243
use ostree_ext::composefs::{
4344
fsverity::{FsVerityHashValue, Sha256HashValue},
45+
oci::image::create_filesystem as create_composefs_filesystem,
4446
oci::pull as composefs_oci_pull,
4547
repository::Repository as ComposefsRepository,
4648
util::Sha256Digest,
49+
write_boot::write_boot_simple as composefs_write_boot_simple,
4750
};
4851
use ostree_ext::oci_spec;
4952
use ostree_ext::ostree;
@@ -1435,6 +1438,11 @@ impl BoundImages {
14351438
}
14361439
}
14371440

1441+
fn open_composefs_repo(rootfs_dir: &Dir) -> Result<ComposefsRepository<Sha256HashValue>> {
1442+
ComposefsRepository::open_path(rootfs_dir, "composefs")
1443+
.context("Failed to open composefs repository")
1444+
}
1445+
14381446
async fn initialize_composefs_repository(
14391447
state: &State,
14401448
root_setup: &RootSetup,
@@ -1447,15 +1455,80 @@ async fn initialize_composefs_repository(
14471455

14481456
tracing::warn!("STATE: {state:#?}");
14491457

1450-
let repo: ComposefsRepository<Sha256HashValue> =
1451-
ComposefsRepository::open_path(rootfs_dir, "composefs").expect("failed to open_path");
1458+
let repo = open_composefs_repo(rootfs_dir)?;
14521459

14531460
let OstreeExtImgRef { transport, name } = &state.target_imgref.imgref;
14541461

14551462
// transport's display is already of type "<transport_type>:"
14561463
composefs_oci_pull(&Arc::new(repo), &format!("{transport}{name}",), None).await
14571464
}
14581465

1466+
#[context("Setting up composefs boot")]
1467+
fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -> Result<()> {
1468+
let boot_uuid = root_setup
1469+
.get_boot_uuid()?
1470+
.or(root_setup.rootfs_uuid.as_deref())
1471+
.ok_or_else(|| anyhow!("No uuid for boot/root"))?;
1472+
1473+
if cfg!(target_arch = "s390x") {
1474+
// TODO: Integrate s390x support into install_via_bootupd
1475+
crate::bootloader::install_via_zipl(&root_setup.device_info, boot_uuid)?;
1476+
} else {
1477+
crate::bootloader::install_via_bootupd(
1478+
&root_setup.device_info,
1479+
&root_setup.physical_root_path,
1480+
&state.config_opts,
1481+
)?;
1482+
}
1483+
1484+
let repo = open_composefs_repo(&root_setup.physical_root)?;
1485+
1486+
let mut fs = create_composefs_filesystem(&repo, image_id, None)?;
1487+
1488+
let entries = fs.transform_for_boot(&repo)?;
1489+
let id = fs.commit_image(&repo, None)?;
1490+
1491+
println!("{entries:#?}");
1492+
1493+
let Some(entry) = entries.into_iter().next() else {
1494+
anyhow::bail!("No boot entries!");
1495+
};
1496+
1497+
let rootfs_uuid = match &root_setup.rootfs_uuid {
1498+
Some(u) => u,
1499+
None => anyhow::bail!("Expected rootfs to have a UUID by now"),
1500+
};
1501+
1502+
let cmdline_refs = [
1503+
"console=ttyS0,115200",
1504+
&format!("root=UUID={rootfs_uuid}"),
1505+
"rw",
1506+
];
1507+
1508+
let boot_dir = root_setup.physical_root_path.join("boot");
1509+
create_dir_all(&boot_dir).context("Failed to create boot dir")?;
1510+
1511+
composefs_write_boot_simple(
1512+
&repo,
1513+
entry,
1514+
&id,
1515+
boot_dir.as_std_path(),
1516+
Some(&format!("{}", id.to_hex())),
1517+
Some("/boot"),
1518+
&cmdline_refs,
1519+
)?;
1520+
1521+
let state_path = root_setup
1522+
.physical_root_path
1523+
.join(format!("state/{}", id.to_hex()));
1524+
1525+
create_dir_all(state_path.join("var"))?;
1526+
create_dir_all(state_path.join("etc/upper"))?;
1527+
create_dir_all(state_path.join("etc/work"))?;
1528+
1529+
Ok(())
1530+
}
1531+
14591532
async fn install_to_filesystem_impl(
14601533
state: &State,
14611534
rootfs: &mut RootSetup,
@@ -1498,6 +1571,8 @@ async fn install_to_filesystem_impl(
14981571
id = hex::encode(id),
14991572
verity = verity.to_hex()
15001573
);
1574+
1575+
setup_composefs_boot(rootfs, state, &hex::encode(id))?;
15011576
} else {
15021577
// Initialize the ostree sysroot (repo, stateroot, etc.)
15031578

0 commit comments

Comments
 (0)