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!
12 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.
Leave a Comment