Skip to content

Commit

Permalink
Merge pull request #647 from cgwalters/kargs-install-time
Browse files Browse the repository at this point in the history
install: Pick up kargs.d kernel arguments too
  • Loading branch information
cgwalters authored Jun 28, 2024
2 parents 0bd1956 + 3c7a620 commit 767ec9c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions hack/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
1 change: 1 addition & 0 deletions hack/test-kargs/10-test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kargs = ["kargsd-test=1", "kargsd-othertest=2"]
1 change: 1 addition & 0 deletions hack/test-kargs/20-test2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kargs = ["testing-kargsd=3"]
13 changes: 13 additions & 0 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -640,18 +642,29 @@ 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()
.and_then(|c| c.kargs.as_ref())
.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::<Vec<_>>();
let mut options = ostree_container::deploy::DeployOpts::default();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/kargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>> {
pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
// 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
Expand Down
5 changes: 5 additions & 0 deletions tests-integration/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 767ec9c

Please sign in to comment.