-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for installing static grub configs
Currently these are duplicated in osbuild and coreos-assembler. We will aim to deduplicate them here. Ideally we'd add support for "day 2" updates of these; I started on a patch for that but it's sadly messy. This is an incremental improvement.
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::{ | ||
os::unix::prelude::OsStrExt, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use anyhow::{Context, Result}; | ||
use openat_ext::OpenatDirExt; | ||
|
||
const CONFIGDIR: &str = "/usr/lib/bootupd/grub2-static"; | ||
|
||
pub(crate) fn find_efi_vendordir(efidir: &openat::Dir) -> Result<PathBuf> { | ||
for d in efidir.list_self()? { | ||
let d = d?; | ||
if d.file_name().as_bytes() == b"BOOT" { | ||
continue; | ||
} | ||
let meta = efidir.metadata(d.file_name())?; | ||
if !meta.is_dir() { | ||
continue; | ||
} | ||
return Ok(d.file_name().into()); | ||
} | ||
anyhow::bail!("Failed to find EFI vendor dir") | ||
} | ||
|
||
/// Install the static GRUB config files. | ||
pub(crate) fn install(target_root: &openat::Dir, efi: bool) -> Result<()> { | ||
let bootdir = &target_root.sub_dir("boot").context("Opening /boot")?; | ||
|
||
bootdir | ||
.copy_file(&Path::new(CONFIGDIR).join("grub-static.cfg"), "grub.cfg") | ||
.context("Copying grub-static.cfg")?; | ||
println!("Installed: grub.cfg"); | ||
|
||
let efidir = efi | ||
.then(|| { | ||
target_root | ||
.sub_dir_optional("boot/efi") | ||
.context("Opening /boot/efi") | ||
}) | ||
.transpose()? | ||
.flatten(); | ||
if let Some(efidir) = efidir.as_ref() { | ||
let vendordir = find_efi_vendordir(efidir)?; | ||
let target = &vendordir.join("grub.cfg"); | ||
efidir.copy_file(&Path::new(CONFIGDIR).join("grub-static-efi.cfg"), target)?; | ||
println!("Installed: {target:?}"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters