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