Skip to content

Commit 59cbf82

Browse files
committed
install: inject kernel arguments for separate /boot during installation
Also need to mount the separate boot partition to `/target/sysroot/boot` on ostree OS. Signed-off-by: Huijing Hei <hhei@redhat.com>
1 parent fb10bf1 commit 59cbf82

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

crates/lib/src/install.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,16 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
758758
// Another implementation: https://github.com/coreos/coreos-assembler/blob/3cd3307904593b3a131b81567b13a4d0b6fe7c90/src/create_disk.sh#L295
759759
crate::lsm::ensure_dir_labeled(rootfs_dir, "", Some("/".into()), 0o755.into(), sepolicy)?;
760760

761+
// If we're installing alongside existing ostree and there's a separate boot partition,
762+
// we need to mount it to the sysroot's /boot so ostree can write bootloader entries there
763+
if has_ostree && root_setup.boot.is_some() {
764+
if let Some(boot) = &root_setup.boot {
765+
let source_boot = &boot.source;
766+
let target_boot = root_setup.physical_root_path.join(BOOT);
767+
tracing::debug!("Mount {source_boot} to {target_boot} on ostree");
768+
bootc_mount::mount(source_boot, &target_boot)?;
769+
}
770+
}
761771
// And also label /boot AKA xbootldr, if it exists
762772
if rootfs_dir.try_exists("boot")? {
763773
crate::lsm::ensure_dir_labeled(rootfs_dir, "boot", None, 0o755.into(), sepolicy)?;
@@ -970,6 +980,23 @@ async fn install_container(
970980
}
971981
}
972982

983+
// For seperate /boot filesystem, the better workaround is
984+
// to inject kernel arguments during installation.
985+
// See discussion in https://github.com/bootc-dev/bootc/issues/1388
986+
if let Some(boot) = root_setup.boot.as_ref() {
987+
if !boot.source.is_empty() {
988+
let mount_extra = format!(
989+
"systemd.mount-extra={}:{}:{}:{}",
990+
boot.source,
991+
boot.target,
992+
boot.fstype,
993+
boot.options.as_deref().unwrap_or("defaults")
994+
);
995+
kargs.extend(&Cmdline::from(mount_extra.as_str()));
996+
tracing::debug!("Add {mount_extra} to kargs if has seperate /boot");
997+
}
998+
}
999+
9731000
// Finally map into &[&str] for ostree_container
9741001
let kargs_strs: Vec<&str> = kargs.iter_str().collect();
9751002

@@ -1882,6 +1909,7 @@ fn remove_all_except_loader_dirs(bootdir: &Dir, is_ostree: bool) -> Result<()> {
18821909
if let Some(subdir) = bootdir.open_dir_noxdev(&file_name)? {
18831910
remove_all_in_dir_no_xdev(&subdir, false)
18841911
.with_context(|| format!("Removing directory contents: {}", file_name))?;
1912+
bootdir.remove_dir(&file_name)?;
18851913
}
18861914
} else {
18871915
bootdir
@@ -2098,7 +2126,7 @@ pub(crate) async fn install_to_filesystem(
20982126
}
20992127
rootfs_fd
21002128
} else {
2101-
target_rootfs_fd.clone()
2129+
target_rootfs_fd.try_clone()?
21022130
};
21032131

21042132
match fsopts.replace {

0 commit comments

Comments
 (0)