From 5b188159a7aa20e5cdee6c69c3eacebe070932cd Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Thu, 16 Apr 2020 21:32:06 +0200 Subject: [PATCH] Make the grub-switch-to-blscfg and 10_linux scripts more robust Signed-off-by: Javier Martinez Canillas --- ...lscfg-Use-install-to-copy-GRUB-binar.patch | 46 +++++++++++++++++++ ...le-BLS-configuration-if-new-kernel-p.patch | 39 ++++++++++++++++ grub.patches | 2 + grub2.spec | 5 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 0208-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch create mode 100644 0209-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch diff --git a/0208-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch b/0208-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch new file mode 100644 index 0000000..c131a7f --- /dev/null +++ b/0208-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 16 Apr 2020 18:53:03 +0200 +Subject: [PATCH] grub-switch-to-blscfg: Use install to copy GRUB binary, + modules and config + +By default the cp command truncates the destination before copying from the +source, so if interrupted it can lead to a file that's half written. + +This behavior can be modified using the --remove-destination option, but is +usually a better choice to use the install tool for this. So let's do that. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 4bbed8e4fe9..3333a620c28 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -273,7 +273,7 @@ copy_bls() { + if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars && \ + ! ${grub_editenv} - list | grep -q blsdir; then + grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" +- cp ${grub_binary} ${grubdir} || exit 1 ++ install -m 700 ${grub_binary} ${grubdir} || exit 1 + # Create a hidden file to indicate that grub2 now has BLS support. + touch /boot/grub2/.grub2-blscfg-supported + fi +@@ -307,13 +307,13 @@ if [ "${GENERATE}" -eq 1 ] ; then + + if [ -n "${mod_dir}" ]; then + for mod in blscfg increment; do +- cp ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 ++ install -m 700 ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 + done + fi + + cp -af "${GRUB_CONFIG_FILE}" "${GRUB_CONFIG_FILE}${backupsuffix}" + if ! grub2-mkconfig -o "${GRUB_CONFIG_FILE}" ; then +- cp -af "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" ++ install -m 700 "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" + sed -i"${backupsuffix}" \ + -e 's,^GRUB_ENABLE_BLSCFG=.*,GRUB_ENABLE_BLSCFG=false,' \ + "${etcdefaultgrub}" diff --git a/0209-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch b/0209-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch new file mode 100644 index 0000000..99c26dd --- /dev/null +++ b/0209-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 16 Apr 2020 18:53:05 +0200 +Subject: [PATCH] 10_linux.in: Enable BLS configuration if new-kernel-pkg isn't + present + +Currently if the the GRUB_ENABLE_BLSCFG option in /etc/default/grub hasn't +been set, the 10_linux script will generate a GRUB configuration that does +not include the blscfg command to populate the menu entries from BLS files. + +But on kernel install the /usr/lib/kernel/install.d/20-grub.install script +will only add menuentry commands to the GRUB config file if the old grubby +tool and new-kernel-pkg script are installed. + +So a configuration with the GRUB_ENABLE_BLSCFG option will lead to a setup +where new kernel entries are not added. Make a BLS config the default if +that option wasn't set and the new-kernel-pkg script is not present. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index c72cc3246bb..847646bd8a8 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -164,6 +164,11 @@ populate_menu() + printf "$menu" + } + ++# Make BLS the default if GRUB_ENABLE_BLSCFG was not set and grubby is not installed. ++if [ -z "${GRUB_ENABLE_BLSCFG}" ] && [ -z "$(which new-kernel-pkg 2> /dev/null)" ]; then ++ GRUB_ENABLE_BLSCFG="true" ++fi ++ + if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + if [ x$dirname = x/ ]; then + if [ -z "${prepare_root_cache}" ]; then diff --git a/grub.patches b/grub.patches index 5a75330..e78e4d7 100644 --- a/grub.patches +++ b/grub.patches @@ -205,3 +205,5 @@ Patch0204: 0204-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch Patch0205: 0205-grub-switch-to-blscfg-Update-grub2-binary-in-ESP-for.patch Patch0206: 0206-grub-switch-to-blscfg-Only-mark-GRUB-as-BLS-supporte.patch Patch0207: 0207-10_linux.in-Merge-logic-from-10_linux_bls-and-drop-t.patch +Patch0208: 0208-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch +Patch0209: 0209-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch diff --git a/grub2.spec b/grub2.spec index 70d10cc..016165c 100644 --- a/grub2.spec +++ b/grub2.spec @@ -9,7 +9,7 @@ Name: grub2 Epoch: 1 Version: 2.04 -Release: 12%{?dist} +Release: 13%{?dist} Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ @@ -504,6 +504,9 @@ rm -r /boot/grub2.tmp/ || : %endif %changelog +* Thu Apr 16 2020 Javier Martinez Canillas - 2.04-13 +- Make the grub-switch-to-blscfg and 10_linux scripts more robust + * Thu Apr 02 2020 Javier Martinez Canillas - 2.04-12 - Merge 10_linux_bls logic into 10_linux and avoid issues if blsdir is set