Skip to content

Commit f867a2d

Browse files
committed
bootloader: Use bootupd --with-static-configs
This depends on the new bootupd 0.2.12; we drop the static grub configs out of this project. Signed-off-by: Colin Walters <[email protected]>
1 parent d87aff8 commit f867a2d

File tree

3 files changed

+5
-172
lines changed

3 files changed

+5
-172
lines changed

lib/src/bootloader.rs

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use camino::Utf8Path;
66
use cap_std::fs::Dir;
77
use cap_std::fs::Permissions;
88
use cap_std_ext::cap_std;
9-
use cap_std_ext::cap_std::fs::DirBuilder;
109
use cap_std_ext::prelude::*;
1110
use fn_error_context::context;
1211

@@ -15,43 +14,9 @@ use crate::task::Task;
1514
/// This variable is referenced by our GRUB fragment
1615
pub(crate) const IGNITION_VARIABLE: &str = "$ignition_firstboot";
1716
const GRUB_BOOT_UUID_FILE: &str = "bootuuid.cfg";
18-
const STATIC_GRUB_CFG: &str = include_str!("grub.cfg");
19-
const STATIC_GRUB_CFG_EFI: &str = include_str!("grub-efi.cfg");
2017
/// The name of the mountpoint for efi (as a subdirectory of /boot, or at the toplevel)
2118
pub(crate) const EFI_DIR: &str = "efi";
2219

23-
#[context("Installing grub2 EFI")]
24-
fn install_grub2_efi(efidir: &Dir, uuid: &str) -> Result<()> {
25-
let mut vendordir = None;
26-
let efidir = efidir.open_dir("EFI").context("Opening EFI/")?;
27-
for child in efidir.entries()? {
28-
let child = child?;
29-
let name = child.file_name();
30-
let name = if let Some(name) = name.to_str() {
31-
name
32-
} else {
33-
continue;
34-
};
35-
if name == "BOOT" {
36-
continue;
37-
}
38-
if !child.file_type()?.is_dir() {
39-
continue;
40-
}
41-
vendordir = Some(child.open_dir()?);
42-
break;
43-
}
44-
let vendordir = vendordir.ok_or_else(|| anyhow::anyhow!("Failed to find EFI vendor dir"))?;
45-
vendordir
46-
.atomic_write("grub.cfg", STATIC_GRUB_CFG_EFI)
47-
.context("Writing static EFI grub.cfg")?;
48-
vendordir
49-
.atomic_write(GRUB_BOOT_UUID_FILE, uuid)
50-
.with_context(|| format!("Writing {GRUB_BOOT_UUID_FILE}"))?;
51-
52-
Ok(())
53-
}
54-
5520
/// Return `true` if the system is booted via EFI
5621
pub(crate) fn is_efi_booted() -> Result<bool> {
5722
if !super::install::ARCH_USES_EFI {
@@ -74,19 +39,19 @@ pub(crate) fn install_via_bootupd(
7439
// to only doing that. This is only on x86_64 because that's the only arch that has multiple
7540
// components right now.
7641
// TODO: Add --component=auto which moves this logic into bootupd
77-
let (install_efi, component_args) = if cfg!(target_arch = "x86_64") && is_alongside {
42+
let component_args = if cfg!(target_arch = "x86_64") && is_alongside {
7843
assert!(super::install::ARCH_USES_EFI);
7944
let install_efi = is_efi_booted()?;
8045
let component_arg = if install_efi {
8146
"--component=EFI"
8247
} else {
8348
"--component=BIOS"
8449
};
85-
(install_efi, Some(component_arg))
50+
Some(component_arg)
8651
} else {
87-
(super::install::ARCH_USES_EFI, None)
52+
None
8853
};
89-
let args = ["backend", "install"]
54+
let args = ["backend", "install", "--with-static-configs"]
9055
.into_iter()
9156
.chain(verbose)
9257
.chain(component_args)
@@ -104,26 +69,7 @@ pub(crate) fn install_via_bootupd(
10469
let bootfs = &rootfs.join("boot");
10570
let bootfs =
10671
Dir::open_ambient_dir(bootfs, cap_std::ambient_authority()).context("Opening boot")?;
107-
108-
if super::install::ARCH_USES_EFI && install_efi {
109-
let efidir = bootfs.open_dir("efi").context("Opening efi")?;
110-
install_grub2_efi(&efidir, &grub2_uuid_contents)?;
111-
}
112-
113-
bootfs
114-
.ensure_dir_with("grub2", &DirBuilder::new())
115-
.context("Creating boot/grub2")?;
116-
let grub2 = bootfs.open_dir("grub2")?;
117-
118-
// Mode 0700 to support passwords etc.
119-
grub2.set_permissions(".", Permissions::from_mode(0o700))?;
120-
grub2
121-
.atomic_write_with_perms(
122-
"grub.cfg",
123-
STATIC_GRUB_CFG,
124-
cap_std::fs::Permissions::from_mode(0o600),
125-
)
126-
.context("Writing grub.cfg")?;
72+
let grub2 = bootfs.open_dir("grub2").context("Opening boot/grub2")?;
12773

12874
grub2
12975
.atomic_write_with_perms(

lib/src/grub-efi.cfg

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/src/grub.cfg

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)