Joe Wein’s blog

Comments from Yokohama, Japan

Fix Windows as default boot on Ubuntu with Grub2 loader

November 28th, 2009 · 6 Comments

If you install Ubuntu on a machine that came with Windows pre-installed you have the choice of preserving Windows and chose each time you boot which operating system to run. By default, the boot menu will list the current Linux kernel, followed by any older Linux kernel versions, followed by a memory test and finally the original Windows version. By changing a GRUB boot loader configuration file you can chose which one is the default that gets booted when you just wait and don’t touch the keyboard.

(NOTE: The following instructions assume the Grub2 loader used in Ubuntu 9.10 – earlier versions are different)

For example, the menu might look like this:

Ubuntu, Linux 2.6.31-14-generic
Ubuntu, Linux 2.6.31-14-generic (recovery mode)
memory test (memtest86+)
memory test (memtest86+, serial console 115200)
Windows Vista (loader) (on /dev/sda1)

You can configure Linux to — unless you tell it otherwise — always boot Vista by setting GRUB_DEFAULT in /etc/default/grub to the number of lines above the entry you want to boot (4 in this case), instead of 0 (zero) for the top entry. After any change to /etc/default/grub you need to also run sudo update-grub:

joe@ubuntu910:~$ gksudo gedit /etc/default/grub

GRUB_DEFAULT=4

joe@ubuntu910:~$ sudo update-grub

The problem with that is, when the next kernel update comes out, two lines will be inserted at the top and your default value now selects the wrong entry:

Ubuntu, Linux 2.6.31-15-generic
Ubuntu, Linux 2.6.31-15-generic (recovery mode)
Ubuntu, Linux 2.6.31-14-generic
Ubuntu, Linux 2.6.31-14-generic (recovery mode)
memory test (memtest86+)
memory test (memtest86+, serial console 115200)
Windows Vista (loader) (on /dev/sda1)

You would need to manually select the latest kernel and repeat the above steps with a new value of 6 in this case. This is clearly a problem. Fortunately, there’s a simple workaround: use a name instead of a number for selecting the default. Here is how it works:

1) List the bootable operating systems:

joe@ubuntu910:~$ fgrep menuentry /boot/grub/grub.cfg
menuentry “Ubuntu, Linux 2.6.31-15-generic” {
menuentry “Ubuntu, Linux 2.6.31-15-generic (recovery mode)” {
menuentry “Ubuntu, Linux 2.6.31-14-generic” {
menuentry “Ubuntu, Linux 2.6.31-14-generic (recovery mode)” {
menuentry “Memory test (memtest86+)” {
menuentry “Memory test (memtest86+, serial console 115200)” {
menuentry “Windows Vista (loader) (on /dev/sda1)” {

2) Mark and copy the entry you want to stay bootable, from double quote to double quote, for example “Windows Vista (loader) (on /dev/sda1)”.

3) Edit the Grub configuration and paste the new value after the GRUB_DEFAULT= (in place of 0 or 4 or whatever number):

joe@ubuntu910:~$ gksudo gedit /etc/default/grub
GRUB_DEFAULT=”Windows Vista (loader) (on /dev/sda1)”
joe@ubuntu910:~$ sudo update-grub

That’s it, no more Grub configuration tinkering required! :-)

Tags: Linux · Windows Vista · Windows XP · software

6 responses so far ↓

  • 1 TristanDee // Dec 9, 2009 at 15:46

    Thanks for sharing the useful piece of information.
    However, trying to set OS name (“Windows Vista (loader)” in my case) to GRUB_DEFAULT didn’t work for me. I rechecked if I did everything right, but every time I rebooted Debian remained selected as the default OS. Setting the default time worked fine, though. Any idea?
    This is Grub 1.97~Beta3, if that’s a factor.

  • 2 Joe Wein // Dec 9, 2009 at 17:55

    Here it’s Grub 1.97~Beta4 — not sure if that would make much of a difference.

    You did run “sudo update-grub” after editing the file, didn’t you?

  • 3 TristanDee // Dec 9, 2009 at 23:18

    Yeah, I did run update-grub.
    What I forgot to mention: the numerical value for GRUB_DEFAULT worked. But, as you said in your article, an upgrade to a newer kernel will need me to manually change the number again.
    I can only hope this glitch regarding setting OS_name will get fixed by then!

  • 4 Joe Wein // Dec 10, 2009 at 18:33

    Hi Tristan,

    can you email me (joewein@pobox.com) this file from your machine:

    /boot/grub/grub.cfg

    I am curious what’s different between your setup and mine!

  • 5 Mike W // Jan 3, 2010 at 04:41

    A much easier way to do this is to install Start up manager through synaptic…

  • 6 Bill Wayson // Jan 7, 2010 at 08:14

    Thank you so much for taking the time to write this up. I came across it at the end of an Ubuntu 9.10 installation, at a meeting of my Linux group, on a PC that needed to dual boot into Windows by default. Your instructions worked perfectly for us.

Leave a Comment