Skip to content

Commit 5681d41

Browse files
install/composefs: Store boot type in origin file
Store whether the boot type for the deployment is BLS or UKI in the origin file for the deployment, under the `boot` section with `boot_type` key Signed-off-by: Johan-Liebert1 <[email protected]>
1 parent ed83e7e commit 5681d41

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

lib/src/cli.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,12 +797,14 @@ async fn upgrade_composefs(_opts: UpgradeOpts) -> Result<()> {
797797
anyhow::bail!("No boot entries!");
798798
};
799799

800-
match BootType::from(&entry) {
800+
let boot_type = BootType::from(&entry);
801+
802+
match boot_type {
801803
BootType::Bls => setup_composefs_bls_boot(BootSetupType::Upgrade, repo, &id, entry),
802804
BootType::Uki => setup_composefs_uki_boot(BootSetupType::Upgrade, repo, &id, entry),
803805
}?;
804806

805-
write_composefs_state(&Utf8PathBuf::from("/sysroot"), id, imgref, true)?;
807+
write_composefs_state(&Utf8PathBuf::from("/sysroot"), id, imgref, true, boot_type)?;
806808

807809
Ok(())
808810
}
@@ -964,12 +966,20 @@ async fn switch_composefs(opts: SwitchOpts) -> Result<()> {
964966
anyhow::bail!("No boot entries!");
965967
};
966968

967-
match BootType::from(&entry) {
969+
let boot_type = BootType::from(&entry);
970+
971+
match boot_type {
968972
BootType::Bls => setup_composefs_bls_boot(BootSetupType::Upgrade, repo, &id, entry),
969973
BootType::Uki => setup_composefs_uki_boot(BootSetupType::Upgrade, repo, &id, entry),
970974
}?;
971975

972-
write_composefs_state(&Utf8PathBuf::from("/sysroot"), id, &target_imgref, true)?;
976+
write_composefs_state(
977+
&Utf8PathBuf::from("/sysroot"),
978+
id,
979+
&target_imgref,
980+
true,
981+
boot_type,
982+
)?;
973983

974984
Ok(())
975985
}

lib/src/install.rs

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ use ostree_ext::composefs::{
4949
util::Sha256Digest,
5050
};
5151
use ostree_ext::composefs_boot::{
52-
bootloader::BootEntry, write_boot::write_boot_simple as composefs_write_boot_simple, BootOps,
52+
bootloader::BootEntry as ComposefsBootEntry,
53+
write_boot::write_boot_simple as composefs_write_boot_simple, BootOps,
5354
};
5455
use ostree_ext::composefs_oci::{
5556
image::create_filesystem as create_composefs_filesystem, pull as composefs_oci_pull,
@@ -67,6 +68,7 @@ use ostree_ext::{
6768
use rustix::fs::FileTypeExt;
6869
use rustix::fs::MetadataExt as _;
6970
use serde::{Deserialize, Serialize};
71+
use schemars::JsonSchema;
7072

7173
#[cfg(feature = "install-to-disk")]
7274
use self::baseline::InstallBlockDeviceOpts;
@@ -237,20 +239,45 @@ pub(crate) struct InstallConfigOpts {
237239
pub(crate) stateroot: Option<String>,
238240
}
239241

240-
#[derive(ValueEnum, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
241-
pub(crate) enum BootType {
242+
#[derive(
243+
ValueEnum, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Default, JsonSchema,
244+
)]
245+
pub enum BootType {
242246
#[default]
243247
Bls,
244248
Uki,
245249
}
246250

247-
impl From<&BootEntry<Sha256HashValue>> for BootType {
248-
fn from(entry: &BootEntry<Sha256HashValue>) -> Self {
251+
impl ::std::fmt::Display for BootType {
252+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
253+
let s = match self {
254+
BootType::Bls => "bls",
255+
BootType::Uki => "uki",
256+
};
257+
258+
write!(f, "{}", s)
259+
}
260+
}
261+
262+
impl TryFrom<&str> for BootType {
263+
type Error = anyhow::Error;
264+
265+
fn try_from(value: &str) -> std::result::Result<Self, Self::Error> {
266+
match value {
267+
"bls" => Ok(Self::Bls),
268+
"uki" => Ok(Self::Uki),
269+
unrecognized => Err(anyhow::anyhow!("Unrecognized boot option: '{unrecognized}'")),
270+
}
271+
}
272+
}
273+
274+
impl From<&ComposefsBootEntry<Sha256HashValue>> for BootType {
275+
fn from(entry: &ComposefsBootEntry<Sha256HashValue>) -> Self {
249276
match entry {
250-
BootEntry::Type1(..) => Self::Bls,
251-
BootEntry::Type2(..) => Self::Uki,
252-
BootEntry::UsrLibModulesUki(..) => Self::Uki,
253-
BootEntry::UsrLibModulesVmLinuz(..) => Self::Bls,
277+
ComposefsBootEntry::Type1(..) => Self::Bls,
278+
ComposefsBootEntry::Type2(..) => Self::Uki,
279+
ComposefsBootEntry::UsrLibModulesUki(..) => Self::Uki,
280+
ComposefsBootEntry::UsrLibModulesVmLinuz(..) => Self::Bls,
254281
}
255282
}
256283
}
@@ -1826,6 +1853,7 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
18261853
signature: None,
18271854
},
18281855
false,
1856+
composefs_opts.boot,
18291857
)?;
18301858

18311859
Ok(())
@@ -1836,13 +1864,17 @@ pub(crate) const COMPOSEFS_STAGED_DEPLOYMENT_PATH: &str = "/run/composefs/staged
18361864
/// Relative to /sysroot
18371865
pub(crate) const STATE_DIR_RELATIVE: &str = "state/deploy";
18381866

1867+
pub(crate) const ORIGIN_KEY_BOOT: &str = "boot";
1868+
pub(crate) const ORIGIN_KEY_BOOT_TYPE: &str = "boot_type";
1869+
18391870
/// Creates and populates /sysroot/state/deploy/image_id
18401871
#[context("Writing composefs state")]
18411872
pub(crate) fn write_composefs_state(
18421873
root_path: &Utf8PathBuf,
18431874
deployment_id: Sha256HashValue,
18441875
imgref: &ImageReference,
18451876
staged: bool,
1877+
boot_type: BootType,
18461878
) -> Result<()> {
18471879
let state_path = root_path.join(format!("{STATE_DIR_RELATIVE}/{}", deployment_id.to_hex()));
18481880

@@ -1861,11 +1893,15 @@ pub(crate) fn write_composefs_state(
18611893
..
18621894
} = &imgref;
18631895

1864-
let config = tini::Ini::new().section("origin").item(
1896+
let mut config = tini::Ini::new().section("origin").item(
18651897
ORIGIN_CONTAINER,
1866-
format!("ostree-unverified-image:{transport}:{image_name}"),
1898+
format!("ostree-unverified-image:{transport}{image_name}"),
18671899
);
18681900

1901+
config = config
1902+
.section(ORIGIN_KEY_BOOT)
1903+
.item(ORIGIN_KEY_BOOT_TYPE, boot_type);
1904+
18691905
let mut origin_file =
18701906
std::fs::File::create(state_path.join(format!("{}.origin", deployment_id.to_hex())))
18711907
.context("Failed to open .origin file")?;

0 commit comments

Comments
 (0)