diff --git a/hack/Containerfile b/hack/Containerfile index bc45d202c..50f88ff90 100644 --- a/hack/Containerfile +++ b/hack/Containerfile @@ -23,6 +23,8 @@ COPY hack/provision-derived.sh /tmp RUN /tmp/provision-derived.sh "$variant" && rm -f /tmp/*.sh # Also copy in some default install configs we use for testing COPY hack/install-test-configs/* /usr/lib/bootc/install/ +# And some test kargs +COPY hack/test-kargs /usr/lib/bootc/kargs.d/ # Inject our built code COPY --from=build /out/bootc.tar.zst /tmp RUN tar -C / --zstd -xvf /tmp/bootc.tar.zst && rm -vrf /tmp/* diff --git a/hack/test-kargs/10-test.toml b/hack/test-kargs/10-test.toml new file mode 100644 index 000000000..a03b69779 --- /dev/null +++ b/hack/test-kargs/10-test.toml @@ -0,0 +1 @@ +kargs = ["kargsd-test=1", "kargsd-othertest=2"] diff --git a/hack/test-kargs/20-test2.toml b/hack/test-kargs/20-test2.toml new file mode 100644 index 000000000..ccf4f13ce --- /dev/null +++ b/hack/test-kargs/20-test2.toml @@ -0,0 +1 @@ +kargs = ["testing-kargsd=3"] diff --git a/lib/src/install.rs b/lib/src/install.rs index 4369a4fa2..e0c943cac 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -538,6 +538,8 @@ async fn initialize_ostree_root_from_self( let sepolicy = state.load_policy()?; let sepolicy = sepolicy.as_ref(); + let container_rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?; + // Load a fd for the mounted target physical root let rootfs_dir = &root_setup.rootfs_fd; let rootfs = root_setup.rootfs.as_path(); @@ -640,6 +642,11 @@ async fn initialize_ostree_root_from_self( imgref: src_imageref, }; + // Load the kargs from the /usr/lib/bootc/kargs.d from the running root, + // which should be the same as the filesystem we'll deploy. + let kargsd = crate::kargs::get_kargs_in_root(container_rootfs, std::env::consts::ARCH)?; + let kargsd = kargsd.iter().map(|s| s.as_str()); + let install_config_kargs = state .install_config .as_ref() @@ -647,11 +654,17 @@ async fn initialize_ostree_root_from_self( .into_iter() .flatten() .map(|s| s.as_str()); + // Final kargs, in order: + // - root filesystem kargs + // - install config kargs + // - kargs.d from container image + // - args specified on the CLI let kargs = root_setup .kargs .iter() .map(|v| v.as_str()) .chain(install_config_kargs) + .chain(kargsd) .chain(state.config_opts.karg.iter().flatten().map(|v| v.as_str())) .collect::>(); let mut options = ostree_container::deploy::DeployOpts::default(); diff --git a/lib/src/kargs.rs b/lib/src/kargs.rs index 6de0a51d0..f686400b1 100644 --- a/lib/src/kargs.rs +++ b/lib/src/kargs.rs @@ -22,7 +22,7 @@ struct Config { /// Load and parse all bootc kargs.d files in the specified root, returning /// a combined list. -fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result> { +pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result> { // If the directory doesn't exist, that's OK. let d = if let Some(d) = d.open_dir_optional("usr/lib/bootc/kargs.d")? { d diff --git a/tests-integration/src/install.rs b/tests-integration/src/install.rs index fc390bb76..73b9f30e7 100644 --- a/tests-integration/src/install.rs +++ b/tests-integration/src/install.rs @@ -100,6 +100,11 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments) "sudo /bin/sh -c 'grep localtestkarg=somevalue /boot/loader/entries/*.conf'" ) .run()?; + cmd!( + sh, + "sudo /bin/sh -c 'grep testing-kargsd=3 /boot/loader/entries/*.conf'" + ) + .run()?; let deployment = &find_deployment_root()?; let cwd = sh.push_dir(format!("/proc/self/fd/{}", deployment.as_raw_fd())); cmd!(