@@ -12,6 +12,7 @@ use crate::{
1212 grub_menuconfig:: { parse_grub_menuentry_file, MenuEntry } ,
1313 } ,
1414 spec:: { BootEntry , BootOrder , Host , HostSpec , ImageReference , ImageStatus } ,
15+ utils:: { read_uefi_var, EfiError } ,
1516} ;
1617
1718use std:: str:: FromStr ;
@@ -32,7 +33,6 @@ use crate::composefs_consts::{
3233 COMPOSEFS_STAGED_DEPLOYMENT_FNAME , COMPOSEFS_TRANSIENT_STATE_DIR , ORIGIN_KEY_BOOT ,
3334 ORIGIN_KEY_BOOT_TYPE , STATE_DIR_RELATIVE ,
3435} ;
35- use crate :: install:: EFIVARFS ;
3636use crate :: spec:: Bootloader ;
3737
3838/// A parsed composefs command line
@@ -153,16 +153,9 @@ async fn get_container_manifest_and_config(
153153
154154#[ context( "Getting bootloader" ) ]
155155fn get_bootloader ( ) -> Result < Bootloader > {
156- let efivarfs = match Dir :: open_ambient_dir ( EFIVARFS , ambient_authority ( ) ) {
157- Ok ( dir) => dir,
158- // Most likely using BIOS
159- Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => return Ok ( Bootloader :: Grub ) ,
160- Err ( e) => Err ( e) . context ( format ! ( "Opening {EFIVARFS}" ) ) ?,
161- } ;
162-
163156 const EFI_LOADER_INFO : & str = "LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f" ;
164157
165- match efivarfs . read_to_string ( EFI_LOADER_INFO ) {
158+ match read_uefi_var ( EFI_LOADER_INFO ) {
166159 Ok ( loader) => {
167160 if loader. to_lowercase ( ) . contains ( "systemd-boot" ) {
168161 return Ok ( Bootloader :: Systemd ) ;
@@ -171,9 +164,12 @@ fn get_bootloader() -> Result<Bootloader> {
171164 return Ok ( Bootloader :: Grub ) ;
172165 }
173166
174- Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => return Ok ( Bootloader :: Grub ) ,
167+ Err ( efi_error) => match efi_error {
168+ EfiError :: SystemNotUEFI => return Ok ( Bootloader :: Grub ) ,
169+ EfiError :: MissingVar => return Ok ( Bootloader :: Grub ) ,
175170
176- Err ( e) => Err ( e) . context ( format ! ( "Opening {EFI_LOADER_INFO}" ) ) ?,
171+ e => return Err ( anyhow:: anyhow!( "Failed to read EfiLoaderInfo: {e:?}" ) ) ,
172+ } ,
177173 }
178174}
179175
0 commit comments