The grub-reboot command is very handy, but has a fatal flaw on config files
with submenus. It requires the user to parse grub.cfg to figure out
non-obvious MENU_ENTRY numbers separated by greater than signs. It would be
nice if it showed a list and asked the user which boot entry is desired.

I've included below a patched version of grub-reboot which does exactly
that. It is imperfect, but I believe it shows what could be done without
too much more work. The main flaw is a lack of a decent parser for the
config file (an awk kludge is included instead). A secondary flaw is that
it uses Bash's mapfile and select commands. For maximum portability, it may
make sense to try to reimplement these as Bourne shell.

—b9

$ *grub-reboot -h*
Usage: grub-reboot [OPTION] [MENU_ENTRY]
Set the default boot menu entry for GRUB, for the next boot only.
  -h, --help              print this message and exit
  -V, --version           print the version information and exit
  -s, --select            interactively select entry to boot (DEFAULT)
  --boot-directory=DIR    expect GRUB images under the directory DIR/grub
                          instead of the /boot/grub directory

MENU_ENTRY is a number, a menu item title or a menu item identifier.
Please note that menu items in submenus or sub-submenus require
specifying the submenu components and then the menu item component.
The titles should be separated using the greater-than character (>)
with no extra spaces. Depending on your shell some characters
including > may need escaping. More information about this is available
in the GRUB Manual in the section about the 'default' command.

Report bugs to <bug-grub@gnu.org>.
$ *grub-reboot*
Please pick an OS to reboot into (for this next boot only).  ^C to cancel.
1)  0>0  Debian GNU/Linux
2) 1 submenu 'Advanced options for Debian GNU/Linux'
3)  1>0          Debian GNU/Linux, with Linux 4.19.0-6-amd64
4)  1>1          Debian GNU/Linux, with Linux 4.19.0-6-amd64 (recovery
mode)
5)  1>2          Debian GNU/Linux, with Linux 4.9.0-11-amd64
6)  1>3          Debian GNU/Linux, with Linux 4.9.0-11-amd64 (recovery
mode)
7)  1>4          Debian GNU/Linux, with Linux 4.9.0-3-amd64
8)  1>5          Debian GNU/Linux, with Linux 4.9.0-3-amd64 (recovery mode)
9) None of the above.
#?* 4.9*
Next reboot will be into `Debian GNU/Linux, with Linux 4.9.0-11-amd64'

Attachment: grub-reboot
Description: Binary data

_______________________________________________
Bug-grub mailing list
Bug-grub@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-grub

Reply via email to