How to reboot into Windows from Ubuntu?

  • 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.

There is a grub command just to do so, it is grub-reboot.

It seems to only work when you have grub configured to start with the last saved entry. So if you have not already done so, modify /etc/default/grub and set

GRUB_DEFAULT=saved

then update grub configuration file:

sudo update-grub

From now on, at each boot grub will start the last used entry.

Now, if you want to set in advance what should be the system to boot the next time, use

sudo grub-reboot ENTRY

where ENTRY could be a number relative to a menu entry (numbered starting from 0), or an exact menu entry title, for example

sudo grub-reboot "Microsoft Windows XP Professional (on /dev/sda1)"

This command can easily be made available as a launcher

#!/usr/bin/env xdg-open
#
# save as ~/Desktop/reboot-into-windows.desktop
#

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=sh -c 'gksu "grub-reboot 2" && gnome-session-save --shutdown-dialog'
Name=Reboot into Windows
Icon=gnome-panel-launcher

but I don't know how it could be integrated into the system menu.

You can obtain the available menu entry title with

sed -n '/menuentry/s/.*\(["'\''].*["'\'']\).*/\1/p' /boot/grub/grub.cfg 

I think I have found an even nicer way for people who want to the same while locally at their pc without ssh.

A solution to reboot into a specific system choosen through a unity launcher was just posted on webupd8. See http://www.webupd8.org/2011/05/custom-unity-launcher-to-reboot-in.html

I know this is not exactly what the question is about but in case someone has a similar question later this might be helpful.