Typical GRUB boot menu looks like the following:
+-----------------------------+
|*Debian GNU/Linux |
| Devuan GNU/Linux |
| Other ... |
| |
+-----------------------------+
The highlighted entry will be executed automatically in Xs
In this example, Debian GNU/Linux
is on index #1, Devuan GNU/Linux
is on index #2, Other ...
is on index #3, and so on. The star ( * ) preceeding Debian GNU/Linux entry means that it's the default selection. You can use arrow keys on keyboard to navigate the menu and press ENTER to boot the selection. If you don't select anything, the default selection gets executed automatically in X seconds.
For headless setup scenario, you mostly access this machine over SSH. You can't see GRUB menu over SSH. This gist guides you to setup your machine so that you can switch between OSes remotely over command line.
This method is only tested to switch between Linux OSes, it may or may not work with Windows. Your mileage may vary and make sure you know what you are doing with GRUB.
When Linux machine boots, Debian GNU/Linux (default, highlighted, with * ) for example. Edit etc/default/grub
and add the following lines:
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
then, run:
$ update-grub
and reboot the machine.
What we did just now is to activate GRUB feature to remember and save the last OS selection. Try to boot different OSes and notice where GRUB highlights your last booted OS.
Boot into Debian GNU/Linux (default, highlighted, with * ). On terminal, do cat /boot/grub/grub.cfg
. You should see something similar to the following:
menuentry 'Debian GNU/Linux' {
set root=(hd0,1)
linux /boot/vmlinuz root=/dev/sda1 quiet
initrd /boot/initrd.img
}
menuentry 'Devuan GNU/Linux' {
set root=(hd0,2)
linux /boot/vmlinuz root=/dev/sda2 quiet
initrd /boot/initrd.img
}
menuentry 'Oher ...' {
...
}
Let's boot into Devuan (index #2) just once:
$ grub-reboot 2
then, reboot the machine. Notice that it switches into Devuan GNU/Linux. Once you are done with Devuan and reboot the machine, it will automatically enter Debian GNU/Linux as default selection.
Let's say you want to boot Devuan GNU/Linux permanently, we make it as default OS selection:
$ grub-set-default 2
$ grub-reboot 2
then, reboot the machine. Notice that it switches into Devuan GNU/Linux. Once you are done with Devuan and reboot the machine, it stays with Devuan GNU/Linux as default selection.
Use the following command for troubleshooting in case your machine boots to the wrong index:
$ grub-editenv list
next_entry = x
saved_entry = y
Make sure you select the correct index, it is relative to active OS you are in when issue GRUB command. The next_entry
is vaild only for the next reboot. The saved_entry
points to default entry.
You can confirm index by looking into /boot/grub/grub.cfg
and look at the menuentry
property:
$ cat /boot/grub/grub.cfg | grep menuentry