Consider the following dual-boot setup:

  • Grub is installed to /dev/sda
  • /dev/sda1 is mounted as /boot
  • /dev/sda6 is mounted as /
  • Windows 10 is installed to /dev/sdb2

As it stands now, Grub selects Ubuntu by default when it boots and I can remotely login via SSH. It is also possible to select Windows when Grub starts and I can remotely login via RDP.

The problem is that I have no way of selecting which OS to boot when I am not physically present.

This question describes a method for having Grub automatically boot the last selected operating system. However, this will not work. If I select Windows, I have no way to remotely restart the PC and boot Ubuntu.

Is there a way to remotely control which OS boots?

  • @Takkat from the Windows side though? (Can I be running Windows and have some sort of program or script instruct Grub to boot Ubuntu?) – Nathan Osman Aug 14 '15 at 18:44
  • @Takkat oh, I see what you're saying... that might work. – Nathan Osman Aug 14 '15 at 18:46
  • Have you thought about booting via PXE? Then you could leave your boot configuration on another server which you could access any time and adjust accordingly and then reboot the other machine to start the specified OS? – Ziazis May 7 '19 at 9:20

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.

| improve this answer | |

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! :-(

| improve this answer | |
  • More ideas please. :) – A.B. Aug 15 '15 at 15:03

You can set the default OS with grub depending on time, see Can GRUB be scheduled? This means: changing default 'entry' (auto login) at defined periods of time automatically?. So, for example, you can configure grub to boot to Windows when $MINUTE is odd and boot to Linux when $MINUTE is even.

insmod datehook
if [ $MINUTE -eq 0 -o $MINUTE -eq 2  -o $MINUTE -eq 4 -o $MINUTE -eq 6 -o $MINUTE -eq 8]; then
    set default="Ubuntu"
    set default="Windows"

If you want to a specific OS ; just wait until its time comes.

Using this method should take into account the time it takes to reach Grub. Using time frame of 5 minutes is probably more reliable.

I think it's also possible to alternate between the boot entries. Something like :

if [ $default = "Ubuntu" ]; then
  set default="Windows"
  set default="Ubuntu"

when grub is configured to remember the last OS booted (How to get grub2 to remember last choice?)

If your PC doesn't boot into the OS you want, just reboot.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.