Sunday, March 21, 2010

Change Default Operating System at Boot for Ubuntu

Suprisingly the solutions to this problem vary wildly. Ubuntu is using the new Grub2 for booting and not too many users know the proper way to change the boot order. However after digging through all the answers I have what I believe is the best solution.

My particular problem is because I just built a new i7 920 system for my grandfather. He paid for Windows 7, but at the last minute I talked him into trying an ubuntu dual boot. Part of this, however is I need windows 7 to be the default choice or he will get frustrated.

Well, here is the adventure. First, the old way to update the boot is by simply modifying menu.lst. This file no longer exists. Then the people who are used to this try updating grub.cfg, because it seems similar to menu.lst. However the system will build a new grub.cfg when it needs to and overwrite any changes.

The closest correct answer is modifying /etc/default/grub and changing GRUB_DEFAULT=0 to the correct number. However this will present problems if the grub list ever grows or shrinks, such as when a new kernel is installed.

I've seen a few other complicated, but unreliable options too. But I'm not going into all the the wrong ways. Lets look at the correct way to change the default boot item.

Step 1, Figure out the exact name of the OS you want to boot. Either write it down when you reboot or type this in a terminal
cat /boot/grub/grub.cfg
Scroll up to find the name. Mine is 'Windows 7 (loader) (on /dev/sda1)'

Copy and paste it or just write it down. Just make sure you get it exact, even the capitalization.

Step 2, open the /etc/default/grub file for editing, here is my favorite command:
sudo nano /etc/default/grub
If you are more of a point and click person try this:
gksudo gedit /etc/default/grub
Step 3, find the line with GRUB_DEFAULT=0 and change the 0 to your OS. Be sure to use double quotes around your OS because it has spaces in the name.
Here is my GRUB_DEFAULT line for my grandfather's computer:
GRUB_DEFAULT="Windows 7 (loader) (on /dev/sda1)"
If you are trying to do this for windows 7, chances are your line will match mine exactly. Be sure to save your file and exit your editor.

Last step! You need to update your grub menu (process the changes we made). Just type into a terminal:
sudo update-grub

That is it. Only 4 steps and a headache saver.

FYI, most of the wrong ways to update grub came from here: http://www.linux.com/community/blogs/changing-the-default-boot-with-ubuntu-910-grub-2.html, though this eventually led me to the right answer. 

No comments:

Post a Comment