From 5d31c0629c2424f0db8b2d685e087ab21b64aa74 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Thu, 14 Dec 2023 23:40:26 -0500 Subject: [PATCH] install: support grub2/50_coreos.cfg for console replacement Upstream we are starting to use grub configs that are partially baked into bootupd [1] and partially baked into the image via the OS vendor (in our case a grub2/50_coreos.cfg file [2]). Let's look first to see if grub2/50_coreos.cfg exists when trying to write new console settings before falling back to grub2/grub.cfg. [1] https://github.com/coreos/bootupd/pull/543 [2] https://github.com/coreos/fedora-coreos-config/pull/2769 --- docs/release-notes.md | 1 + src/install.rs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index e6398ae24..fc6c79b24 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -8,6 +8,7 @@ nav_order: 8 Major changes: +- Support alternative grub2/50_coreos.cfg location for grub console configuration Minor changes: diff --git a/src/install.rs b/src/install.rs index c2a8cc56b..0429eeffc 100644 --- a/src/install.rs +++ b/src/install.rs @@ -636,11 +636,17 @@ fn write_console(mountpoint: &Path, platform: Option<&str>, consoles: &[Console] // set grub commands if grub_commands != metal_spec.grub_commands { - let path = mountpoint.join("grub2/grub.cfg"); - let grub_cfg = fs::read_to_string(&path).context("reading grub.cfg")?; + // prefer the new grub2/50_coreos.cfg, but fallback to grub2/grub.cfg + let mut name = "grub2/50_coreos.cfg"; + let mut path = mountpoint.join(name); + if !path.exists() { + name = "grub2/grub.cfg"; + path = mountpoint.join(name); + } + let grub_cfg = fs::read_to_string(&path).with_context(|| format!("reading {}", name))?; let new_grub_cfg = update_grub_cfg_console_settings(&grub_cfg, &grub_commands) - .context("updating grub.cfg")?; - fs::write(&path, new_grub_cfg).context("writing grub.cfg")?; + .with_context(|| format!("updating {}", name))?; + fs::write(&path, new_grub_cfg).with_context(|| format!("writing {}", name))?; } Ok(()) }