Skip to content

Commit 682535e

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 6098379 commit 682535e

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
@@ -787,12 +787,14 @@ async fn upgrade_composefs(_opts: UpgradeOpts) -> Result<()> {
787787
anyhow::bail!("No boot entries!");
788788
};
789789

790-
match BootType::from(&entry) {
790+
let boot_type = BootType::from(&entry);
791+
792+
match boot_type {
791793
BootType::Bls => setup_composefs_bls_boot(BootSetupType::Upgrade, repo, &id, entry),
792794
BootType::Uki => setup_composefs_uki_boot(BootSetupType::Upgrade, repo, &id, entry),
793795
}?;
794796

795-
write_composefs_state(&Utf8PathBuf::from("/sysroot"), id, imgref, true)?;
797+
write_composefs_state(&Utf8PathBuf::from("/sysroot"), id, imgref, true, boot_type)?;
796798

797799
Ok(())
798800
}
@@ -954,12 +956,20 @@ async fn switch_composefs(opts: SwitchOpts) -> Result<()> {
954956
anyhow::bail!("No boot entries!");
955957
};
956958

957-
match BootType::from(&entry) {
959+
let boot_type = BootType::from(&entry);
960+
961+
match boot_type {
958962
BootType::Bls => setup_composefs_bls_boot(BootSetupType::Upgrade, repo, &id, entry),
959963
BootType::Uki => setup_composefs_uki_boot(BootSetupType::Upgrade, repo, &id, entry),
960964
}?;
961965

962-
write_composefs_state(&Utf8PathBuf::from("/sysroot"), id, &target_imgref, true)?;
966+
write_composefs_state(
967+
&Utf8PathBuf::from("/sysroot"),
968+
id,
969+
&target_imgref,
970+
true,
971+
boot_type,
972+
)?;
963973

964974
Ok(())
965975
}

lib/src/install.rs

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ use ostree_ext::composefs::{
4848
util::Sha256Digest,
4949
};
5050
use ostree_ext::composefs_boot::{
51-
bootloader::BootEntry, write_boot::write_boot_simple as composefs_write_boot_simple, BootOps,
51+
bootloader::BootEntry as ComposefsBootEntry,
52+
write_boot::write_boot_simple as composefs_write_boot_simple, BootOps,
5253
};
5354
use ostree_ext::composefs_oci::{
5455
image::create_filesystem as create_composefs_filesystem, pull as composefs_oci_pull,
@@ -66,6 +67,7 @@ use ostree_ext::{
6667
use rustix::fs::FileTypeExt;
6768
use rustix::fs::MetadataExt as _;
6869
use serde::{Deserialize, Serialize};
70+
use schemars::JsonSchema;
6971

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

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

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

18331861
Ok(())
@@ -1838,13 +1866,17 @@ pub(crate) const COMPOSEFS_STAGED_DEPLOYMENT_PATH: &str = "/run/composefs/staged
18381866
/// Relative to /sysroot
18391867
pub(crate) const STATE_DIR_RELATIVE: &str = "state/deploy";
18401868

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

@@ -1863,11 +1895,15 @@ pub(crate) fn write_composefs_state(
18631895
..
18641896
} = &imgref;
18651897

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

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

0 commit comments

Comments
 (0)