Skip to content

Commit 7c16f46

Browse files
authored
Merge pull request #155 from cgwalters/install-efi-opt-if-bios
install: Don't require EFI if booted via BIOS and doing alongside
2 parents 3baecf4 + 20aa19c commit 7c16f46

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ pub(crate) struct RootSetup {
637637
rootfs: Utf8PathBuf,
638638
rootfs_fd: Dir,
639639
rootfs_uuid: Option<String>,
640-
/// If true, do not try to remount the root read-only and flush the journal, etc.
641-
skip_finalize: bool,
640+
/// True if this is an "alongside" install where we didn't create the filesystem
641+
is_alongside: bool,
642642
boot: Option<MountSpec>,
643643
kargs: Vec<String>,
644644
}
@@ -866,7 +866,12 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
866866
.get_boot_uuid()?
867867
.or(rootfs.rootfs_uuid.as_deref())
868868
.ok_or_else(|| anyhow!("No uuid for boot/root"))?;
869-
crate::bootloader::install_via_bootupd(&rootfs.device, &rootfs.rootfs, boot_uuid)?;
869+
crate::bootloader::install_via_bootupd(
870+
&rootfs.device,
871+
&rootfs.rootfs,
872+
boot_uuid,
873+
rootfs.is_alongside,
874+
)?;
870875
tracing::debug!("Installed bootloader");
871876

872877
// If Ignition is specified, enable it
@@ -887,7 +892,7 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
887892
.run()?;
888893

889894
// Finalize mounted filesystems
890-
if !rootfs.skip_finalize {
895+
if !rootfs.is_alongside {
891896
let bootfs = rootfs.rootfs.join("boot");
892897
for fs in [bootfs.as_path(), rootfs.rootfs.as_path()] {
893898
finalize_filesystem(fs)?;
@@ -1117,7 +1122,7 @@ pub(crate) async fn install_to_filesystem(opts: InstallToFilesystemOpts) -> Resu
11171122
rootfs_uuid: inspect.uuid.clone(),
11181123
boot,
11191124
kargs,
1120-
skip_finalize: matches!(fsopts.replace, Some(ReplaceMode::Alongside)),
1125+
is_alongside: matches!(fsopts.replace, Some(ReplaceMode::Alongside)),
11211126
};
11221127

11231128
install_to_filesystem_impl(&state, &mut rootfs).await?;

lib/src/install/baseline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,6 @@ pub(crate) fn install_create_rootfs(
387387
rootfs_uuid: Some(root_uuid.to_string()),
388388
boot: Some(boot),
389389
kargs,
390-
skip_finalize: false,
390+
is_alongside: false,
391391
})
392392
}

0 commit comments

Comments
 (0)