Skip to content

Commit 0e4b2eb

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs/boot: Get os_id from mounted EROFS
Instead of reading the in memory filesystem to get /usr/lib/os-release get it from the mounted EROFS. This is also prep for providing backwards compatibility due to our newly introduced prefix `bootc_composefs-` where we'll need to create new boot entries and we can get the `os_id` from the mounted root Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com> Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 54307c3 commit 0e4b2eb

File tree

1 file changed

+16
-13
lines changed
  • crates/lib/src/bootc_composefs

1 file changed

+16
-13
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
//! 2. **Secondary**: Currently booted deployment (rollback option)
6363
6464
use std::fs::create_dir_all;
65+
use std::io::Read;
6566
use std::io::Write;
6667
use std::path::Path;
6768
use std::sync::Arc;
@@ -422,19 +423,21 @@ fn write_bls_boot_entries_to_disk(
422423
}
423424

424425
/// Parses /usr/lib/os-release and returns (id, title, version)
425-
fn parse_os_release(mounted_fs: &Dir) -> Result<Option<(String, Option<String>, Option<String>)>> {
426+
/// Expects a reference to the root of the filesystem, or the root
427+
/// of a mounted EROFS
428+
pub fn parse_os_release(root: &Dir) -> Result<Option<(String, Option<String>, Option<String>)>> {
426429
// Every update should have its own /usr/lib/os-release
427-
let file_contents = match mounted_fs.read_to_string("usr/lib/os-release") {
428-
Ok(c) => c,
429-
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
430-
return Ok(None);
431-
}
432-
Err(e) => {
433-
tracing::warn!("Could not read /usr/lib/os-release: {e:?}");
434-
return Ok(None);
435-
}
430+
let file = root
431+
.open_optional("usr/lib/os-release")
432+
.context("Opening usr/lib/os-release")?;
433+
434+
let Some(mut os_rel_file) = file else {
435+
return Ok(None);
436436
};
437437

438+
let mut file_contents = String::new();
439+
os_rel_file.read_to_string(&mut file_contents)?;
440+
438441
let parsed = OsReleaseInfo::parse(&file_contents);
439442

440443
let os_id = parsed
@@ -551,13 +554,13 @@ pub(crate) fn setup_composefs_bls_boot(
551554
// Remove "root=" from kernel cmdline as systemd-auto-gpt-generator should use DPS
552555
// UUID
553556
if bootloader == Bootloader::Systemd {
554-
cmdline_refs.remove(&ParameterKey::from("root"));
557+
cmdline_refs.remove(&ParameterKey::from("root") as &ParameterKey);
555558
}
556559

557560
let is_upgrade = matches!(setup_type, BootSetupType::Upgrade(..));
558561

559562
let current_root = if is_upgrade {
560-
Some(&Dir::open_ambient_dir("/", ambient_authority()).context("Opening root")?)
563+
Some(&Dir::open_ambient_dir("/", ambient_authority()).context("Opening root")? as &Dir)
561564
} else {
562565
None
563566
};
@@ -1222,7 +1225,7 @@ pub(crate) async fn setup_composefs_boot(
12221225
let id = composefs_oci::generate_boot_image(&repo, &pull_result.manifest_digest)
12231226
.context("Generating bootable EROFS image")?;
12241227

1225-
// Get boot entries from the OCI filesystem (untransformed).
1228+
// Reconstruct the OCI filesystem to discover boot entries (kernel, initramfs, etc.).
12261229
let fs = composefs_oci::image::create_filesystem(&*repo, &pull_result.config_digest, None)
12271230
.context("Creating composefs filesystem for boot entry discovery")?;
12281231
let entries =

0 commit comments

Comments
 (0)