Skip to content

Commit 20aa19c

Browse files
committed
install/alongside: Match bootloader method by default
Today Anaconda defaults to setting up the bootloader with source == target mode; on x86_64 that means if booted via BIOS the system is installed just with BIOS, and EFI if booted via EFI. Hence, we must match the target boot method only. (TODO: drive down into bootupd something like `backend install --component=auto`) Signed-off-by: Colin Walters <[email protected]>
1 parent b3e35c4 commit 20aa19c

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

lib/src/bootloader.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::os::unix::prelude::PermissionsExt;
2+
use std::path::Path;
23

34
use anyhow::{Context, Result};
45
use 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")]
5566
pub(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
}

lib/src/install.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,12 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
861861
.get_boot_uuid()?
862862
.or(rootfs.rootfs_uuid.as_deref())
863863
.ok_or_else(|| anyhow!("No uuid for boot/root"))?;
864-
crate::bootloader::install_via_bootupd(&rootfs.device, &rootfs.rootfs, boot_uuid)?;
864+
crate::bootloader::install_via_bootupd(
865+
&rootfs.device,
866+
&rootfs.rootfs,
867+
boot_uuid,
868+
rootfs.is_alongside,
869+
)?;
865870
tracing::debug!("Installed bootloader");
866871

867872
// If Ignition is specified, enable it

0 commit comments

Comments
 (0)