dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0238-Only-set-kernelopts-in-grubenv-if-it-wasn-t-set-befo.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Javier Martinez Canillas <javierm@redhat.com>
d9d99f
Date: Fri, 5 Oct 2018 16:29:47 +0200
d9d99f
Subject: [PATCH] Only set kernelopts in grubenv if it wasn't set before
d9d99f
d9d99f
Users may want to use a different command line parameters, so if there's
d9d99f
a kernelopts var set in grubenv, grub2-mkconfig shouldn't reset it.
d9d99f
d9d99f
While being there, print a warning so users know that they shouldn't edit
d9d99f
the grub config file and instead edit the BootLoaderSpec config files.
d9d99f
d9d99f
Resolves: rhbz#1636466
d9d99f
d9d99f
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
d9d99f
---
d9d99f
 util/grub.d/10_linux.in     | 20 +++++++++++++++++++-
d9d99f
 util/grub.d/10_linux_bls.in |  4 +++-
d9d99f
 2 files changed, 22 insertions(+), 2 deletions(-)
d9d99f
d9d99f
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
d9d99f
index 9682e97b7f5..01e66e5fc74 100644
d9d99f
--- a/util/grub.d/10_linux.in
d9d99f
+++ b/util/grub.d/10_linux.in
d9d99f
@@ -82,6 +82,20 @@ case x"$GRUB_FS" in
d9d99f
 	;;
d9d99f
 esac
d9d99f
 
d9d99f
+populate_header_warn()
d9d99f
+{
d9d99f
+cat <
d9d99f
+
d9d99f
+# This section was generated by a script. Do not modify the generated file - all changes
d9d99f
+# will be lost the next time file is regenerated. Instead edit the BootLoaderSpec files.
d9d99f
+#
d9d99f
+# The blscfg command parses the BootLoaderSpec files stored in /boot/loader/entries and
d9d99f
+# populates the boot menu. Please refer to the Boot Loader Specification documentation
d9d99f
+# for the files format: https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/.
d9d99f
+
d9d99f
+EOF
d9d99f
+}
d9d99f
+
d9d99f
 mktitle ()
d9d99f
 {
d9d99f
   local title_type
d9d99f
@@ -141,6 +155,8 @@ linux_entry ()
d9d99f
         prepare_grub_to_access_device ${boot_device} boot
d9d99f
     fi
d9d99f
 
d9d99f
+    populate_header_warn
d9d99f
+
d9d99f
     cat << EOF
d9d99f
 insmod blscfg
d9d99f
 blscfg
d9d99f
@@ -150,7 +166,9 @@ fi
d9d99f
 EOF
d9d99f
 
d9d99f
     ${grub_editenv} - set saved_entry=0
d9d99f
-    ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
d9d99f
+    if ! grub2-editenv - list | grep -q kernelopts; then
d9d99f
+	${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
d9d99f
+    fi
d9d99f
 
d9d99f
     exit 0
d9d99f
   fi
d9d99f
diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in
d9d99f
index 3cc7803c6a1..8a3379578bd 100644
d9d99f
--- a/util/grub.d/10_linux_bls.in
d9d99f
+++ b/util/grub.d/10_linux_bls.in
d9d99f
@@ -201,7 +201,9 @@ linux_entry ()
d9d99f
     populate_menu
d9d99f
 
d9d99f
     ${grub_editenv} - set saved_entry=0
d9d99f
-    ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
d9d99f
+    if ! grub2-editenv - list | grep -q kernelopts; then
d9d99f
+	${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
d9d99f
+    fi
d9d99f
 
d9d99f
     exit 0
d9d99f
   fi