From 12f9ae70bd2edd204c29f80ef9189a3a1c5ca6ac Mon Sep 17 00:00:00 2001 From: HuijingHei Date: Wed, 4 Dec 2024 15:52:34 +0800 Subject: [PATCH] bios.rs: detect when payload is missing `grub2-modules` Fixes https://github.com/coreos/bootupd/issues/787 --- src/bios.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/bios.rs b/src/bios.rs index 96d00741..1604c59a 100644 --- a/src/bios.rs +++ b/src/bios.rs @@ -62,8 +62,27 @@ impl Bios { Ok(device) } + // Return `true` if grub2-modules installed + fn check_grub_modules(&self) -> Result { + let usr_path = Path::new("/usr/lib/grub"); + #[cfg(target_arch = "x86_64")] + { + usr_path.join("i386-pc").try_exists().map_err(Into::into) + } + #[cfg(target_arch = "powerpc64")] + { + usr_path + .join("powerpc-ieee1275") + .try_exists() + .map_err(Into::into) + } + } + // Run grub2-install fn run_grub_install(&self, dest_root: &str, device: &str) -> Result<()> { + if !self.check_grub_modules()? { + bail!("Failed to find grub2-modules"); + } let grub_install = Path::new("/").join(GRUB_BIN); if !grub_install.exists() { bail!("Failed to find {:?}", grub_install);