Patch against 10_linux to allow extra entries with special options
Marc Haber
mh+pkg-grub-devel at zugschlus.de
Sat Feb 2 09:30:29 GMT 2019
Hi,
I would like to suggest the attached patch to 10_linux that allows
adding of extra options to /etc/default/grub that will result in
additional menu entries. For example:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash console=ttyS0,57600n8"
GRUB_CMDLINE_LINUX=""
GRUB_CMDLINE_LINUX_EXTRA_ENTRIES="noserial"
GRUB_CMDLINE_LINUX_noserial="quiet splash"
Behavior of GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX is
unchanged, full backwards compatibility is preserved. Behavior of init
system dependent entries and recovery entries is not changed.
For each entry listed in GRUB_CMDLINE_LINUX_EXTRA_ENTRIES, an additional
linux_entry is generated, with the options taken from the variable
GRUB_CMDLINE_LINUX_$ENTRYNAME.
Thus, the example will generate the following entries:
- the DEFAULT entry with the quiet splash console=ttyS0,57600n8 options
- the recovery entry, if so configured
- the init system entries, if so configured
- a "noserial" entry with the quiet splash options
This is a real-life usecase for a server that is usually booted with a
serial console, but in debugging cases wit a local console.
Frankly, I find this patch a bit ugly for three reasons:
- the re-sourcing of /etc/default/grub is necessary since the files from
/etc/grub.d are executed, not sourced, and therefore all environent
variables being used there need to be manually exported. I went for
the minimal-invasive way that only need changes in a single file.
- the extra variable GRUB_CMDLINE_LINUX_EXTRA_ENTRIES is needed since
enumerating environment variables is a bashism, the scripts being
#!/bin/sh files
- the eval needed to build the variable name to evaluate might have
security implcations, but we're calling the script as root anyway, and
all related files are owned by root.
I didn't try upstreaming the change while it might be worthwhile to,
since our 10_linux is heavily changed anyway.
Please indicate whether you might be willing to accept this patch or
whether you would want the implementation to be different. If the
debian-related changes to 10_linux and the meanings of the environment
variables are documented anywhere (I didn't find the docs) I'd be
willing to adapt the documentation as well. I would submit a salsa PR to
make things easier for you.
I'd love hearing from you. Please Cc me as I am not subscribed.
Greetings
Marc
--- 10_linux.orig 2019-02-01 20:06:00.181034980 +0100
+++ 10_linux 2019-02-01 20:10:40.724607616 +0100
@@ -34,6 +34,20 @@
CLASS="--class gnu-linux --class gnu --class os"
SUPPORTED_INITS="sysvinit:/lib/sysvinit/init systemd:/lib/systemd/systemd upstart:/sbin/upstart"
+# copied from /usr/sbin/grub-mkconfig
+# we need to read the configuration again since otherwise all variables
+# would need extra exports
+# is sysconfdir not exported?
+sysconfdir="/etc"
+if test -f ${sysconfdir}/default/grub ; then
+ . ${sysconfdir}/default/grub
+fi
+for x in ${sysconfdir}/default/grub.d/*.cfg ; do
+ if [ -e "${x}" ]; then
+ . "${x}"
+ fi
+done
+
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS=GNU/Linux
else
@@ -120,6 +134,8 @@
title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")")" ;;
init-*)
title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "${type#init-}")" ;;
+ extra-*)
+ title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "${type#extra-}")" ;;
*)
title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
esac
@@ -358,7 +374,11 @@
linux_entry "${OS}" "${version}" recovery \
"${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
fi
-
+ for extra_entry in ${GRUB_CMDLINE_LINUX_EXTRA_ENTRIES}; do
+ eval EXTRA_ENTRY_OPTIONS=\$GRUB_CMDLINE_LINUX_${extra_entry}
+ linux_entry "${OS}" "${version}" "extra-${extra_entry}" \
+ "${EXTRA_ENTRY_OPTIONS} ${GRUB_CMDLINE_LINUX}"
+ done
list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
done
--
-----------------------------------------------------------------------------
Marc Haber | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421
More information about the Pkg-grub-devel
mailing list