Skip to content

Add code to support GRUB_CMDLINE_LINUX_EXTRA_ENTRIES

Marc Haber requested to merge zugschlus/grub:extralinux into master

This patch allows adding of extra options to /etc/default/grub which 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 with a local console. A different use case would for example be a desktop/notebook computer, adding an option to not boot into graphical:

GRUB_CMDLINE_LINUX_EXTRA_ENTRIES="nongraphical" GRUB_CMDLINE_LINUX_nongraphical="systemd.unit=multi-user.target"

This patch has room for improvement though:

  • the re-sourcing of /etc/default/grub is necessary since the files from /etc/grub.d are executed, not sourced, and therefore all environment variables being used there need to be manually exported. For this patch, the minimal-invasive way that only need changes in a single file was chosen.
  • 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.

Upstreaming the change wasn tried. It might be worthwhile to, but Debian's 10_linux is heavily changed anyway.

Merge request reports

Loading