Configuring the GRUB boot loader on linux systems
assembly date
2007, September 12.
author(s)
Balla Marcell
keywords
- boot
- config
This article discusses the configuration of the GNU GRUB boot loader. It is intended to teach you how to maintain your system boot up sequence.
GRUB (full name: GNU GRUB) is a boot loader and is thereby the first program that is executed when your computer starts. The boot loader is responsible for loading the desired operating system (e.g. Linux).
GRUB is a practical boot loader, because it understands many filesystem types and can access and load kernels with ease - you only have to tell GRUB on which partition the kernel resides and what the name of the file to load is. For proprietary systems (like Windows or DOS) the boot loader makes use of the so called "chain loading" procedure. It means that GRUB loads another boot loader to ensure safe boot up of the operating system.
GRUB also offers you a menu interface to select the operating system you want to boot. This menu is based on a configuration file.
Firstly you will learn how to set up GRUB as the boot loader of your choice.
Many Linux based operating systems today offer to install and configure GRUB as the boot loader during their setup. In this case you don’t have to install GRUB manually.
If you are not one of the lucky guys, you should download the newest version from the GNU GRUB download page (see related links at the top). Once you have downloaded the boot loader (usually a tarball = zipped TAR file) you install it by opening a unix shell and entering the following commands (in this example "grub-1.95.tar.gz" is the name of the downloaded tarball):
tar xzvf grub-1.95.tar.gz
cd grub-1.95
./configure
make
make install
Note: You have to be in the directory where your downloaded tarball is located. Moreover you have to be the super user to execute the last command.
Now we have installed the boot loader but GRUB is not yet our boot loader at boot time. We need to set up GRUB first. To do this you need to be the super user and execute the command called "grub-install". As parameter you need to supply the device name of the disk where you want GRUB to be installed (in this example the first hard disk):
grub-install /dev/hda
This command should create a directory called "grub" in the "boot" directory of your root partition (full directory name is "/boot/grub") and install GRUB to the boot record of the disk that you have supplied as argument. To understand things better it is good to know that the "/boot" directory is the one where Linux distributions store their bootable kernel files by default.
Note: If you have a separate boot partition you need to tell GRUB the location of the partition by adding the "--root-directory=/yourpartition" argument to the grub-install command.
The next thing to do is to create a configuration file with predefined entries so that you can choose an operating system to boot from the GRUB menu at boot up time. For this you need to create a file called "menu.lst" in the directory where GRUB is located (e.g. /boot/grub).
But don’t worry since GRUB has a utility that will automatically create this configuration file for you. It looks for kernel images in your "/boot" directory (the files that start with "vmlinuz-") and creates/updates your menu.lst file. The command you need to execute is:
update-grub
The entries in your menu configuration file consist of several command lines with the leading words title, root, kernel, boot etc. Let’s have a look at an example file to explain the command lines. Figure 1 shows such a file.
Figure 1: example menu.lst file contents
The lines starting with "title" are used to give a title to the menu entry. You will see this text in the GRUB boot menu when you boot your system. The lines starting with "root" are used to set the root filesystem location for GRUB (you can omit this by entering the location in front of the "kernel" command). The lines starting with "kernel" are used to load the bootable kernel of the operating system. Things like "(hd0,13)" define the drive and the partition in the GRUB format. hd0,13 tells GRUB to use the 1st hard disk (counting starts at 0) and its 14th partition (counting also starts at 0 here) to finally find the kernel image at the supplied location.
Note: In the example figure above some kernel commands are followed be other parameters inline. These parameters are kernel command line parameters and evaluated by the kernel itself! Partitions supplied as parameter for the kernel and root command are usually the same unless you have a separate boot partition which stores the kernel boot images (like mentioned above).
You can find the full list of available GRUB menu commands here
Note: In some BIOS versions changing the booting hard disk also changes the physical numbering of the hard disks! So "hd0" might correspond to "hdb" and "hd1" to "hda" for example! In such a case you have to manually change the hard disk part of the generated "root" entries in the "menu.lst" file, because GRUB will generate them according to their true order (master first, slave second)! In the case of windows being on a different (e.g. the second) hard disk, you might also have to map the drives to successfully boot windows, because the contents of the "boot.ini" file also don’t fit anymore. Use the "map" GRUB command to do this (check the link to the menu commands above for an example).
Note: The menu command "boot" is used to boot the kernel. Nevertheless the command doesn’t show up in our example, since it is automatically executed by GRUB for each entry.
Once you have created this file and are satisfied with its content you can reboot your system. Having rebooted you should see the GRUB boot menu. Figure 2 shows a picture of our boot menu example.
Figure 2: example GRUB boot menu
The last four entries in Figure 2 correspond to the entries in the menu.lst file in Figure 1. The menu in our example has blue background and light-gray text color. This was achieved by changing the color in the menu.lst file as follows:
# change the color (foreground/background for text and highlighting)
color light-gray/blue blue/light-gray
For security issues during boot up and how you can deal with them using GRUB, you might want to have a look here.
To sum it up the most important things to know are:
- You install GRUB with the "grub-install" command followed by the target hard disk
- The menu.lst file stores the entries of your GRUB boot menu
- You can auto-create your menu.lst file with the "update-grub" command
- To insert a new entry in the boot menu you insert GRUB menu commands (like title, root, kernel etc.) into your menu.lst file

GNU GRUB Manual
GNU GRUB FTP download page