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! 🙂
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.
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?
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!
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!
A much easier way to do this is to install Start up manager through synaptic…
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.
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!
@martin:
Thanks! Your suggestions are now reflected in the revised text 🙂
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
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.
Thanks!
Perfect!
Boby
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.
Pingback: ncatarino.net – Stuff I added on top of my default Ubuntu install
Worked perfectly, thanks.
Thanks for the clear instructions.
Great! Thank you!
Just what i need! Thank you and keep up the good work. stay classy…
Your post really helped me to reconfigure grub2 default menu item selection. Thank you.
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) :)))
Pingback: Grub 2 Fixes » Solo Technology
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/
It worked 😀 thank you sooooooooooooo much
Really nice, Thanks for this
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.
Thanks Action Parsnip!
THIS worked for me:
sudo mv 30_os-prober 08_0s-prober
sudo update-grub
(StartUp Manager affects nothing FSDR)
Brilliant! Thanks very much!
Thanks, that is what i need.
Thanks, this is what I was looking for!
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.
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
On typing
sudo update-grub
It displays –
/etc/default/grub: Syntax error: “||” unexpected
How to resolve this ?
Hello Ankit, you should take a look at /etc/default/grub, e.g.
sudo vi /etc/default/grub
and look for syntax errors.
Pingback: How do I set Windows to boot as the default in the boot loader?