GRUB was originally written by Erich Stefan Boleyn and is now part of the GNU project. The current production version is GRUB 0.9x, also known as GRUB Legacy. In 2002 the developers shifted their focus to GRUB 2 and stopped adding features to the legacy code, though it still receives regular patches and bug fixes. GRUB 2 remains a development version; most distributions still rely on GRUB Legacy.
GRUB is not dependent upon any operating system. It was written to conform with the Free Software Foundation's Multiboot Specification, which allows it to boot almost any operating system. In fact, it can boot multiple operating systems on computers that have more than one installed on their hard drives. Among GRUB's features:
- Dynamic configuration. Users can change settings and parameters at boot time.
- Support for multiple executable formats and hard drive filesystems.
- Both a graphical and command-line interface to let users choose what operating system to boot.
One common task preformed by GRUB in the Linux world -- besides booting the kernel -- is to allow users to dual boot Linux and Microsoft Windows. The typical pattern for creating a dual boot system is to install Windows, if it is not already installed, then install Linux on another hard drive or on an empty partition. Most Linux distributions will detect the Windows installation and automatically install and configure an open source boot loader -- such as GRUB or LILO -- to boot both Linux and Windows, replacing the Windows bootloader.
Most Linux distributions that use GRUB come with it installed and ready to use. Many of the distributions that do not have GRUB installed by default have it available in their package systems; check there first before doing a manual installation.
If you have a different bootloader already installed, you really don't need to replace it with GRUB unless a specific operating system that you are trying to use that is not supported by your installed bootloader.
If something goes wrong during your attempted GRUB install you can cause your computer not to boot. You should not apply the instructions that follow to your primary hard drive (/dev/hda, or /dev/sda if you have a SCSI hard drive) unless you know what you are doing. Instead, try them first on a USB or diskette drive first.
To do a manual installation you need to download GRUB from the GNU Web site; make sure you get the Legacy branch. Once you have the package, unpack, build, and install it with the commands:
tar -xzvf grub-0.9x.tar.gz
sudo make install
The last step needs to be performed by the root user, hence the
sudo command. If all goes well, GRUB will be installed and ready to use. If you have issues building or installing, consult the GRUB FAQ or the GRUB wiki to get help.
Configuring the GRUB menu
Most users will want GRUB to automatically boot a specific operating system, or present them with a way to select what system they want from among all that are installed on the hard drive. That is the function of the GRUB menu -- a configuration file called menu.lst that goes into the "grub" directory on the drive on which GRUB is installed. If GRUB finds this file during boot it will automatically load the menu.
The file is just a plain text file with a set of directives and configuration parameters. The file below is an abbreviated version of the default menu.lst file from the Ubuntu 7.04 release.
default 0 timeout 3 hiddenmenu title Ubuntu, kernel 2.6.20-15-generic root (hd0,0) kernel /boot/vmlinuz-2.6.20-15-... ro quiet splash initrd /boot/initrd.img-2.6.20-15-generic
- default specifies which entry is the default. An entry comprises, at least, title, root, and kernel directives. Entry numbers start at 0 and increment upward.
- timeout specifies how long, in seconds, the menu will be displayed before the default entry is executed.
- hiddenmenu means that the menu is not displayed. This parameter is used to automate the boot process without asking the user what to do.
- title is the text that is displayed in the menu for the entry that follows.
- root tells GRUB on what device and partition it can find the kernel for this entry.
- kernel specifies what kernel will be booted if this entry is selected. Options after this directive are passed to the kernel for processing. Here,
romeans read-only (the device is not physically made read-only; it just tells the kernel not to attempt writing),
quietinidcates do not display debug information, and
splashmeans show a splash screen while booting.
- initrd tells GRUB what to run after the kernel has been loaded. When this directive is executed, GRUB passes off control of the system to the operating system.
You can set several other parameters here. It is possible to specify a color scheme, underlay a splash image, and even specify a boot-time password to protect the menu. Consult the GRUB documentation for a complete list of available commands.
If you need to have GRUB boot Windows you can use the following entries into the menu configuration file. The example provides GRUB with the instructions to boot a Windows 2000 installation on the primary hard drive.
title Windows 2000 unhide (hd0,0) hide (hd0,1) hide (hd0,2) rootnoverify (hd0,0) chainloader +1
With GRUB you can boot a customized Linux distribution directly from a USB drive; boot embedded devices automatically; or simply build machines that allow users to select what distribution or operating system they want to use.
Chad Files, a software developer and writer, has been developing software applications for more than 10 years, and is a contributing developer to many open source projects. Recently he has been using GRUB to boot embedded Gentoo media jukebox devices.