How can I get grub2 to boot a different option only on the next boot?

You need to make sure you have GRUB_DEFAULT=saved in your grub config (which is autogenerated, you change this part of it by editing /etc/default/grub). sudo update-grub to make the changes active and then use sudo grub-reboot $1.

grep -i "menuentry '" /boot/grub/grub.cfg

Will give you the menuentries that you can cut-paste in for $1. Or, as you note the options are zero-indexed, so the n-th menuentry can be had by passing (n-1) to grub-reboot.

See eg

  • How to reboot into Windows from Ubuntu?
  • https://unix.stackexchange.com/questions/43196/how-can-i-tell-grub-i-want-to-reboot-into-windows-before-i-reboot
  • https://superuser.com/questions/285755/boot-to-windows-once-from-grub-then-back-to-ubuntu-on-next-boot.

Not tested by me as I don't have a 'Windows 7' install.


That is exactly what grub2-once does. Please try it. Seems grub2-once is only available for linux distros from SUSE.

shiraz-1:~/:[0]# grub2-once --list
     0 SLES 15-SP1
     1 Advanced options for SLES 15-SP1>SLES 15-SP1, with Linux 4.12.14-195-default
     2 Advanced options for SLES 15-SP1>SLES 15-SP1, with Linux 4.12.14-195-default (recovery mode)
     3 Advanced options for SLES 15-SP1>SLES 15-SP1, with Linux 4.12.14-95.54.1.19924.5.TEST.1167133-default
     4 Advanced options for SLES 15-SP1>SLES 15-SP1, with Linux 4.12.14-95.54.1.19924.5.TEST.1167133-default (recovery mode)

shiraz-1:~/:[0]# grub2-once 3
shiraz-1:~/:[0]# reboot