4ff5f8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
4ff5f8
From: Javier Martinez Canillas <javierm@redhat.com>
4ff5f8
Date: Mon, 10 Dec 2018 13:11:58 +0100
4ff5f8
Subject: [PATCH] Make grub2-mkconfig to honour GRUB_CMDLINE_LINUX in
4ff5f8
 /etc/default/grub
4ff5f8
4ff5f8
The kernelopts grub environment variable is set with the GRUB_CMDLINE_LINUX
4ff5f8
value only if wasn't set before. This is because the kernel cmdline params
4ff5f8
of the entries are not in the grub.cfg anymore so grub2-mkconfig shouldn't
4ff5f8
have side effects on neither the entries nor their kernel cmdline params.
4ff5f8
4ff5f8
But there's a lot of documentation pointing at modifying GRUB_CMDLINE_LINUX
4ff5f8
to change the kernel cmdline params and users have built a muscle memory on
4ff5f8
it, so the BLS support should be compatible.
4ff5f8
4ff5f8
Make the grub2-mkconfig script update the $kernelopts environment variable
4ff5f8
unless the --no-grubenv-update option is used.
4ff5f8
4ff5f8
Resolves: rhbz#1637875
4ff5f8
4ff5f8
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
4ff5f8
---
4ff5f8
 util/grub-mkconfig.8        | 4 ++++
4ff5f8
 util/grub-mkconfig.in       | 6 ++++++
4ff5f8
 util/grub.d/10_linux.in     | 2 +-
4ff5f8
 util/grub.d/10_linux_bls.in | 2 +-
4ff5f8
 4 files changed, 12 insertions(+), 2 deletions(-)
4ff5f8
4ff5f8
diff --git a/util/grub-mkconfig.8 b/util/grub-mkconfig.8
4ff5f8
index a2d1f577b9b..434fa4deda4 100644
4ff5f8
--- a/util/grub-mkconfig.8
4ff5f8
+++ b/util/grub-mkconfig.8
4ff5f8
@@ -13,5 +13,9 @@
4ff5f8
 \fB--output\fR=\fIFILE\fR
4ff5f8
 Write generated output to \fIFILE\fR.
4ff5f8
 
4ff5f8
+.TP
4ff5f8
+\fB--no-grubenv-update\fR
4ff5f8
+Do not update variables in the grubenv file.
4ff5f8
+
4ff5f8
 .SH SEE ALSO
4ff5f8
 .BR "info grub"
4ff5f8
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
4ff5f8
index c20171919d9..5e643e16973 100644
4ff5f8
--- a/util/grub-mkconfig.in
4ff5f8
+++ b/util/grub-mkconfig.in
4ff5f8
@@ -50,6 +50,8 @@ grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@"
4ff5f8
 export TEXTDOMAIN=@PACKAGE@
4ff5f8
 export TEXTDOMAINDIR="@localedir@"
4ff5f8
 
4ff5f8
+export GRUB_GRUBENV_UPDATE="yes"
4ff5f8
+
4ff5f8
 . "${pkgdatadir}/grub-mkconfig_lib"
4ff5f8
 
4ff5f8
 # Usage: usage
4ff5f8
@@ -59,6 +61,7 @@ usage () {
4ff5f8
     gettext "Generate a grub config file"; echo
4ff5f8
     echo
4ff5f8
     print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")"
4ff5f8
+    print_option_help "--no-grubenv-update" "$(gettext "do not update variables in the grubenv file")"
4ff5f8
     print_option_help "-h, --help" "$(gettext "print this message and exit")"
4ff5f8
     print_option_help "-v, --version" "$(gettext "print the version information and exit")"
4ff5f8
     echo
4ff5f8
@@ -94,6 +97,9 @@ do
4ff5f8
     --output=*)
4ff5f8
 	grub_cfg=`echo "$option" | sed 's/--output=//'`
4ff5f8
 	;;
4ff5f8
+    --no-grubenv-update)
4ff5f8
+	GRUB_GRUBENV_UPDATE="no"
4ff5f8
+	;;
4ff5f8
     -*)
4ff5f8
 	gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
4ff5f8
 	usage
4ff5f8
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
4ff5f8
index b54d2774a7d..da2992ac9f1 100644
4ff5f8
--- a/util/grub.d/10_linux.in
4ff5f8
+++ b/util/grub.d/10_linux.in
4ff5f8
@@ -165,7 +165,7 @@ if [ -s \$prefix/grubenv ]; then
4ff5f8
 fi
4ff5f8
 EOF
4ff5f8
 
4ff5f8
-    if ! grub2-editenv - list | grep -q kernelopts; then
4ff5f8
+    if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then
4ff5f8
 	${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
4ff5f8
     fi
4ff5f8
 
4ff5f8
diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in
4ff5f8
index 8cff4c58ab5..175bedd0763 100644
4ff5f8
--- a/util/grub.d/10_linux_bls.in
4ff5f8
+++ b/util/grub.d/10_linux_bls.in
4ff5f8
@@ -225,7 +225,7 @@ linux_entry ()
4ff5f8
     populate_header_warn
4ff5f8
     populate_menu
4ff5f8
 
4ff5f8
-    if ! grub2-editenv - list | grep -q kernelopts; then
4ff5f8
+    if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then
4ff5f8
 	${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
4ff5f8
     fi
4ff5f8