@@ -48,7 +48,8 @@ use ostree_ext::composefs::{
4848 util:: Sha256Digest ,
4949} ;
5050use 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} ;
5354use ostree_ext:: composefs_oci:: {
5455 image:: create_filesystem as create_composefs_filesystem, pull as composefs_oci_pull,
@@ -66,6 +67,7 @@ use ostree_ext::{
6667use rustix:: fs:: FileTypeExt ;
6768use rustix:: fs:: MetadataExt as _;
6869use serde:: { Deserialize , Serialize } ;
70+ use schemars:: JsonSchema ;
6971
7072#[ cfg( feature = "install-to-disk" ) ]
7173use 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
18391867pub ( 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" ) ]
18431874pub ( 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