Skip to content

Commit 5982e19

Browse files
committed
efi: install grub.cfg under new vendor during updates
When doing switches from RHEL 10 to Fedora 43, after reboot, check grub.cfg and bootuuid.cfg are in old vendor redhat, that will make the machine fails to boot a second time since grub.cfg cannot be found. We need to install the 2 files under new vendor during updates. See #1024
1 parent 17f4ec7 commit 5982e19

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/efi.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,42 @@ impl Component for Efi {
481481
anyhow::bail!("Failed to find all esp devices");
482482
};
483483

484+
// Get old vendor name from installed filetree
485+
let old_vendor = {
486+
let mut vendor = "";
487+
for child in currentf.children.keys() {
488+
if child.ends_with(SHIM) {
489+
vendor = child.strip_suffix(&format!("/{SHIM}")).unwrap_or("");
490+
break;
491+
}
492+
}
493+
vendor.to_owned()
494+
};
495+
484496
for esp in esp_devices {
485497
let destpath = &self.ensure_mounted_esp(rootcxt.path.as_ref(), Path::new(&esp))?;
486-
let destdir = openat::Dir::open(&destpath.join("EFI")).context("opening EFI dir")?;
498+
let dest_efi = destpath.join("EFI");
499+
let destdir = openat::Dir::open(&dest_efi).context("opening EFI dir")?;
487500
validate_esp_fstype(&destdir)?;
501+
488502
log::trace!("applying diff: {}", &diff);
489503
filetree::apply_diff(&updated, &destdir, &diff, None)
490504
.context("applying filesystem changes")?;
491505

506+
// Install grub.cfg under new vendor
507+
{
508+
// Get new vendor name
509+
let sysroot = rootcxt.path.as_std_path();
510+
let Some(new_vendor) = self.get_efi_vendor(&sysroot.join(&updated_path))? else {
511+
anyhow::bail!("Failed to find efi vendor in new update");
512+
};
513+
if new_vendor != old_vendor && destdir.exists(&old_vendor)? {
514+
grubconfigs::install(sysroot_dir, None, Some(&new_vendor), true)?;
515+
destdir.remove_all(&old_vendor)?;
516+
assert!(destdir.exists(format!("{new_vendor}/{}", grubconfigs::GRUBCONFIG))?);
517+
}
518+
}
519+
492520
// Do the sync before unmount
493521
fsfreeze_thaw_cycle(destdir.open_file(".")?)?;
494522
drop(destdir);
@@ -609,7 +637,7 @@ impl Component for Efi {
609637

610638
// Does not support multiple shim for efi
611639
if shim_files.len() > 1 {
612-
anyhow::bail!("Found multiple {SHIM} in the image");
640+
anyhow::bail!("Found multiple {SHIM} in the image: {:?}", shim_files);
613641
}
614642
if let Some(p) = shim_files.first() {
615643
let p = p

0 commit comments

Comments
 (0)