@@ -51,7 +51,7 @@ use crate::install::{RootSetup, State};
5151/// Contains the EFP's filesystem UUID. Used by grub
5252pub ( crate ) const EFI_UUID_FILE : & str = "efiuuid.cfg" ;
5353/// The EFI Linux directory
54- const EFI_LINUX : & str = "EFI/Linux" ;
54+ pub ( crate ) const EFI_LINUX : & str = "EFI/Linux" ;
5555
5656/// Timeout for systemd-boot bootloader menu
5757const SYSTEMD_TIMEOUT : & str = "timeout 5" ;
126126 )
127127}
128128
129+ /// Returns `true` if detect the target rootfs carries a UKI.
130+ pub ( crate ) fn container_root_has_uki ( root : & Dir ) -> Result < bool > {
131+ let Some ( boot) = root. open_dir_optional ( crate :: install:: BOOT ) ? else {
132+ return Ok ( false ) ;
133+ } ;
134+ let Some ( efi_linux) = boot. open_dir_optional ( EFI_LINUX ) ? else {
135+ return Ok ( false ) ;
136+ } ;
137+ for entry in efi_linux. entries ( ) ? {
138+ let entry = entry?;
139+ let name = entry. file_name ( ) ;
140+ let name = Path :: new ( & name) ;
141+ let extension = name. extension ( ) . and_then ( |v| v. to_str ( ) ) ;
142+ if extension == Some ( "efi" ) {
143+ return Ok ( true ) ;
144+ }
145+ }
146+ Ok ( false )
147+ }
148+
129149pub fn get_esp_partition ( device : & str ) -> Result < ( String , Option < String > ) > {
130150 let device_info = bootc_blockdev:: partitions_of ( Utf8Path :: new ( device) ) ?;
131151 let esp = device_info
@@ -372,11 +392,7 @@ pub(crate) fn setup_composefs_bls_boot(
372392 esp_part. node . clone ( ) ,
373393 cmdline_options,
374394 fs,
375- state
376- . composefs_options
377- . as_ref ( )
378- . map ( |opts| opts. bootloader . clone ( ) )
379- . unwrap_or ( Bootloader :: default ( ) ) ,
395+ state. detected_bootloader . clone ( ) ,
380396 )
381397 }
382398
@@ -839,7 +855,7 @@ pub(crate) fn setup_composefs_uki_boot(
839855 (
840856 root_setup. physical_root_path . clone ( ) ,
841857 esp_part. node . clone ( ) ,
842- cfs_opts . bootloader . clone ( ) ,
858+ state . detected_bootloader . clone ( ) ,
843859 cfs_opts. insecure ,
844860 cfs_opts. uki_addon . as_ref ( ) ,
845861 )
@@ -944,13 +960,20 @@ pub(crate) fn setup_composefs_boot(
944960 if cfg ! ( target_arch = "s390x" ) {
945961 // TODO: Integrate s390x support into install_via_bootupd
946962 crate :: bootloader:: install_via_zipl ( & root_setup. device_info , boot_uuid) ?;
947- } else {
963+ } else if state . detected_bootloader == Bootloader :: Grub {
948964 crate :: bootloader:: install_via_bootupd (
949965 & root_setup. device_info ,
950966 & root_setup. physical_root_path ,
951967 & state. config_opts ,
952968 None ,
953969 ) ?;
970+ } else {
971+ crate :: bootloader:: install_systemd_boot (
972+ & root_setup. device_info ,
973+ & root_setup. physical_root_path ,
974+ & state. config_opts ,
975+ None ,
976+ ) ?;
954977 }
955978
956979 let repo = open_composefs_repo ( & root_setup. physical_root ) ?;
@@ -1001,3 +1024,34 @@ pub(crate) fn setup_composefs_boot(
10011024
10021025 Ok ( ( ) )
10031026}
1027+
1028+ #[ cfg( test) ]
1029+ mod tests {
1030+ use super :: * ;
1031+ use cap_std_ext:: cap_std;
1032+
1033+ #[ test]
1034+ fn test_root_has_uki ( ) -> Result < ( ) > {
1035+ // Test case 1: No boot directory
1036+ let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
1037+ assert_eq ! ( container_root_has_uki( & tempdir) ?, false ) ;
1038+
1039+ // Test case 2: boot directory exists but no EFI/Linux
1040+ tempdir. create_dir ( crate :: install:: BOOT ) ?;
1041+ assert_eq ! ( container_root_has_uki( & tempdir) ?, false ) ;
1042+
1043+ // Test case 3: boot/EFI/Linux exists but no .efi files
1044+ tempdir. create_dir_all ( "boot/EFI/Linux" ) ?;
1045+ assert_eq ! ( container_root_has_uki( & tempdir) ?, false ) ;
1046+
1047+ // Test case 4: boot/EFI/Linux exists with non-.efi file
1048+ tempdir. atomic_write ( "boot/EFI/Linux/readme.txt" , b"some file" ) ?;
1049+ assert_eq ! ( container_root_has_uki( & tempdir) ?, false ) ;
1050+
1051+ // Test case 5: boot/EFI/Linux exists with .efi file
1052+ tempdir. atomic_write ( "boot/EFI/Linux/bootx64.efi" , b"fake efi binary" ) ?;
1053+ assert_eq ! ( container_root_has_uki( & tempdir) ?, true ) ;
1054+
1055+ Ok ( ( ) )
1056+ }
1057+ }
0 commit comments