@@ -14,6 +14,7 @@ mod osbuild;
14
14
pub ( crate ) mod osconfig;
15
15
16
16
use std:: collections:: HashMap ;
17
+ use std:: fmt:: write;
17
18
use std:: fs:: create_dir_all;
18
19
use std:: io:: { Read , Write } ;
19
20
use std:: os:: fd:: { AsFd , AsRawFd } ;
@@ -50,8 +51,7 @@ use ostree_ext::composefs::{
50
51
util:: Sha256Digest ,
51
52
} ;
52
53
use ostree_ext:: composefs_boot:: {
53
- bootloader:: BootEntry as ComposefsBootEntry ,
54
- write_boot:: write_boot_simple as composefs_write_boot_simple, BootOps ,
54
+ bootloader:: BootEntry as ComposefsBootEntry , cmdline:: get_cmdline_composefs, uki, BootOps ,
55
55
} ;
56
56
use ostree_ext:: composefs_oci:: {
57
57
image:: create_filesystem as create_composefs_filesystem, pull as composefs_oci_pull,
@@ -69,8 +69,8 @@ use ostree_ext::{
69
69
use rustix:: fs:: FileTypeExt ;
70
70
use rustix:: fs:: MetadataExt as _;
71
71
use rustix:: path:: Arg ;
72
- use serde:: { Deserialize , Serialize } ;
73
72
use schemars:: JsonSchema ;
73
+ use serde:: { Deserialize , Serialize } ;
74
74
75
75
#[ cfg( feature = "install-to-disk" ) ]
76
76
use self :: baseline:: InstallBlockDeviceOpts ;
@@ -269,7 +269,9 @@ impl TryFrom<&str> for BootType {
269
269
match value {
270
270
"bls" => Ok ( Self :: Bls ) ,
271
271
"uki" => Ok ( Self :: Uki ) ,
272
- unrecognized => Err ( anyhow:: anyhow!( "Unrecognized boot option: '{unrecognized}'" ) ) ,
272
+ unrecognized => Err ( anyhow:: anyhow!(
273
+ "Unrecognized boot option: '{unrecognized}'"
274
+ ) ) ,
273
275
}
274
276
}
275
277
}
@@ -1706,10 +1708,11 @@ pub fn get_esp_partition(device: &str) -> Result<(String, Option<String>)> {
1706
1708
Ok ( ( esp. node , esp. uuid ) )
1707
1709
}
1708
1710
1709
- pub ( crate ) fn get_user_config ( uki_id : & str ) -> String {
1711
+ pub ( crate ) fn get_user_config ( boot_label : & String , uki_id : & str ) -> String {
1712
+ // TODO: Full EFI path here
1710
1713
let s = format ! (
1711
1714
r#"
1712
- menuentry "Fedora Bootc UKI : ({uki_id})" {{
1715
+ menuentry "{boot_label} : ({uki_id})" {{
1713
1716
insmod fat
1714
1717
insmod chain
1715
1718
search --no-floppy --set=root --fs-uuid "${{EFI_PART_UUID}}"
@@ -1779,16 +1782,34 @@ pub(crate) fn setup_composefs_uki_boot(
1779
1782
. args ( [ & PathBuf :: from ( & esp_device) , & mounted_esp. clone ( ) ] )
1780
1783
. run ( ) ?;
1781
1784
1782
- composefs_write_boot_simple (
1783
- & repo,
1784
- entry,
1785
- & id,
1786
- false ,
1787
- & mounted_esp,
1788
- None ,
1789
- Some ( & id. to_hex ( ) ) ,
1790
- & [ ] ,
1791
- ) ?;
1785
+ let boot_label = match entry {
1786
+ ComposefsBootEntry :: Type1 ( ..) => todo ! ( ) ,
1787
+ ComposefsBootEntry :: UsrLibModulesUki ( ..) => todo ! ( ) ,
1788
+ ComposefsBootEntry :: UsrLibModulesVmLinuz ( ..) => todo ! ( ) ,
1789
+
1790
+ ComposefsBootEntry :: Type2 ( type2_entry) => {
1791
+ let uki = read_file ( & type2_entry. file , & repo) . context ( "Reading UKI" ) ?;
1792
+ let cmdline = uki:: get_cmdline ( & uki) . context ( "Getting UKI cmdline" ) ?;
1793
+ let ( composefs_cmdline, _) = get_cmdline_composefs :: < Sha256HashValue > ( cmdline) ?;
1794
+
1795
+ let boot_label = uki:: get_boot_label ( & uki) . context ( "Getting UKI boot label" ) ?;
1796
+
1797
+ if composefs_cmdline != * id {
1798
+ anyhow:: bail!(
1799
+ "The UKI has the wrong composefs= parameter (is '{composefs_cmdline:?}', should be {id:?})"
1800
+ ) ;
1801
+ }
1802
+
1803
+ // Write the UKI to ESP
1804
+ let efi_linux = mounted_esp. join ( "EFI/Linux" ) ;
1805
+ create_dir_all ( & efi_linux) . context ( "Creating EFI/Linux" ) ?;
1806
+
1807
+ let final_uki_path = efi_linux. join ( format ! ( "{}.efi" , id. to_hex( ) ) ) ;
1808
+ std:: fs:: write ( final_uki_path, uki) . context ( "Writing UKI to final path" ) ?;
1809
+
1810
+ boot_label
1811
+ }
1812
+ } ;
1792
1813
1793
1814
Task :: new ( "Unmounting ESP" , "umount" )
1794
1815
. arg ( & mounted_esp)
@@ -1826,7 +1847,7 @@ pub(crate) fn setup_composefs_uki_boot(
1826
1847
. with_context ( || format ! ( "Opening {user_cfg_name}" ) ) ?;
1827
1848
1828
1849
usr_cfg. write_all ( efi_uuid_source. as_bytes ( ) ) ?;
1829
- usr_cfg. write_all ( get_user_config ( & id. to_hex ( ) ) . as_bytes ( ) ) ?;
1850
+ usr_cfg. write_all ( get_user_config ( & boot_label , & id. to_hex ( ) ) . as_bytes ( ) ) ?;
1830
1851
1831
1852
// root_path here will be /sysroot
1832
1853
for entry in std:: fs:: read_dir ( root_path. join ( STATE_DIR_RELATIVE ) ) ? {
@@ -1836,7 +1857,7 @@ pub(crate) fn setup_composefs_uki_boot(
1836
1857
// SAFETY: Deployment file name shouldn't containg non UTF-8 chars
1837
1858
let depl_file_name = depl_file_name. to_string_lossy ( ) ;
1838
1859
1839
- usr_cfg. write_all ( get_user_config ( & depl_file_name) . as_bytes ( ) ) ?;
1860
+ usr_cfg. write_all ( get_user_config ( & boot_label , & depl_file_name) . as_bytes ( ) ) ?;
1840
1861
}
1841
1862
1842
1863
return Ok ( ( ) ) ;
@@ -1868,7 +1889,7 @@ pub(crate) fn setup_composefs_uki_boot(
1868
1889
. with_context ( || format ! ( "Opening {user_cfg_name}" ) ) ?;
1869
1890
1870
1891
usr_cfg. write_all ( efi_uuid_source. as_bytes ( ) ) ?;
1871
- usr_cfg. write_all ( get_user_config ( & id. to_hex ( ) ) . as_bytes ( ) ) ?;
1892
+ usr_cfg. write_all ( get_user_config ( & boot_label , & id. to_hex ( ) ) . as_bytes ( ) ) ?;
1872
1893
1873
1894
Ok ( ( ) )
1874
1895
}
0 commit comments