Skip to content

Commit ef52c2c

Browse files
composefs/bls: Get cmdline from usr/lib/bootc/kargs.d
Parse toml files in usr/lib/bootc/kargs.d and append them to kernel cmdline on install and upgrade/switch. Also, copy over current deployment's cmdline args on upgrade/switch to another deployment Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 99123ba commit ef52c2c

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::Path;
55

66
use anyhow::{anyhow, Context, Result};
77
use bootc_blockdev::find_parent_devices;
8-
use bootc_kernel_cmdline::utf8::Cmdline;
8+
use bootc_kernel_cmdline::utf8::{Cmdline, Parameter};
99
use bootc_mount::inspect_filesystem_of_dir;
1010
use bootc_mount::tempmount::TempMount;
1111
use camino::{Utf8Path, Utf8PathBuf};
@@ -33,6 +33,7 @@ use rustix::{mount::MountFlags, path::Arg};
3333
use schemars::JsonSchema;
3434
use serde::{Deserialize, Serialize};
3535

36+
use crate::bootc_kargs::kargs_from_composefs_filesystem;
3637
use crate::composefs_consts::{TYPE1_ENT_PATH, TYPE1_ENT_PATH_STAGED};
3738
use crate::parsers::bls_config::{BLSConfig, BLSConfigType};
3839
use crate::parsers::grub_menuconfig::MenuEntry;
@@ -51,7 +52,6 @@ use crate::{
5152
BOOT_LOADER_ENTRIES, COMPOSEFS_CMDLINE, ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_DIGEST,
5253
STAGED_BOOT_LOADER_ENTRIES, STATE_DIR_ABS, USER_CFG, USER_CFG_STAGED,
5354
},
54-
install::RW_KARG,
5555
spec::{Bootloader, Host},
5656
};
5757

@@ -381,10 +381,11 @@ pub(crate) fn setup_composefs_bls_boot(
381381
repo: crate::store::ComposefsRepository,
382382
id: &Sha512HashValue,
383383
entry: &ComposefsBootEntry<Sha512HashValue>,
384+
mounted_erofs: &Dir
384385
) -> Result<String> {
385386
let id_hex = id.to_hex();
386387

387-
let (root_path, esp_device, cmdline_refs, fs, bootloader) = match setup_type {
388+
let (root_path, esp_device, mut cmdline_refs, fs, bootloader) = match setup_type {
388389
BootSetupType::Setup((root_setup, state, postfetch, fs)) => {
389390
// root_setup.kargs has [root=UUID=<UUID>, "rw"]
390391
let mut cmdline_options = Cmdline::new();
@@ -415,16 +416,53 @@ pub(crate) fn setup_composefs_bls_boot(
415416
let sysroot_parent = get_sysroot_parent_dev(&storage.physical_root)?;
416417
let bootloader = host.require_composefs_booted()?.bootloader.clone();
417418

419+
let current_cfg = match bootloader {
420+
Bootloader::Grub => {
421+
let boot_dir = storage
422+
.physical_root
423+
.open_dir("boot")
424+
.context("Opening boot")?;
425+
426+
get_booted_bls(&boot_dir)?
427+
}
428+
429+
Bootloader::Systemd => {
430+
let esp = get_esp_partition(&sysroot_parent)?.0;
431+
let esp_mnt = mount_esp(&esp)?;
432+
433+
get_booted_bls(&esp_mnt.fd)?
434+
}
435+
};
436+
437+
let mut cmdline = match current_cfg.cfg_type {
438+
BLSConfigType::NonEFI { options, .. } => {
439+
let options = options
440+
.ok_or_else(|| anyhow::anyhow!("No 'options' found in BLS Config"))?;
441+
442+
Cmdline::from(options)
443+
}
444+
445+
_ => anyhow::bail!("Found NonEFI config"),
446+
};
447+
448+
// Copy all cmdline args, replacing only `composefs=`
449+
let param = format!("{COMPOSEFS_CMDLINE}={id_hex}");
450+
let param =
451+
Parameter::parse(&param).context("Failed to create 'composefs=' parameter")?;
452+
cmdline.add_or_modify(&param);
453+
418454
(
419455
Utf8PathBuf::from("/sysroot"),
420456
get_esp_partition(&sysroot_parent)?.0,
421-
Cmdline::from(format!("{RW_KARG} {COMPOSEFS_CMDLINE}={id_hex}")),
457+
cmdline,
422458
fs,
423459
bootloader,
424460
)
425461
}
426462
};
427463

464+
kargs_from_composefs_filesystem(mounted_erofs, &mut cmdline_refs)?;
465+
428466
let is_upgrade = matches!(setup_type, BootSetupType::Upgrade(..));
429467

430468
let (entry_paths, _tmpdir_guard) = match bootloader {
@@ -1053,6 +1091,7 @@ pub(crate) fn setup_composefs_boot(
10531091
repo,
10541092
&id,
10551093
entry,
1094+
&mounted_fs
10561095
)?;
10571096

10581097
boot_digest = Some(digest);

crates/lib/src/bootc_composefs/switch.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use anyhow::{Context, Result};
22
use camino::Utf8PathBuf;
3+
use cap_std_ext::cap_std::fs::Dir;
4+
use composefs::fsverity::FsVerityHashValue;
35
use fn_error_context::context;
46

57
use crate::{
@@ -54,13 +56,20 @@ pub(crate) async fn switch_composefs(
5456
let boot_type = BootType::from(entry);
5557
let mut boot_digest = None;
5658

59+
let mounted_fs = Dir::reopen_dir(
60+
&repo
61+
.mount(&id.to_hex())
62+
.context("Failed to mount composefs image")?,
63+
)?;
64+
5765
match boot_type {
5866
BootType::Bls => {
5967
boot_digest = Some(setup_composefs_bls_boot(
6068
BootSetupType::Upgrade((storage, &fs, &host)),
6169
repo,
6270
&id,
6371
entry,
72+
&mounted_fs,
6473
)?)
6574
}
6675
BootType::Uki => setup_composefs_uki_boot(

crates/lib/src/bootc_composefs/update.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use anyhow::{Context, Result};
22
use camino::Utf8PathBuf;
3-
use composefs::util::{parse_sha256, Sha256Digest};
3+
use cap_std_ext::cap_std::fs::Dir;
4+
use composefs::{
5+
fsverity::FsVerityHashValue,
6+
util::{parse_sha256, Sha256Digest},
7+
};
48
use fn_error_context::context;
59
use ostree_ext::oci_spec::image::{ImageConfiguration, ImageManifest};
610

@@ -154,6 +158,12 @@ pub(crate) async fn upgrade_composefs(
154158
anyhow::bail!("No boot entries!");
155159
};
156160

161+
let mounted_fs = Dir::reopen_dir(
162+
&repo
163+
.mount(&id.to_hex())
164+
.context("Failed to mount composefs image")?,
165+
)?;
166+
157167
let boot_type = BootType::from(entry);
158168
let mut boot_digest = None;
159169

@@ -164,6 +174,7 @@ pub(crate) async fn upgrade_composefs(
164174
repo,
165175
&id,
166176
entry,
177+
&mounted_fs,
167178
)?)
168179
}
169180

crates/lib/src/bootc_kargs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ impl Config {
4545
}
4646
}
4747

48+
/// Looks for files in usr/lib/bootc/kargs.d and parses cmdline agruments
49+
pub(crate) fn kargs_from_composefs_filesystem(
50+
new_fs: &Dir,
51+
cmdline: &mut Cmdline,
52+
) -> Result<()> {
53+
let remote_kargs = get_kargs_in_root(new_fs, std::env::consts::ARCH)?;
54+
cmdline.extend(&remote_kargs);
55+
Ok(())
56+
}
57+
4858
/// Load and parse all bootc kargs.d files in the specified root, returning
4959
/// a combined list.
5060
pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<CmdlineOwned> {

0 commit comments

Comments
 (0)