Joe Wein's blog

Comments from Tokyo, Japan

Fix Windows as default boot on Ubuntu with Grub2 loader

November 28th, 2009 · 37 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, including double quotes, 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

Note: Make sure to close the gedit window before doing sudo update-grub

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

Tags: Linux · software · Windows Vista · Windows XP

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

  • 7 martin // Apr 16, 2010 at 07:35

    ThanX Joe!
    I got the link to your post from within #linuxmint-help chatbox.
    As an non-English non-Linux-expert I still had some struggle though!
    I would suggest to change your remark: ‘from double quote to double quote’ to ‘including double quotes’ and also add the advice to close the opened gedit-window before giving ‘sudo update-grub’ in terminal. I tried to do this command first, but then nothing happened, while I also seemed to have lost the auto-beginning of the next command, i.e. user@machine ~$ . After closing gedit, everything came allright do, according to sudden terminal-output-reaction!

  • 8 Joe Wein // Apr 16, 2010 at 08:30

    @martin:

    Thanks! Your suggestions are now reflected in the revised text :-)

  • 9 Peter // Apr 21, 2010 at 04:05

    Thanks Joe,
    Worked for me.
    I installed Ubuntu on a Windows PC but for the time being still need the user to get used to Ubuntu
    so want to launch Windows by default. I will change that in the future:-)
    Regards,
    Peter

  • 10 Neil // May 2, 2010 at 03:55

    Thanks. Tried Startup Manager, but this changed the entry back to the numeric value of the default O/S. When I removed the memtest entries, Ubuntu became the default again.

  • 11 boby // May 19, 2010 at 21:56

    Thanks!
    Perfect!

    Boby

  • 12 Pierre // Jun 22, 2010 at 20:22

    Hi there! I tried the original procedure, but my problem is, that since I updated ubuntu 9.10, Windows 7 is missing from the grub list, meaning, the boot loader and the grub. cfg file.
    I though maybe the new kernels were ‘pushing down windows 7, not allowing it to appear in the list, so I tried removing older kernels from synaptic as well, but they’re still listed. So I have no idea what to do to fix grub. I’m about to try 3 things; removing entries manually, running this code:

    $ sudo apt-get install –reinstall libdebian-installer4
    $ sudo os-prober
    $ sudo update-grub

    …or ultimately, reinstall windows to overwrite grub. I hope I won’t have to get to that though.

  • 13 ncatarino.net – Stuff I added on top of my default Ubuntu install // Sep 4, 2010 at 07:38

    [...] http://www.joewein.net/blog/2009/11/28/fix-windows-as-default-boot-on-ubuntu-9-10-with-grub2-loader/ Share this post: [...]

  • 14 Nuno // Sep 4, 2010 at 07:47

    Worked perfectly, thanks.

  • 15 Dmytrii Nagirniak // Oct 7, 2010 at 18:08

    Thanks for the clear instructions.

  • 16 Angelo Fiorillo // Oct 21, 2010 at 01:46

    Great! Thank you!

  • 17 Niklas // Dec 15, 2010 at 04:24

    Just what i need! Thank you and keep up the good work. stay classy…

  • 18 Vladimir // Jan 27, 2011 at 18:32

    Your post really helped me to reconfigure grub2 default menu item selection. Thank you.

  • 19 Ivan Ivanić // Feb 7, 2011 at 05:26

    Hi Joe :)
    That did not worked for me. But I have quick and dirty fix :)
    Neither setting default as number nor as long entry with quotes. But I did this:
    Open /boot/grub/grub.cfg
    Find windows entry near end of file. Entry is long e.g.:
    “Windows 7 (loader) on (/dev/sda2)” change that to “Windows7″
    make that default entry. That does it. I think it has something to do with that long names are not yet supported in grub2. (I read that somewhere, maybe it is bogus info) :)))

  • 20 Grub 2 Fixes » Solo Technology // Mar 8, 2011 at 15:37

    [...] I found a blog post titled, “Fix Windows as default boot on Ubuntu with Grub2 loader” that offers a very simple solution. Just specify the default OS by name instead of number! [...]

  • 21 ActionParsnip // Apr 21, 2011 at 22:07

    The value defined in DEFAULT= does not respect new kernels. This is a better fix and will withstand new kernels:
    http://saji89.wordpress.com/2010/02/01/how-to-make-windows-the-defaultfirst-entry-in-your-grub2-menu/

  • 22 Shawon // May 1, 2011 at 13:34

    It worked :D thank you sooooooooooooo much

  • 23 Noobslab // Aug 14, 2011 at 21:53

    Really nice, Thanks for this

  • 24 Joe Wein // Aug 23, 2011 at 17:28

    The fix described at http://saji89.wordpress.com/2010/02/01/how-to-make-windows-the-defaultfirst-entry-in-your-grub2-menu/ works but if you have a Windows recovery partition enumerated above the Windows boot partition, it will default to the recovery partition, not the boot partition.

  • 25 Prophet Zarquon // Sep 29, 2011 at 03:53

    Thanks Action Parsnip!

    THIS worked for me:

    sudo mv 30_os-prober 08_0s-prober
    sudo update-grub

    (StartUp Manager affects nothing FSDR)

  • 26 Ryan // Oct 9, 2011 at 04:14

    Brilliant! Thanks very much!

  • 27 gokay // Oct 21, 2011 at 06:24

    Thanks, that is what i need.

  • 28 Sergey // Feb 25, 2012 at 21:08

    Thanks, this is what I was looking for!

  • 29 san diego packing supplies // Nov 23, 2012 at 17:57

    I though maybe the new kernels were ‘pushing down windows 7, not allowing it to appear in the list, so I tried removing older kernels from synaptic as well, but they’re still listed.

  • 30 syed // Jul 13, 2013 at 17:00

    hi..i have same loader problem.it doesnt move..because at the startup my Keyboard doesnt work…i went to hardware guy ..he changed startup from the BIOS setting and it worked like charm..now again same problem with me..how to do it.. From BIOS ..i want to skip this whole..choose your OS step..plese help

  • 31 best free registry cleaner // Oct 13, 2013 at 17:27

    Identify the amount of hard drive area it will need to completely set up its laptop laptop or computer pc pc or personal pc components. See if it contains storage requirements to be able to operate.

  • 32 how can I get my repossessed car back // Oct 17, 2013 at 23:33

    All those individuals authorized as associates have to follow certain requirements and the social requirements of the associated organization.Paralegal companies benefit its associates in various ways. They perform academic programs, sessions, conferences,

  • 33 how to jailbreak iphone 4 // Nov 6, 2013 at 15:36

    Your phone is ready for use this service is best service for unlock 3gs and many user can follow this service. Because these unlock 3gs service is using for many smart phones and iphones there 3G, 4G phone also unlocked by suing this service.

  • 34 Huntsville buy insurance // Dec 7, 2013 at 18:25

    Insurance plan in Huntsville is no longer a annoying challenge. I have observed that my economical program is made of things just like a challenge.

  • 35 green coffee bean max // Jul 29, 2014 at 17:58

    Green Coffee Bean Max is a weight loss health supplement with 100% green coffee bean extract as its main ingredient. The health supplement has gained popularity for its unique ability to burn fat effective and other remarkable benefits. It is one of the rare 100% safe and natural health supplements as it contains completely natural ingredients without additives.

  • 36 vacation rentals jerusalem // Aug 20, 2014 at 17:06

    J town rentals began in 2008 as a local sublet business. 4 years later, we have become a full scale brokerage company,still servicing the locals as well as tourists and property owners worldwide.

  • 37 job seekers job search // Sep 5, 2014 at 23:31

    Why does your company need to post a job with a hefty fee? Everyone searches on the Internet for jobs. Your company can post on Global Jobs Finds for free for an infinite amount of time.

Leave a Comment