@@ -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}
@@ -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
18371865pub ( 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" ) ]
18411872pub ( 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