Please Note: This is the fourth article in a series about Ubuntu. I go into great detail about simple items on the assumption that these articles are being read in order by first time Ubuntu users. Feel free to skip around if you already know how to do certain things. This was written in reference to Ubuntu version 8.04.
When you installed Ubuntu (or just about any Linux variant for that matter), a boot loader was likely installed as well. The boot loader, as the name implies, is the program that makes the operating systems installed on your computer boot up. It can be installed on a floppy (does anyone still use those?), a CD (the Ubuntu LiveCD has one built in), a USB flash drive, or just about any type of removable media. The most common place to install the boot loader is your computer's hard drive.
The boot loader is installed in a special place on the hard drive called the Master Boot Record (hereafter to be referred to as the MBR). When your computer powers on, it does a series of tests called the Power On Self Tests (POST). These are the messages you see immediately when you turn your computer on and they often list your computer's main hardware. Once this is done (it takes about 1 to 5 seconds), the computer checks the boot order you have selected in the BIOS settings and attempts to boot from that device. If it is your hard drive (and it most often is), the computer looks at the MBR and executes whatever program is there.
When Windows is installed, it automatically installs a program into the MBR that boots Windows. This is completely invisible to the user and most people don't even know it exists (until something happens to it). When Ubuntu is installed, it installs a boot loader into the MBR called GRUB (GRand Unified Boot loader). GRUB allows you to boot any number of installed operating systems by presenting you with a menu. It will also automatically boot the first operating system in the list after a certain period of time. By default Ubuntu lists itself as the first operating system, but I suspect many new users might prefer that Windows be first. So here is how you change the boot menu in grub.
Warning: Command line usage is ahead!
Grub menu configuration (as with most GNU software) is done through the editing of a text file. To edit that file we first need to open the terminal. Click on Applications >> Accessories >> Terminal.

The terminal gives you access to the command line and is something you may or may not use very often. It's good to know where it's at though and now you know. The terminal gives you a simple prompt consisting of your login name, the computer name, the current working directory (in this case it will be a ~ which represents your home directory i.e. /home/username), and a dollar sign. Then there is a flashing cursor where the fun begins!

Important: The Linux command line and file system is case sensitive. This means that foo is completely different from Foo or foO or FOO. Also, it is not appropriate to put spaces in file names in Linux. Linux can handle it, but not very well. Instead you should use an underscore or dash and save yourself a lot of trouble.
The first thing you want to do at the command line is save a backup of the grub menu configuration file. If the worst happens and you manage to mess up the file, we can can simply restore from backup.
At the prompt, type the following and hit Enter:
cd /boot/grub
The cd command changes directories. Directory is just another name for a folder. /boot/grub is the location we are changing to. So this is the grub directory within the boot directory, which is within the root file system. Note that the directories are separated by forward slashes and not backslashes like in Windows. In Windows this directory location might look like this- C:\boot\grub.
Once you execute this command, your prompt will change to indicate your new location within the directory structure. Now let's take a look at the files in the grub directory, type the following:
ls
That was simple. The ls command lists the files in a directory. There are several files, but we are looking for one called menu.lst so that we can make a backup. Yup, there it is, let's make a backup copy. Type:
sudo cp menu.lst menu.lst.backup
You'll be asked for your password, enter it. The sudo command lets the system know that you wish to execute the following commands as the administrator. If you do not use sudo, you will not be able to edit files owned by the root account. In this example, the /boot/grub directory is owned by the root account, so we wouldn't be able to write files to it without administrator privileges. The root account is the superuser account within Linux. By default, Ubuntu does not allow you to directly log in as root as the potential for damaging your installation is great.
The cp command copies a file from one location to another. In this case we are copying the location to the same directory, but changing the name. Any time you use cp, you'll type the file you want to move first, then you will type the location you want to copy it to, or the name of the new file, or a combination of both if you want to copy it and change the name as well. You can name your backup file whatever you wish as long as it doesn't contain any spaces or other weird characters. Try to just use numbers, letters, dashes, underscores, and periods. I just added a period and backup. It's often a good idea to put the date and even time in the backup name in case you need to create multiple backups.
Now we are finally ready to start editing the grub menu. At the prompt type the following:
sudo gedit /boot/grub/menu.lst &
We've already went over the sudo command. You may or may not be asked for your password again. If it asks, just enter it again. The gedit command opens the text editor gedit, the Ubuntu equivalent to Notepad. /boot/grub/menu.lst is the location and name of the file we are editing. The "&" means that this program will be run as a background process and will return you to the command prompt once gedit opens. If you did not use the "&" gedit will open and you will not get a new command prompt until you close it. Also, if you do not use "&" and you close the terminal, it will also close gedit.
In gedit you will see a text file with a bunch of "#" symbols in it. These are usually called hash marks or hashes. Grub treats everything after a hash mark on a single line as a comment and ignores it when it executes. There are a lot of things we can edit in the file, but for now we will just concentrate on making Windows first on the boot list. Scroll all the way to the end of the file and your Windows entry should be there. It will look something like the following although your details may differ depending your hardware and Windows version:
### END DEBIAN AUTOMAGIC KERNELS LIST
# This is a divider, added to separate the menu items below from the Debian
# ones.
title Other operating systems:
root
# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title Microsoft Windows XP Home Edition
root (hd0,0)
savedefault
makeactive
chainloader +1
First you want to comment out the divider listing. Since we will be moving the Windows entry to the top we don't need it (not that we needed it in the first place). Just add hash marks to the lines that start with the words title and root after the lines. It will look like this afterwards:
# This is a divider, added to separate the menu items below from the Debian
# ones.
#title Other operating systems:
#root
Now we need to move the Windows entry to the beginning of the list. Select the entire Windows entry including the comments and copy it to the clipboard. We need to insert it BEFORE the automagic kernels list so look for the following line which is near the middle of the file:
### BEGIN AUTOMAGIC KERNELS LIST
Paste the entry into the file BEFORE this line. It will look similar to the following:
#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST
# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title Microsoft Windows XP Home Edition
root (hd0,0)
savedefault
makeactive
chainloader +1
### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below
Now go back to the bottom of the file and select and delete the Windows entry there. You can also just comment it out with hash marks in front of each line if you wish. Now you should save the file and reboot to see if it works. It should since it worked for me!
If it didn't work, your computer may not be able to boot to the hard drive. You will need to boot from the Ubuntu LiveCD to fix it so have one handy. Extensive documentation on how to do this can be found at the Ubuntu help site, but here are the basic instructions:
- Boot to the Ubuntu LiveCD as if you were going to try Ubuntu for the first time.
- Open a terminal window as mentioned above.
- Type grub at the prompt and you should get a short message and a grub prompt.
- Type find /boot/grub/stage1 and make a note of the results.
- Type root (hd0,4) substituting the results from step 4.
- Type setup (hd0) substituting the hard drive number you obtained from step 4.
- Quit grub by typing quit.
- Reboot and you should be able to boot into Ubuntu.
To restore the original menu.lst file from the backup we made simply follow these instructions:
- Open a terminal window.
- Type cd /boot/grub
- Type sudo rm menu.lst
- Type sudo mv menu.lst.backup menu.lst
In step 3 we used the rm command. This command deletes files (rm stands for remove). In step 4 we used the mv command. This is actually the move command which moves something from one place to another. It can also be used to rename a file as we did above, just type mv then the name of the file to be renamed and then the name you want to rename it as. We could have also used the cp command again in place of mv if we wanted to keep the same backup copy.
For more detailed information about grub, visit the grub manual page online or type man grub at the command prompt.
Joseph Bales is a writer of fiction and humor, as well as a true computer geek and Linux guru. Visit his blog at josephbales.com.


