Bug#996003: grub2: add GRUB_CMDLINE_LINUX_RECOVERY to /etc/default/grub
Chris Vogel
chris at z9.de
Sat Oct 9 22:16:38 BST 2021
Package: grub2
Version: 2.04-20
Severity: wishlist
Tags: patch fixed-upstream
Hi,
I'd like to propose the following patch to add GRUB_CMDLINE_LINUX_RECOVERY to
/etc/default/grub. The patch is accepted already upstream.
When generating grub.cfg using grub-mkconfig and the scripts 10_linux and
20_linux_xen there is no way to add kernel command line parameters _only_ to
the recovery entries generated.
This is needed to e.g. start a debug shell for systemd using the kernel command
line parameter "systemd.debug-shell" or to recover in a system with encrypted
root in situations where the decryption of the root filesystem per crypttab in
the intiramfs image is broken and the recovery entry should contain information
how to decrypt the rootfs (cryptopts=).
This patch does not change the default behaviour of GRUB if
GRUB_CMDLINE_LINUX_RECOVERY is not set in /etc/default/grub.
If GRUB_CMDLINE_LINUX_RECOVERY is set and the generated recovery entry should
include the kernel parameter "single" or "recovery" the parameter must be
explicitly included in GRUB_CMDLINE_LINUX_RECOVERY.
The patch from upstream is altered to respect the already implemented usage of
GRUB_CMDLINE_LINUX_RECOVERY for including friendly-recovery.
As far as I know all credits for the idea and the initial implementation go to
Kyle Ranking of Purism. If this patch is accepted it closes his bug(wishlist)
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=922425 .
Regards.
diff -Nru --exclude .gitignore grub2-2.04/debian/changelog grub2-2.04/debian/changelog
--- grub2-2.04/debian/changelog 2021-07-11 01:37:36.000000000 +0200
+++ grub2-2.04/debian/changelog 2021-10-08 22:47:02.000000000 +0200
@@ -1,3 +1,45 @@
+grub2 (2.04-20.1) UNRELEASED; urgency=medium
+
+ * Non-maintainer upload.
+ * apply patch from upstream:
+ commit 0e5889b98ac202e0aadf04f4115a810304578219
+ Author: Chris Vogel <chris at z9.de>
+ Date: Wed Sep 15 17:42:29 2021 +0200
+
+ templates: Add GRUB_CMDLINE_LINUX_RECOVERY
+
+ When generating grub.cfg using grub-mkconfig and the scripts 10_linux and
+ 20_linux_xen there is no way to add kernel command line parameters _only_ to
+ the recovery entries generated.
+
+ This is needed to e.g. start a debug shell in installations using systemd
+ using the kernel command line parameter "systemd.debug-shell" or to recover
+ in a system with encrypted root in situations where the decryption of the
+ root filesystem per crypttab in the intiramfs image is broken and the recovery
+ entry should contain information how to decrypt the rootfs (cryptopts=).
+
+ This patch does not change the default behaviour of the GRUB if
+ GRUB_CMDLINE_LINUX_RECOVERY is not set.
+
+ If GRUB_CMDLINE_LINUX_RECOVERY is set and the generated recovery entry should
+ include the kernel parameter "single" the parameter must be explicitly included
+ in GRUB_CMDLINE_LINUX_RECOVERY.
+
+ As far as I know all credits for the idea and the initial implementation go to
+ Kyle Ranking of Purism.
+
+ Signed-off-by: Kyle Rankin <kyle.rankin at puri.sm>
+ Signed-off-by: Chris Vogel <chris at z9.de>
+ Reviewed-by: Daniel Kiper <daniel.kiper at oracle.com>
+ * adopted the patch to respect the changes made to integrate friendly-recovery.
+ grubs behaviour will not change with this patch if GRUB_CMDLINE_LINUX_RECOVERY
+ is not set in /etc/default/grub.
+ If GRUB_CMDLINE_LINUX_RECOVERY is set in /etc/default/grub it needs to explicitly
+ include 'single' or 'recovery' if those are wanted to be in the kernel command
+ line of recovery entries.
+
+ -- Chris Vogel <chris at z9.de> Fri, 08 Oct 2021 22:47:02 +0200
+
grub2 (2.04-20) unstable; urgency=medium
[ Mathieu Trudel-Lapierre ]
diff -Nru --exclude .gitignore grub2-2.04/debian/default/grub grub2-2.04/debian/default/grub
--- grub2-2.04/debian/default/grub 2021-07-11 01:37:36.000000000 +0200
+++ grub2-2.04/debian/default/grub 2021-10-08 22:47:02.000000000 +0200
@@ -9,6 +9,17 @@
GRUB_CMDLINE_LINUX_DEFAULT="@DEFAULT_CMDLINE@"
GRUB_CMDLINE_LINUX=""
+# Unless GRUB_DISABLE_RECOVERY is set to "true", two menu entries will be
+# generated for each Linux kernel: one default entry and one entry for
+# recovery mode.
+# This option lists command-line arguments to add only to the recovery menu
+# entry, before those listed in GRUB_CMDLINE_LINUX.
+# The default is "single" or "recovery" if /lib/recovery-mode/recovery-menu
+# (from package friendly-recovery) is present.
+# If the variable is set and the kernel command line shall include "single"
+# or "recovery" it must be explicitly included.
+# GRUB_CMDLINE_LINUX_RECOVERY="single"
+
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
diff -Nru --exclude .gitignore grub2-2.04/debian/patches/mkconfig-default-variable-GRUB_CMDLINE_LINUX_RECOVERY.patch grub2-2.04/debian/patches/mkconfig-default-variable-GRUB_CMDLINE_LINUX_RECOVERY.patch
--- grub2-2.04/debian/patches/mkconfig-default-variable-GRUB_CMDLINE_LINUX_RECOVERY.patch 1970-01-01 01:00:00.000000000 +0100
+++ grub2-2.04/debian/patches/mkconfig-default-variable-GRUB_CMDLINE_LINUX_RECOVERY.patch 2021-10-08 22:47:02.000000000 +0200
@@ -0,0 +1,79 @@
+Index: grub2-2.04/docs/grub.texi
+===================================================================
+--- grub2-2.04.orig/docs/grub.texi
++++ grub2-2.04/docs/grub.texi
+@@ -1382,6 +1382,15 @@ entry for recovery mode. This option li
+ only to the default menu entry, after those listed in
+ @samp{GRUB_CMDLINE_LINUX}.
+
++ at item GRUB_CMDLINE_LINUX_RECOVERY
++Unless @samp{GRUB_DISABLE_RECOVERY} is set to @samp{true}, two menu
++entries will be generated for each Linux kernel: one default entry and one
++entry for recovery mode.
++This option lists command-line arguments to add only to the recovery menu
++entry, before those listed in @samp{GRUB_CMDLINE_LINUX}.
++The default is @samp{single} or @samp{recovery} if @file{/lib/recovery-mode/recovery-menu}
++(from package friendly-recovery) is present.
++
+ @item GRUB_CMDLINE_NETBSD
+ @itemx GRUB_CMDLINE_NETBSD_DEFAULT
+ As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for
+Index: grub2-2.04/util/grub-mkconfig.in
+===================================================================
+--- grub2-2.04.orig/util/grub-mkconfig.in
++++ grub2-2.04/util/grub-mkconfig.in
+@@ -221,6 +221,7 @@ export GRUB_DEFAULT \
+ GRUB_DISTRIBUTOR \
+ GRUB_CMDLINE_LINUX \
+ GRUB_CMDLINE_LINUX_DEFAULT \
++ GRUB_CMDLINE_LINUX_RECOVERY \
+ GRUB_CMDLINE_XEN \
+ GRUB_CMDLINE_XEN_DEFAULT \
+ GRUB_CMDLINE_LINUX_XEN_REPLACE \
+Index: grub2-2.04/util/grub.d/10_linux.in
+===================================================================
+--- grub2-2.04.orig/util/grub.d/10_linux.in
++++ grub2-2.04/util/grub.d/10_linux.in
+@@ -97,11 +97,14 @@ esac
+
+ title_correction_code=
+
+-if [ -x /lib/recovery-mode/recovery-menu ]; then
+- GRUB_CMDLINE_LINUX_RECOVERY=recovery
+-else
+- GRUB_CMDLINE_LINUX_RECOVERY=single
++if [ "x${GRUB_CMDLINE_LINUX_RECOVERY}" = "x" ] ; then
++ if [ -x /lib/recovery-mode/recovery-menu ]; then
++ GRUB_CMDLINE_LINUX_RECOVERY=recovery
++ else
++ GRUB_CMDLINE_LINUX_RECOVERY=single
++ fi
+ fi
++
+ if [ "$ubuntu_recovery" = 1 ]; then
+ GRUB_CMDLINE_LINUX_RECOVERY="$GRUB_CMDLINE_LINUX_RECOVERY nomodeset"
+ fi
+Index: grub2-2.04/util/grub.d/20_linux_xen.in
+===================================================================
+--- grub2-2.04.orig/util/grub.d/20_linux_xen.in
++++ grub2-2.04/util/grub.d/20_linux_xen.in
+@@ -49,6 +49,10 @@ case ${GRUB_DEVICE} in
+ ;;
+ esac
+
++if [ "x${GRUB_CMDLINE_LINUX_RECOVERY}" = "x" ] ; then
++ GRUB_CMDLINE_LINUX_RECOVERY='single'
++fi
++
+ # Default to disabling partition uuid support to maintian compatibility with
+ # older kernels.
+ GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}
+@@ -351,7 +355,7 @@ while [ "x${xen_list}" != "x" ] ; do
+ done
+ if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
+ linux_entry "${OS}" "${version}" "${xen_version}" recovery \
+- "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
++ "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
+ fi
+
+ list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
diff -Nru --exclude .gitignore grub2-2.04/debian/patches/series grub2-2.04/debian/patches/series
--- grub2-2.04/debian/patches/series 2021-07-11 01:37:36.000000000 +0200
+++ grub2-2.04/debian/patches/series 2021-10-08 22:47:02.000000000 +0200
@@ -219,3 +219,4 @@
debug_verifiers.patch
mkimage-fix-section-sizes.patch
tpm-unknown-error-non-fatal.patch
+mkconfig-default-variable-GRUB_CMDLINE_LINUX_RECOVERY.patch
More information about the Pkg-grub-devel
mailing list