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