oreilly.comSafari Books Online.Conferences.


Top Five Open Source Packages for System Administrators
Pages: 1, 2

Some GRUB Recipes

We're now ready to look at the GRUB configuration file (grub.conf). Here are some sample lines from its first, general section:

# general section
splashimage (hd0,0)/grub/splash.xpm.gz   Pretty picture behind the menu. 
default 0                    Default boot entry (numbering starts at 0).
timeout 30                               Menu timeout period in seconds.
password -md5 xxxxxxx             Use grub-md5-crypt to encode password.

These lines specify the image displayed behind the boot menu, the menu timeout period and default entry to boot, and the boot password.

The remainder of the file specifies the items on the boot menu. Here are two examples that boot the Linux operating system on the first partition on the first hard disk (selecting different kernels):

title Linux
   root (hd0,0)
   kernel /vmlinuz ro root=/dev/hda2
   initrd /initrd.img

title Test-Linux
   root (hd0,0) 
   kernel /vmlinuz-test ro root=/dev/hda3
   initrd /initrd.img-test

The title lines indicate the menu item text. The root lines specify the partition where the boot loader is located. All directory references are assumed to be relative to the root of this partition. Thus, the location of the vmlinuz files specified in the kernel lines is in the root directory of this partition.

The kernel lines specify the path to the Linux kernel in each case, along with any parameters to be passed to it. In this case, a separate /boot partition is being used, so the root parameter is passed to the kernel; the latter indicates the location of the system root directory (such as /). Thus, we can tell that the kernel images reside at /boot/vmlinuz* from the point of view of the booted Linux system. The initrd lines similarly specify the path to the initrd.img file (if used).

Booting FreeBSD is also very simple:

title FreeBSD
   # use the 1st BSD subpartition in disk 1 partition 3
   root (hd0,2,a) 
   kernel /boot/loader

Related Reading

Essential System Administration Pocket Reference
Commands and File Formats
By Æleen Frisch

This stanza again specifies the boot partition and locates the FreeBSD final-stage boot loader. This is the recommended practice (rather than directly invoking the FreeBSD kernel).

This stanza defines a bootable Windows partition:

title Win2K
   root (hd0,2) 
   chainloader +1

The boot partition is specified in the usual way. The makeactive command activates the partition, and the chainloader command hands off the boot process to local boot loader (for example, NTLDR).

In general, GRUB can boot operating systems on any disk. However, in some cases, it is easier to boot non-Unix operating systems on the second hard disk if you logically "swap" the first two drives. GRUB uses entries like these to do so:

map (hd0) (hd1)
map (hd1) (hd0)

GRUB also has the nice feature of remembering what operating system was last booted and making it the default for the next time. To enable this capability, set the default entry to saved (in the general section), and add a savedefault directive to the end of each stanza:

title Linux

Installing GRUB

Once you've created the configuration file, installing GRUB is very easy. It is done with the grub-install utility that is included with the package. This tool has the following general syntax:

# grub-install [--root-directory=/dir] disk

where disk is the boot partition, specified in either GRUB's format or the local format (for example, (hd0) or /dev/hda, etc.).

The --root-directory option specifies the directory location of a separate boot partition (for example, /boot under Linux).

For more information about GRUB, consult the following:

If you liked this article and would like to receive the free ESA3 newsletter, you can sign up here.

Æleen Frisch has been a system administrator for over 20 years, tending a plethora of VMS, Unix, Macintosh, and Windows systems. If you liked this article and would like to receive the free ESA3 newsletter, you can sign up at

O'Reilly & Associates recently released (August 2002) Essential System Administration, 3rd Edition.

Return to

Sponsored by: