Skip to content

Commit

Permalink
bootloader: Use bootupd --with-static-configs
Browse files Browse the repository at this point in the history
This depends on the new bootupd 0.2.12; we drop the static
grub configs out of this project.
  • Loading branch information
cgwalters committed Oct 23, 2023
1 parent d87aff8 commit ba18566
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 172 deletions.
64 changes: 5 additions & 59 deletions lib/src/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use camino::Utf8Path;
use cap_std::fs::Dir;
use cap_std::fs::Permissions;
use cap_std_ext::cap_std;
use cap_std_ext::cap_std::fs::DirBuilder;
use cap_std_ext::prelude::*;
use fn_error_context::context;

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

#[context("Installing grub2 EFI")]
fn install_grub2_efi(efidir: &Dir, uuid: &str) -> Result<()> {
let mut vendordir = None;
let efidir = efidir.open_dir("EFI").context("Opening EFI/")?;
for child in efidir.entries()? {
let child = child?;
let name = child.file_name();
let name = if let Some(name) = name.to_str() {
name
} else {
continue;
};
if name == "BOOT" {
continue;
}
if !child.file_type()?.is_dir() {
continue;
}
vendordir = Some(child.open_dir()?);
break;
}
let vendordir = vendordir.ok_or_else(|| anyhow::anyhow!("Failed to find EFI vendor dir"))?;
vendordir
.atomic_write("grub.cfg", STATIC_GRUB_CFG_EFI)
.context("Writing static EFI grub.cfg")?;
vendordir
.atomic_write(GRUB_BOOT_UUID_FILE, uuid)
.with_context(|| format!("Writing {GRUB_BOOT_UUID_FILE}"))?;

Ok(())
}

/// Return `true` if the system is booted via EFI
pub(crate) fn is_efi_booted() -> Result<bool> {
if !super::install::ARCH_USES_EFI {
Expand All @@ -74,19 +39,19 @@ pub(crate) fn install_via_bootupd(
// to only doing that. This is only on x86_64 because that's the only arch that has multiple
// components right now.
// TODO: Add --component=auto which moves this logic into bootupd
let (install_efi, component_args) = if cfg!(target_arch = "x86_64") && is_alongside {
let component_args = if cfg!(target_arch = "x86_64") && is_alongside {
assert!(super::install::ARCH_USES_EFI);
let install_efi = is_efi_booted()?;
let component_arg = if install_efi {
"--component=EFI"
} else {
"--component=BIOS"
};
(install_efi, Some(component_arg))
Some(component_arg)
} else {
(super::install::ARCH_USES_EFI, None)
None
};
let args = ["backend", "install"]
let args = ["backend", "install", "--with-static-configs"]
.into_iter()
.chain(verbose)
.chain(component_args)
Expand All @@ -104,26 +69,7 @@ pub(crate) fn install_via_bootupd(
let bootfs = &rootfs.join("boot");
let bootfs =
Dir::open_ambient_dir(bootfs, cap_std::ambient_authority()).context("Opening boot")?;

if super::install::ARCH_USES_EFI && install_efi {
let efidir = bootfs.open_dir("efi").context("Opening efi")?;
install_grub2_efi(&efidir, &grub2_uuid_contents)?;
}

bootfs
.ensure_dir_with("grub2", &DirBuilder::new())
.context("Creating boot/grub2")?;
let grub2 = bootfs.open_dir("grub2")?;

// Mode 0700 to support passwords etc.
grub2.set_permissions(".", Permissions::from_mode(0o700))?;
grub2
.atomic_write_with_perms(
"grub.cfg",
STATIC_GRUB_CFG,
cap_std::fs::Permissions::from_mode(0o600),
)
.context("Writing grub.cfg")?;
let grub2 = bootfs.open_dir("grub2").context("Opening boot/grub2")?;

grub2
.atomic_write_with_perms(
Expand Down
18 changes: 0 additions & 18 deletions lib/src/grub-efi.cfg

This file was deleted.

95 changes: 0 additions & 95 deletions lib/src/grub.cfg

This file was deleted.

0 comments on commit ba18566

Please sign in to comment.