How to remotely control which OS Grub boots?

Solution 1:

We can reboot to a given Grub menu boot entry using grub-reboot. This can also be done from a remote session e.g. via SSH.

To boot into another OS choose the position it is represented in the Grub menu starting from 0:

sudo grub-reboot <num>

enter image description here

In this case my Windows is on position 4. So when issueing

sudo grub-reboot 4 && sudo reboot

The machine will reboot to Windows after the timeout we defined in the Grub settings.

After rebooting from Windows the machine will boot into the default OS. This can be defined with

sudo grub-set-default <num>

To make this work we may have to define GRUB_DEFAULT=saved in our /etc/default/grub but on my system it also worked with the default settings.

Sadly rebooting Windows from Windows can not be done by this.

Solution 2:

Another idea thanks to takkat's answer:

  1. Default boot is Ubuntu
  2. grub-reboot N where N is the Windows boot entry
  3. Rebooting Windows will bring you back to default boot: Ubuntu.

Disadvantage: to reboot Windows you have to reboot twice: Reboot Windows, let Ubuntu boot and grub-reboot N again! :-(