I, like many others, have a dual-boot system. I run Debian (unstable / sid) as my primary OS, and Windows 7 when I play games. Hopefully Steam coming to Linux means that I won’t have to reboot anymore, but for the moment I do.
Of course, it’s not really hard to reboot your system and then choose the correct option in th GRUB menu, but it does mean you have to stay around to prevent GRUB from booting the default OS, instead of walking to the kitchen to get a cup of coffee / tea / [insert beverage of choice here]. Well, there’s a solution for that, a command called grub-reboot. For example:
sudo grub-reboot 6
This will set the 7th entry in the list of OSes as the default for one boot (it’s a 0-based index). Then reboot, et voila! You still have to know which entry to boot, of course, but you can just count it once and remember. Right? Well, it’s not always that simple.
The problem is that sometimes a new Linux kernel is installed and the old one is kept, to be able to reboot safely when the new kernel doesn’t work (which has actually never happened to me, but is a possibility when running Debian unstable). In that case, you might need to reboot to a different entry. Besides that, I wanted to have a nice icon to click on, that would set the grub entry and reboot me in one simple step.
I’ve created a simple shell script that reads the correct menu entry from grub.cfg and sets that up for the next boot. After that the script calls gnome-session-quit to request a reboot (you can choose between Cancel, Restart or Power Off):
#!/bin/sh # Find the menuentry containing Windows #entry=`grep menuentry /boot/grub/grub.cfg | grep -n Windows | cut -d":" -f 1` entry=`grep -E '^menuentry|submenu' /boot/grub/grub.cfg | grep -n Windows | cut -d":" -f 1` /usr/sbin/grub-reboot $(($entry - 1)) gnome-session-quit --power-off
Update (16-5-2013): The version of Grub I currently use, adds support for submenus. Only top-level menuitems and submenus should be counted.
Save it as ~/bin/reboot-to-windows.sh (or some such). Use chmod to make it executable. Also, you will probably have to fiddle with write rights to /boot/grub/grubenv. Either create a grub-reboot group that you add all allowed users to, and set that as the group for the file. Or you can add yourself and other allowed users to the ‘root’ group (Beware: This might introduce serious security issues). Or you can just make the file world-writeable (which allows all users to fuck up your system by corrupting the file).
Now, to create an entry in the Gnome-shell menu (yes, I use Gnome-shell), create a file ~/.local/share/applications/RebootWindows.desktop with the following contents:
#!/usr/bin/env xdg-open [Desktop Entry] Encoding=UTF-8 Name=Reboot to Windows Exec=/home/your-username/bin/reboot-to-windows.sh Icon=/home/your-username/bin/Windows-reboot.svg Type=Application Categories=System;
Where ‘your-username’ is your username, obviously. I’m not sure ~/bin/reboot-to-windows.sh will work, instead of a full path. The Icon entry refers to a svg graphic I created, here it is:
Save the file. The entry should now show up and be clickable.
Enjoy!
Update (31-12-2012): I forgot a modification in /etc/default/grub:
# Enable grub-reboot #GRUB_DEFAULT=0 GRUB_DEFAULT=saved
Otherwise, grub will just boot the first entry, no matter what.

Hey nice one Matthijs, useful for me since I’ve the same problem all the time…
I’m gonne try to modify this one for KDE (not today..)
Comment by arno — January 2, 2013 @ 5:10 pm
Cool! Let me know how it works out.
Comment by wensveen — January 2, 2013 @ 7:53 pm
It seems that KDE can already do this out of the box: How to use grub-reboot in KDE
Comment by wensveen — January 3, 2013 @ 7:29 am
This worked for older versions of KDE, the option to set the boot manager doesn’t seem to exist any more.
It can still work, just a matter of finding out how to modify the shutdown dialog…
Comment by arno — January 5, 2013 @ 11:02 am