Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: support grub2/30_console.cfg for console replacement #1360

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ nav_order: 8

Major changes:

- Support alternative grub2/30_console.cfg location for grub console configuration

Minor changes:

Expand Down
14 changes: 10 additions & 4 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/30_console.cfg, but fallback to grub2/grub.cfg
let mut name = "grub2/30_console.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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very minor but style is usually to use .with_context(|| format!(...)) to avoid string allocation even on non-error paths.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I updated it.. shamefully I know very little about rust, but have been meaning to change that for a long time :(

.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(())
}
Expand Down