11use std:: os:: unix:: prelude:: PermissionsExt ;
2+ use std:: path:: Path ;
23
34use anyhow:: { Context , Result } ;
45use camino:: Utf8Path ;
@@ -51,20 +52,51 @@ fn install_grub2_efi(efidir: &Dir, uuid: &str) -> Result<()> {
5152 Ok ( ( ) )
5253}
5354
55+ /// Return `true` if the system is booted via EFI
56+ pub ( crate ) fn is_efi_booted ( ) -> Result < bool > {
57+ if !super :: install:: ARCH_USES_EFI {
58+ return Ok ( false ) ;
59+ }
60+ Path :: new ( "/sys/firmware/efi" )
61+ . try_exists ( )
62+ . map_err ( Into :: into)
63+ }
64+
5465#[ context( "Installing bootloader" ) ]
5566pub ( crate ) fn install_via_bootupd (
5667 device : & Utf8Path ,
5768 rootfs : & Utf8Path ,
5869 boot_uuid : & str ,
70+ is_alongside : bool ,
5971) -> Result < ( ) > {
6072 let verbose = std:: env:: var_os ( "BOOTC_BOOTLOADER_DEBUG" ) . map ( |_| "-vvvv" ) ;
61- let args = [ "backend" , "install" ] . into_iter ( ) . chain ( verbose) . chain ( [
62- "--src-root" ,
63- "/" ,
64- "--device" ,
65- device. as_str ( ) ,
66- rootfs. as_str ( ) ,
67- ] ) ;
73+ // If we're doing an alongside install, only match the boot method because Anaconda defaults
74+ // to only doing that. This is only on x86_64 because that's the only arch that has multiple
75+ // components right now.
76+ // TODO: Add --component=auto which moves this logic into bootupd
77+ let ( install_efi, component_args) = if cfg ! ( target_arch = "x86_64" ) && is_alongside {
78+ assert ! ( super :: install:: ARCH_USES_EFI ) ;
79+ let install_efi = is_efi_booted ( ) ?;
80+ let component_arg = if install_efi {
81+ "--component=EFI"
82+ } else {
83+ "--component=BIOS"
84+ } ;
85+ ( install_efi, Some ( component_arg) )
86+ } else {
87+ ( super :: install:: ARCH_USES_EFI , None )
88+ } ;
89+ let args = [ "backend" , "install" ]
90+ . into_iter ( )
91+ . chain ( verbose)
92+ . chain ( component_args)
93+ . chain ( [
94+ "--src-root" ,
95+ "/" ,
96+ "--device" ,
97+ device. as_str ( ) ,
98+ rootfs. as_str ( ) ,
99+ ] ) ;
68100 Task :: new_and_run ( "Running bootupctl to install bootloader" , "bootupctl" , args) ?;
69101
70102 let grub2_uuid_contents = format ! ( "set BOOT_UUID=\" {boot_uuid}\" \n " ) ;
@@ -73,7 +105,7 @@ pub(crate) fn install_via_bootupd(
73105 let bootfs =
74106 Dir :: open_ambient_dir ( bootfs, cap_std:: ambient_authority ( ) ) . context ( "Opening boot" ) ?;
75107
76- if super :: install:: ARCH_USES_EFI {
108+ if super :: install:: ARCH_USES_EFI && install_efi {
77109 let efidir = bootfs. open_dir ( "efi" ) . context ( "Opening efi" ) ?;
78110 install_grub2_efi ( & efidir, & grub2_uuid_contents) ?;
79111 }
0 commit comments