@@ -49,7 +49,8 @@ use ostree_ext::composefs::{
4949 util:: Sha256Digest ,
5050} ;
5151use 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} ;
5455use ostree_ext:: composefs_oci:: {
5556 image:: create_filesystem as create_composefs_filesystem, pull as composefs_oci_pull,
@@ -67,6 +68,7 @@ use ostree_ext::{
6768use rustix:: fs:: FileTypeExt ;
6869use rustix:: fs:: MetadataExt as _;
6970use serde:: { Deserialize , Serialize } ;
71+ use schemars:: JsonSchema ;
7072
7173#[ cfg( feature = "install-to-disk" ) ]
7274use 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}
@@ -1819,6 +1846,7 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
18191846 signature : None ,
18201847 } ,
18211848 false ,
1849+ composefs_opts. boot ,
18221850 ) ?;
18231851
18241852 Ok ( ( ) )
@@ -1829,13 +1857,17 @@ pub(crate) const COMPOSEFS_STAGED_DEPLOYMENT_PATH: &str = "/run/composefs/staged
18291857/// Relative to /sysroot
18301858pub ( crate ) const STATE_DIR_RELATIVE : & str = "state/deploy" ;
18311859
1860+ pub ( crate ) const ORIGIN_KEY_BOOT : & str = "boot" ;
1861+ pub ( crate ) const ORIGIN_KEY_BOOT_TYPE : & str = "boot_type" ;
1862+
18321863/// Creates and populates /sysroot/state/deploy/image_id
18331864#[ context( "Writing composefs state" ) ]
18341865pub ( crate ) fn write_composefs_state (
18351866 root_path : & Utf8PathBuf ,
18361867 deployment_id : Sha256HashValue ,
18371868 imgref : & ImageReference ,
18381869 staged : bool ,
1870+ boot_type : BootType ,
18391871) -> Result < ( ) > {
18401872 let state_path = root_path. join ( format ! ( "{STATE_DIR_RELATIVE}/{}" , deployment_id. to_hex( ) ) ) ;
18411873
@@ -1854,11 +1886,15 @@ pub(crate) fn write_composefs_state(
18541886 ..
18551887 } = & imgref;
18561888
1857- let config = tini:: Ini :: new ( ) . section ( "origin" ) . item (
1889+ let mut config = tini:: Ini :: new ( ) . section ( "origin" ) . item (
18581890 ORIGIN_CONTAINER ,
1859- format ! ( "ostree-unverified-image:{transport}: {image_name}" ) ,
1891+ format ! ( "ostree-unverified-image:{transport}{image_name}" ) ,
18601892 ) ;
18611893
1894+ config = config
1895+ . section ( ORIGIN_KEY_BOOT )
1896+ . item ( ORIGIN_KEY_BOOT_TYPE , boot_type) ;
1897+
18621898 let mut origin_file =
18631899 std:: fs:: File :: create ( state_path. join ( format ! ( "{}.origin" , deployment_id. to_hex( ) ) ) )
18641900 . context ( "Failed to open .origin file" ) ?;
0 commit comments