All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] templates: Add GRUB_CMDLINE_LINUX_RECOVERY
@ 2021-09-14 19:25 chris
  2021-09-15 13:18 ` Paul Menzel
  0 siblings, 1 reply; 5+ messages in thread
From: chris @ 2021-09-14 19:25 UTC (permalink / raw)
  To: grub-devel; +Cc: daniel.kiper, alexander.burmashev, phcoder, Chris Vogel

From: Chris Vogel <chris@z9.de>

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 informations about how to decrypt the rootfs (cryptopts=).

This patch does not change the default behaviour of 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: Chris Vogel <chris@z9.de>
---
 docs/grub.texi              | 8 ++++++++
 util/grub-mkconfig.in       | 1 +
 util/grub.d/10_linux.in     | 6 +++++-
 util/grub.d/20_linux_xen.in | 6 +++++-
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index f8b4b3b21..8b5482ee1 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1411,6 +1411,14 @@ entry for recovery mode.  This option lists command-line arguments to add
 only to the default menu entry, after those listed in
 @samp{GRUB_CMDLINE_LINUX}.
 
+@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}.
+
 @item GRUB_CMDLINE_NETBSD
 @itemx GRUB_CMDLINE_NETBSD_DEFAULT
 As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index f8cbb8d7a..c3ea7612e 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -225,6 +225,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 \
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index e8b01c0d0..af51ae2f7 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -43,6 +43,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}
@@ -287,7 +291,7 @@ while [ "x$list" != "x" ] ; do
               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
     linux_entry "${OS}" "${version}" recovery \
-                "single ${GRUB_CMDLINE_LINUX}"
+                "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
   fi
 
   list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
index 3b1f47049..992363c3e 100644
--- a/util/grub.d/20_linux_xen.in
+++ b/util/grub.d/20_linux_xen.in
@@ -43,6 +43,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}
@@ -343,7 +347,7 @@ while [ "x${xen_list}" != "x" ] ; do
 	    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
 	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' ' '`
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] templates: Add GRUB_CMDLINE_LINUX_RECOVERY
@ 2021-09-15 15:42 chris
  0 siblings, 0 replies; 5+ messages in thread
From: chris @ 2021-09-15 15:42 UTC (permalink / raw)
  To: grub-devel
  Cc: daniel.kiper, alexander.burmashev, phcoder, kyle.rankin, Chris Vogel

From: Chris Vogel <chris@z9.de>

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 informations about how to decrypt the rootfs (cryptopts=).

This patch does not change the default behaviour of 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: Chris Vogel <chris@z9.de>
---
 docs/grub.texi              | 8 ++++++++
 util/grub-mkconfig.in       | 1 +
 util/grub.d/10_linux.in     | 6 +++++-
 util/grub.d/20_linux_xen.in | 6 +++++-
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index f8b4b3b21..8b5482ee1 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1411,6 +1411,14 @@ entry for recovery mode.  This option lists command-line arguments to add
 only to the default menu entry, after those listed in
 @samp{GRUB_CMDLINE_LINUX}.
 
+@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}.
+
 @item GRUB_CMDLINE_NETBSD
 @itemx GRUB_CMDLINE_NETBSD_DEFAULT
 As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index f8cbb8d7a..c3ea7612e 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -225,6 +225,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 \
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index e8b01c0d0..af51ae2f7 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -43,6 +43,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}
@@ -287,7 +291,7 @@ while [ "x$list" != "x" ] ; do
               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
     linux_entry "${OS}" "${version}" recovery \
-                "single ${GRUB_CMDLINE_LINUX}"
+                "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
   fi
 
   list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
index 3b1f47049..992363c3e 100644
--- a/util/grub.d/20_linux_xen.in
+++ b/util/grub.d/20_linux_xen.in
@@ -43,6 +43,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}
@@ -343,7 +347,7 @@ while [ "x${xen_list}" != "x" ] ; do
 	    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
 	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' ' '`
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-15 17:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 19:25 [PATCH] templates: Add GRUB_CMDLINE_LINUX_RECOVERY chris
2021-09-15 13:18 ` Paul Menzel
2021-09-15 15:12   ` Daniel Kiper
2021-09-15 15:35     ` Kyle Rankin
2021-09-15 15:42 chris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.