From 3c7a620bc7f549aee8d948cdea180ee155fae91f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 27 Jun 2024 20:40:18 -0400 Subject: [PATCH] install: Pick up kargs.d kernel arguments too This was a rather important miss; we need to pick up the kargs.d files when doing a `bootc install` too. Signed-off-by: Colin Walters --- hack/Containerfile | 2 ++ hack/test-kargs/10-test.toml | 1 + hack/test-kargs/20-test2.toml | 1 + lib/src/install.rs | 13 +++++++++++++ lib/src/kargs.rs | 2 +- tests-integration/src/install.rs | 5 +++++ 6 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 hack/test-kargs/10-test.toml create mode 100644 hack/test-kargs/20-test2.toml diff --git a/hack/Containerfile b/hack/Containerfile index bc45d202..50f88ff9 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 00000000..a03b6977 --- /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 00000000..ccf4f13c --- /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 4369a4fa..e0c943ca 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 d4815cbe..4fdd5551 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 fc390bb7..73b9f30e 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!(