1
1
use std:: os:: unix:: prelude:: PermissionsExt ;
2
+ use std:: path:: Path ;
2
3
3
4
use anyhow:: { Context , Result } ;
4
5
use camino:: Utf8Path ;
@@ -51,20 +52,51 @@ fn install_grub2_efi(efidir: &Dir, uuid: &str) -> Result<()> {
51
52
Ok ( ( ) )
52
53
}
53
54
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
+
54
65
#[ context( "Installing bootloader" ) ]
55
66
pub ( crate ) fn install_via_bootupd (
56
67
device : & Utf8Path ,
57
68
rootfs : & Utf8Path ,
58
69
boot_uuid : & str ,
70
+ is_alongside : bool ,
59
71
) -> Result < ( ) > {
60
72
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
+ ] ) ;
68
100
Task :: new_and_run ( "Running bootupctl to install bootloader" , "bootupctl" , args) ?;
69
101
70
102
let grub2_uuid_contents = format ! ( "set BOOT_UUID=\" {boot_uuid}\" \n " ) ;
@@ -73,7 +105,7 @@ pub(crate) fn install_via_bootupd(
73
105
let bootfs =
74
106
Dir :: open_ambient_dir ( bootfs, cap_std:: ambient_authority ( ) ) . context ( "Opening boot" ) ?;
75
107
76
- if super :: install:: ARCH_USES_EFI {
108
+ if super :: install:: ARCH_USES_EFI && install_efi {
77
109
let efidir = bootfs. open_dir ( "efi" ) . context ( "Opening efi" ) ?;
78
110
install_grub2_efi ( & efidir, & grub2_uuid_contents) ?;
79
111
}
0 commit comments