Skip to content

Commit b87d620

Browse files
authored
Merge pull request #206 from cgwalters/kargs-install
install: Add `kargs` to installation config
2 parents ee35410 + 9ba17af commit b87d620

File tree

7 files changed

+91
-7
lines changed

7 files changed

+91
-7
lines changed

ci/Dockerfile.fcos

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ RUN make test-bin-archive
77

88
FROM quay.io/fedora/fedora-coreos:testing-devel
99
COPY --from=builder /src/target/bootc.tar.zst /tmp
10+
COPY ci/usr usr
1011
RUN tar -xvf /tmp/bootc.tar.zst && ostree container commit
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[install]
2+
kargs = ["localtestkarg=somevalue", "otherlocalkarg=42"]

docs/install.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,32 @@ in that case you will need to specify `--skip-fetch-check`.
9696

9797
### Operating system install configuration required
9898

99-
The container image **MUST** define its default install configuration. For example,
100-
create `/usr/lib/bootc/install/00-exampleos.toml` with the contents:
99+
The container image **MUST** define its default install configuration. A key choice
100+
that bootc by default leaves up to the operating system image is the root filesystem
101+
type.
102+
103+
To enable `bootc install` as part of your OS/distribution base image,
104+
create a file named `/usr/lib/bootc/install/00-<osname>.toml` with the contents of the form:
101105

102106
```toml
103107
[install]
104108
root-fs-type = "xfs"
105109
```
106110

107-
At the current time, `root-fs-type` is the only available configuration option, and it **MUST** be set.
111+
The `root-fs-type` value **MUST** be set.
108112

109113
Configuration files found in this directory will be merged, with higher alphanumeric values
110114
taking precedence. If for example you are building a derived container image from the above OS,
111115
you could create a `50-myos.toml` that sets `root-fs-type = "btrfs"` which will override the
112116
prior setting.
113117

118+
Other available options, also under the `[install]` section:
119+
120+
`kargs`: This allows setting kernel arguments which apply only at the time of `bootc install`.
121+
This option is particularly useful when creating derived/layered images; for example, a cloud
122+
image may want to have its default `console=` set, in contrast with a default base image.
123+
The values in this field are space separated.
124+
114125
## Installing an "unconfigured" image
115126

116127
The bootc project aims to support generic/general-purpose operating

lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ regex = "1.7.1"
3434
rustix = { "version" = "0.38", features = ["thread", "fs", "system", "process"] }
3535
schemars = { version = "0.8.6", features = ["chrono"] }
3636
serde = { features = ["derive"], version = "1.0.125" }
37+
serde_ignored = "0.1.9"
3738
serde_json = "1.0.64"
3839
serde_yaml = "0.9.17"
3940
serde_with = ">= 1.9.4, < 2"

lib/src/install.rs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ pub(crate) mod config {
381381
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
382382
#[serde(rename = "install", rename_all = "kebab-case", deny_unknown_fields)]
383383
pub(crate) struct InstallConfiguration {
384+
/// Root filesystem type
384385
pub(crate) root_fs_type: Option<super::baseline::Filesystem>,
386+
/// Kernel arguments, applied at installation time
387+
pub(crate) kargs: Option<Vec<String>>,
385388
}
386389

387390
impl InstallConfiguration {
@@ -392,7 +395,12 @@ pub(crate) mod config {
392395
*s = Some(o);
393396
}
394397
}
395-
mergeopt(&mut self.root_fs_type, other.root_fs_type)
398+
mergeopt(&mut self.root_fs_type, other.root_fs_type);
399+
if let Some(other_kargs) = other.kargs {
400+
self.kargs
401+
.get_or_insert_with(|| Default::default())
402+
.extend(other_kargs)
403+
}
396404
}
397405
}
398406

@@ -405,10 +413,18 @@ pub(crate) mod config {
405413
let mut config: Option<InstallConfiguration> = None;
406414
for (_name, path) in fragments {
407415
let buf = std::fs::read_to_string(&path)?;
408-
let c: InstallConfigurationToplevel =
409-
toml::from_str(&buf).with_context(|| format!("Parsing {path:?}"))?;
416+
let mut unused = std::collections::HashSet::new();
417+
let de = toml::Deserializer::new(&buf);
418+
let c: InstallConfigurationToplevel = serde_ignored::deserialize(de, |path| {
419+
unused.insert(path.to_string());
420+
})
421+
.with_context(|| format!("Parsing {path:?}"))?;
422+
for key in unused {
423+
eprintln!("warning: {path:?}: Unknown key {key}");
424+
}
410425
if let Some(config) = config.as_mut() {
411426
if let Some(install) = c.install {
427+
tracing::debug!("Merging install config: {install:?}");
412428
config.merge(install);
413429
}
414430
} else {
@@ -434,10 +450,43 @@ root-fs-type = "xfs"
434450
let other = InstallConfigurationToplevel {
435451
install: Some(InstallConfiguration {
436452
root_fs_type: Some(Filesystem::Ext4),
453+
kargs: None,
437454
}),
438455
};
439456
install.merge(other.install.unwrap());
440457
assert_eq!(install.root_fs_type.unwrap(), Filesystem::Ext4);
458+
459+
let c: InstallConfigurationToplevel = toml::from_str(
460+
r##"[install]
461+
root-fs-type = "ext4"
462+
kargs = ["console=ttyS0", "foo=bar"]
463+
"##,
464+
)
465+
.unwrap();
466+
let mut install = c.install.unwrap();
467+
assert_eq!(install.root_fs_type.unwrap(), Filesystem::Ext4);
468+
let other = InstallConfigurationToplevel {
469+
install: Some(InstallConfiguration {
470+
root_fs_type: None,
471+
kargs: Some(
472+
["console=tty0", "nosmt"]
473+
.into_iter()
474+
.map(ToOwned::to_owned)
475+
.collect(),
476+
),
477+
}),
478+
};
479+
install.merge(other.install.unwrap());
480+
assert_eq!(install.root_fs_type.unwrap(), Filesystem::Ext4);
481+
assert_eq!(
482+
install.kargs,
483+
Some(
484+
["console=ttyS0", "foo=bar", "console=tty0", "nosmt"]
485+
.into_iter()
486+
.map(ToOwned::to_owned)
487+
.collect()
488+
)
489+
)
441490
}
442491
}
443492

lib/src/install/baseline.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ pub(crate) fn install_create_rootfs(
350350
.into_iter()
351351
.flatten()
352352
.chain([rootarg, RW_KARG.to_string(), bootarg].into_iter())
353+
.chain(
354+
state
355+
.install_config
356+
.kargs
357+
.iter()
358+
.flatten()
359+
.map(ToOwned::to_owned),
360+
)
353361
.collect::<Vec<_>>();
354362

355363
mount::mount(&rootdev, &rootfs)?;

tests/kolainst/install

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ cd $(mktemp -d)
1919

2020
case "${AUTOPKGTEST_REBOOT_MARK:-}" in
2121
"")
22-
podman run --rm -ti --privileged --pid=host -v /usr/bin/bootc:/usr/bin/bootc ${IMAGE} bootc install --target-no-signature-verification --karg=foo=bar ${DEV}
22+
mkdir -p ~/.config/containers
23+
cp -a /etc/ostree/auth.json ~/.config/containers
24+
mkdir -p usr/{lib,bin}
25+
cp -a /usr/lib/bootc usr/lib
26+
cp -a /usr/bin/bootc usr/bin
27+
cat > Dockerfile << EOF
28+
FROM ${IMAGE}
29+
COPY usr usr
30+
EOF
31+
podman build -t localhost/testimage .
32+
podman run --rm -ti --privileged --pid=host --env RUST_LOG=error,bootc_lib::install=debug \
33+
localhost/testimage bootc install --target-no-signature-verification --skip-fetch-check --karg=foo=bar ${DEV}
2334
# In theory we could e.g. wipe the bootloader setup on the primary disk, then reboot;
2435
# but for now let's just sanity test that the install command executes.
2536
lsblk ${DEV}
2637
mount /dev/vda3 /var/mnt
2738
grep foo=bar /var/mnt/loader/entries/*.conf
39+
grep localtestkarg=somevalue /var/mnt/loader/entries/*.conf
2840
grep -Ee '^linux /boot/ostree' /var/mnt/loader/entries/*.conf
2941
umount /var/mnt
3042
echo "ok install"

0 commit comments

Comments
 (0)