How can I tell GRUB I want to reboot into Windows—before I reboot?
- Edit the /etc/default/grub and replace
GRUB_DEFAULT=0
withGRUB_DEFAULT=saved
sudo update-grub
Your command will be:
sudo grub-reboot "$(grep -i windows /boot/grub/grub.cfg|cut -d"'" -f2)" && sudo reboot
A pretty function for your
~/.bashrc
or.bash_aliases
could look like:# Reboot directly to Windows # Inspired by http://askubuntu.com/questions/18170/how-to-reboot-into-windows-from-ubuntu reboot_to_windows () { windows_title=$(grep -i windows /boot/grub/grub.cfg | cut -d "'" -f 2) sudo grub-reboot "$windows_title" && sudo reboot } alias reboot-to-windows='reboot_to_windows'
Editor's notes:
I have replaced deprecated backticks (
``
) by$(...)
construct.In general, I have re-written it to adhere to current POSIX (wiki) standards, and while at it, did a few minor other changes.
For completeness, I left the below function untouched for comparison.
In case, your grub.conf contains multiple lines for Windows, following functions will take care only about lines starting by menuentry
and picking just the first one, referring to Windows:
function my_reboot_to_windows {
WINDOWS_TITLE=`grep -i "^menuentry 'Windows" /boot/grub/grub.cfg|head -n 1|cut -d"'" -f2`
sudo grub-reboot "$WINDOWS_TITLE"
sudo reboot
}
In order for the grub-reboot
command to work, several required configuration changes must be in place:
- The default entry for grub must be set to
saved
. One possible location for this is theGRUB_DEFAULT=
line in/etc/default/grub
- Use
grub-set-default
to set your default entry to the one you normally use. - Update your grub config (e.g.
update-grub
).
This should take care of the initial set-up. In the future, just do grub-reboot <entry>
for a one-time boot of <entry>
.
Agree with @jw013. And you can also give the menu tile to grub-reboot (including the title of parent menu). e.g:
$ sudo grub-reboot "Advanced options for Ubuntu>Ubuntu, with Linux 4.13.0-26-generic"
$ sudo reboot
Where "Advanced options for Ubuntu" is the parent menu, "Ubuntu, with Linux 4.13.0-26-generic" is submenu.