Ubuntu – How to reboot into Windows from Ubuntu

dual-bootgrub2reboot

I'm looking for a way to reboot into Windows from Ubuntu on a 10.10/Vista dual boot system. The specific use case is that I would like to be able to ssh into my running Ubuntu instance and issue a command that will initiate a reboot directly into Windows.

I found a promising blog post, but the script that it suggests isn't working:

#!/bin/bash

WINDOWS_ENTRY=`grep menuentry /boot/grub/grub.cfg  | grep --line-number Windows`
MENU_NUMBER=$(( `echo $WINDOWS_ENTRY | sed -e "s/:.*//"` - 1 ))
sudo grub-reboot $MENU_NUMBER
sudo reboot

man grub-reboot isn't much help, but it seems to be leading me in the right direction:

set the default boot entry for GRUB,
for the next boot only

WINDOWS_ENTRY=`grep menuentry /boot/grub/grub.cfg  | grep --line-number Windows`
MENU_NUMBER=$(( `echo $WINDOWS_ENTRY | sed -e "s/:.*//"` - 1 ))
echo $MENU_NUMBER

This returns the expected value, but on reboot the first menu entry is still highlighted. Any ideas why this isn't working or suggestions for other solutions?

Best Answer

  • You have to edit your grub first.

    sudo gedit /etc/default/grub
    
  • Search for the line GRUB_DEFAULT=0 and modify it to GRUB_DEFAULT=saved alt text

  • Update your grub using the following command.

    sudo update-grub  
    
  • Now create a script file,

    sudo gedit switch-to-windows.sh
    
  • Then add these lines.

    #!/bin/bash
    WINDOWS_ENTRY=`grep menuentry /boot/grub/grub.cfg  | grep --line-number Windows`
    MENU_NUMBER=$(( `echo $WINDOWS_ENTRY | sed -e "s/:.*//"` - 1 ))
    sudo grub-reboot $MENU_NUMBER
    sudo reboot
    
  • Make the script executable.

    sudo chmod +x switch-to-windows.sh
    
  • And now you can run this script from terminal to reboot into windows.

    ./switch-to-windows.sh
    
  • Or you can execute the following command in your terminal

    sudo grub-reboot X  
    
  • Where X is the menuentry position of the OS you want to restart in from the GRUB menu.(starting with 0 as the first entry)

For Example:

  • If this is your grub menu and if you want to boot into windows you should give the value of X as 5.
  • sudo grub-reboot 5

    alt text

  • You can also create a launcher for the above command,so that double clicking the launcher will reboot into windows.
Related Question