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

Rework grub2 default static config #841

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ install:
.PHONY: install-grub-static
install-grub-static:
install -m 644 -D -t ${DESTDIR}$(PREFIX)/lib/bootupd/grub2-static src/grub2/*.cfg
install -m 755 -d ${DESTDIR}$(PREFIX)/lib/bootupd/grub2-static/configs.d
install -m 644 -D -t ${DESTDIR}$(PREFIX)/lib/bootupd/grub2-static/configs.d src/grub2/configs.d/*.cfg

.PHONY: install-systemd-unit
install-systemd-unit:
Expand Down
10 changes: 10 additions & 0 deletions src/grub2/configs.d/01_users.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Keep the comment for grub2-set-password
### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
source ${prefix}/user.cfg
if [ -n "${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root ${GRUB2_PASSWORD}
fi
fi
1 change: 1 addition & 0 deletions src/grub2/configs.d/10_blscfg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blscfg
8 changes: 8 additions & 0 deletions src/grub2/configs.d/14_menu_show_once.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Force the menu to be shown once, with a timeout of ${menu_show_once_timeout}
# if requested by ${menu_show_once_timeout} being set in the env.
if [ "${menu_show_once_timeout}" ]; then
set timeout_style=menu
set timeout="${menu_show_once_timeout}"
unset menu_show_once_timeout
save_env menu_show_once_timeout
fi
5 changes: 5 additions & 0 deletions src/grub2/configs.d/30_uefi-firmware.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if [ "$grub_platform" = "efi" ]; then
menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
fwsetup
}
fi
3 changes: 3 additions & 0 deletions src/grub2/configs.d/41_custom.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if [ -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg
fi
17 changes: 0 additions & 17 deletions src/grub2/grub-static-post.cfg

This file was deleted.

21 changes: 5 additions & 16 deletions src/grub2/grub-static-pre.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,13 @@ if [ -f $prefix/console.cfg ]; then
source $prefix/console.cfg
fi

if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
else
menuentry_id_option=""
fi
menuentry_id_option="--id"

function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
insmod all_video
}

set timeout_style=menu
set timeout=1

# Other package code will be injected from here
20 changes: 9 additions & 11 deletions src/grubconfigs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ pub(crate) fn install(
bootdir.create_dir(GRUB2DIR, 0o700)?;
}

let mut config = std::fs::read_to_string(Path::new(CONFIGDIR).join("grub-static-pre.cfg"))?;
let mut config = String::from("# Generated by bootupd / do not edit\n\n");

let pre = std::fs::read_to_string(Path::new(CONFIGDIR).join("grub-static-pre.cfg"))?;
config.push_str(pre.as_str());

let dropindir = openat::Dir::open(&Path::new(CONFIGDIR).join(DROPINDIR))?;
// Sort the files for reproducibility
Expand All @@ -47,16 +50,11 @@ pub(crate) fn install(
log::debug!("Ignoring {name}");
continue;
}
writeln!(config, "source $prefix/{name}")?;
dropindir
.copy_file_at(name, bootdir, format!("{GRUB2DIR}/{name}"))
.with_context(|| format!("Copying {name}"))?;
println!("Installed {name}");
}

{
let post = std::fs::read_to_string(Path::new(CONFIGDIR).join("grub-static-post.cfg"))?;
config.push_str(post.as_str());
writeln!(config, "\n### BEGIN {name} ###")?;
let dropin = std::fs::read_to_string(Path::new(CONFIGDIR).join(DROPINDIR).join(name))?;
config.push_str(dropin.as_str());
writeln!(config, "### END {name} ###")?;
println!("Added {name}");
}

bootdir
Expand Down