Skip to content

Commit a9da46e

Browse files
jbtrystramcgwalters
authored andcommitted
install/config: wire up skip_boot_uuid_stamp
Wiring-up this knob to the install config to allow it's use in bootc-image-builder. Assisted-by: OpenCode (Opus 4.5) Signed-off-by: jbtrystram <[email protected]>
1 parent 15b5f4d commit a9da46e

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

crates/lib/src/install.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ async fn verify_target_fetch(
15171517

15181518
/// Preparation for an install; validates and prepares some (thereafter immutable) global state.
15191519
async fn prepare_install(
1520-
config_opts: InstallConfigOpts,
1520+
mut config_opts: InstallConfigOpts,
15211521
source_opts: InstallSourceOpts,
15221522
target_opts: InstallTargetOpts,
15231523
mut composefs_options: InstallComposefsOpts,
@@ -1642,8 +1642,17 @@ async fn prepare_install(
16421642
}
16431643

16441644
let install_config = config::load_config()?;
1645-
if install_config.is_some() {
1645+
if let Some(ref config) = install_config {
16461646
tracing::debug!("Loaded install configuration");
1647+
// Merge config file values into config_opts (CLI takes precedence)
1648+
// Only apply config file value if CLI didn't explicitly set it
1649+
if !config_opts.bootupd_skip_boot_uuid {
1650+
config_opts.bootupd_skip_boot_uuid = config
1651+
.bootupd
1652+
.as_ref()
1653+
.and_then(|b| b.skip_boot_uuid)
1654+
.unwrap_or(false);
1655+
}
16471656
} else {
16481657
tracing::debug!("No install configuration found");
16491658
}

crates/lib/src/install/config.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ pub(crate) struct BasicFilesystems {
6161
/// Configuration for ostree repository
6262
pub(crate) type OstreeRepoOpts = ostree_ext::repo_options::RepoOptions;
6363

64+
/// Configuration options for bootupd, responsible for setting up the bootloader.
65+
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
66+
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
67+
pub(crate) struct Bootupd {
68+
/// Whether to skip writing the boot partition UUID to the bootloader configuration.
69+
/// When true, bootupd is invoked with `--with-static-configs` instead of `--write-uuid`.
70+
/// Defaults to false (UUIDs are written by default).
71+
pub(crate) skip_boot_uuid: Option<bool>,
72+
}
73+
6474
/// The serialized `[install]` section
6575
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6676
#[serde(rename = "install", rename_all = "kebab-case", deny_unknown_fields)]
@@ -85,6 +95,8 @@ pub(crate) struct InstallConfiguration {
8595
pub(crate) root_mount_spec: Option<String>,
8696
/// Mount specification for the /boot filesystem.
8797
pub(crate) boot_mount_spec: Option<String>,
98+
/// Bootupd configuration
99+
pub(crate) bootupd: Option<Bootupd>,
88100
}
89101

90102
fn merge_basic<T>(s: &mut Option<T>, o: Option<T>, _env: &EnvProperties) {
@@ -142,6 +154,13 @@ impl Mergeable for OstreeRepoOpts {
142154
}
143155
}
144156

157+
impl Mergeable for Bootupd {
158+
/// Apply any values in other, overriding any existing values in `self`.
159+
fn merge(&mut self, other: Self, env: &EnvProperties) {
160+
merge_basic(&mut self.skip_boot_uuid, other.skip_boot_uuid, env)
161+
}
162+
}
163+
145164
impl Mergeable for InstallConfiguration {
146165
/// Apply any values in other, overriding any existing values in `self`.
147166
fn merge(&mut self, other: Self, env: &EnvProperties) {
@@ -160,6 +179,7 @@ impl Mergeable for InstallConfiguration {
160179
merge_basic(&mut self.stateroot, other.stateroot, env);
161180
merge_basic(&mut self.root_mount_spec, other.root_mount_spec, env);
162181
merge_basic(&mut self.boot_mount_spec, other.boot_mount_spec, env);
182+
self.bootupd.merge(other.bootupd, env);
163183
if let Some(other_kargs) = other.kargs {
164184
self.kargs
165185
.get_or_insert_with(Default::default)
@@ -731,4 +751,62 @@ boot-mount-spec = ""
731751
assert_eq!(install.root_mount_spec.as_deref().unwrap(), "");
732752
assert_eq!(install.boot_mount_spec.as_deref().unwrap(), "");
733753
}
754+
755+
#[test]
756+
fn test_parse_bootupd_skip_boot_uuid() {
757+
// Test parsing true
758+
let c: InstallConfigurationToplevel = toml::from_str(
759+
r#"[install.bootupd]
760+
skip-boot-uuid = true
761+
"#,
762+
)
763+
.unwrap();
764+
assert_eq!(
765+
c.install.unwrap().bootupd.unwrap().skip_boot_uuid.unwrap(),
766+
true
767+
);
768+
769+
// Test parsing false
770+
let c: InstallConfigurationToplevel = toml::from_str(
771+
r#"[install.bootupd]
772+
skip-boot-uuid = false
773+
"#,
774+
)
775+
.unwrap();
776+
assert_eq!(
777+
c.install.unwrap().bootupd.unwrap().skip_boot_uuid.unwrap(),
778+
false
779+
);
780+
781+
// Test default (not specified) is None
782+
let c: InstallConfigurationToplevel = toml::from_str(
783+
r#"[install]
784+
root-fs-type = "xfs"
785+
"#,
786+
)
787+
.unwrap();
788+
assert!(c.install.unwrap().bootupd.is_none());
789+
}
790+
791+
#[test]
792+
fn test_merge_bootupd_skip_boot_uuid() {
793+
let env = EnvProperties {
794+
sys_arch: "x86_64".to_string(),
795+
};
796+
let mut install: InstallConfiguration = toml::from_str(
797+
r#"[bootupd]
798+
skip-boot-uuid = false
799+
"#,
800+
)
801+
.unwrap();
802+
let other = InstallConfiguration {
803+
bootupd: Some(Bootupd {
804+
skip_boot_uuid: Some(true),
805+
}),
806+
..Default::default()
807+
};
808+
install.merge(other, &env);
809+
// skip_boot_uuid should be overridden to true
810+
assert_eq!(install.bootupd.unwrap().skip_boot_uuid.unwrap(), true);
811+
}
734812
}

docs/src/man/bootc-install-config.5.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ Configuration options for the ostree repository. There is one valid field:
5454
Boot Loader Spec entries, except for the default entry. This is useful for configuring
5555
arguments that should only apply to non-default deployments.
5656

57+
# bootupd
58+
59+
Configuration options for bootupd, responsible of setting up the bootloader.
60+
There is only one valid field:
61+
- `skip-boot-uuid`: A boolean that controls whether to skip writing partition UUIDs
62+
to the bootloader configuration. When `true`, bootupd is invoked with `--with-static-configs`
63+
instead of `--write-uuid`. Defaults to `false` (UUIDs are written by default).
64+
5765
# Examples
5866

5967
```toml

0 commit comments

Comments
 (0)