Doug's Linux Notebook

Using Grub

Grub (GRand Unified Boot loader) is a boot loader for Linux and can also load several other OS's. Using Grub is not difficult once you understand how it works.

To use Grub first you must find out if it is installed on your computer. Type man grub at a shell prompt, if the man page for Grub comes up then it is installed, if no man page then it probably is not installed. If you do not have Grub then you can download it from the internet. The Grub home page is www.gnu.org/grub or find it on freshmeat.net. The newest version at the time I am writing this is grub-0.92, compile and install as you would any other program.

After Grub is installed create a new subdirectory named grub in /boot

[root@linux]$ mkdir/boot/grub

Then copy the files in /usr/local/share/grub/i386-pc to /boot/grub

[root@linux]$ cp /usr/local/share/grub/i386-pc/* /boot/grub

Next create a text file named menu.lst in the /boot/grub directory, menu.lst is the configuration file with the boot parameters for Grub. I have seen RedHat use a file named grub.conf as the configuration file and menu.lst as a symlink to grub.conf, which seems rather pointless to me. A typical menu.lst might look something like this.


#grubmenu.lst

timeout 5
default 0
fallback 1
color blue/cyan yellow/magenta

#(0) Windows
title Windows-98
rootnoverify (hd0,0)
chainloader +1

#(1) RedHat
title Red Hat Linux
root (hd1,0)
kernel /vmlinuz ro root=/dev/hdf6 hdd=ide-scsi

#(2) Peanut
title Peanut Linux
root (hd1,7)
kernel /boot/vmlinuz ro root=/dev/hdf8

Now let's break down the menu.lst and see what each line means.

timeout 5 ---- boot the default automatically after 5 seconds
default 0 ---- the default OS to boot
fallback 1 ---- if the default won't boot then boot this -- optional
color blue/cyan yellow/magenta ---- colors for the boot menu screen -- optional

#(0) Windows ---- just a comment to help organize things
title Windows-98 ---- boot menu entry, can be anything you like after "title"
rootnoverify (hd0,0) ---- location of the windows root filesystem
chainloader +1 ---- tells Grub too pass control to the windows boot loader

#(1) RedHat ---- just a comment to help organize things
title Red Hat Linux ---- boot menu entry, can be anything you like after "title"
root (hd1,0) ---- partition containing the kernel, in this case the /boot partition
kernel /vmlinuz root=/dev/hdf6 ro hdd=ide-scsi ---- kernel to boot + kernel parameters

#(2) Peanut ---- just a comment to help organize things
title Peanut Linux ---- boot menu entry, can be anything you like after "title"
root (hd1,7) ---- partition containing the kernel, in this case the / (root) partition
kernel /boot/vmlinuz root=/dev/hdf8 ro ---- kernel to boot + kernel parameters

Grub has it's own way of naming drives, hard disks are all hd, floppy disks are fd, device numbers start from zero, partition numbers start from zero and complete device names are enclosed in parentheses. Also note that Grub addresses only drives that are actually attached to the computer and dose not reserve spaces for drives that are not there. And Grub also ignores CD drives because it dose not consider them to be bootable hard drives.

For example:


Drive

Hardware location

Linux location

Grub location

Hard drive

Primary master

hda

(hd0)

none

Primary slave

hdb

none

Hard drive

Secondary master

hdc

(hd1)

CD Rom

Secondary slave

hdd

none

First primary partition

Primary master

hda1

(hd0,0)

First extended partition

Primary master

hda5

(hd0,4)


In the kernel line there are a couple of things to pay close attention to. If there is a separate boot partition as in (1) above then the kernel is actually in the root directory of that partition "kernel /vmlinuz". If there is no boot partition as in (2) above then the kernel is in the /boot directory of the root partition, "kernel /boot/vmlinuz".

Next tell the kernel where to find the root file system of the OS to be booted, "root=/dev/hdxx" using linux type drive and partition addressing when booting a linux system. Then add "ro" so it mounts the file system read only so fsck can preform it's checks, the kernel will later remount the system read write. Next add any boot parameters, separated by a space, that you wish to pass to the kernel, such as hdx=ide-scsi, or mem=xx, or whatever is needed for your system

Installing The Bootloader

Once the needed files including your custom menu.lst have been copied to /boot/grub you are ready to install the Grub bootloader. The bootloader can be installed to the MBR or to a primary partition that is set active or bootable. This example will install to the MBR of the first hard disk, this is the way to go if you also have Windows installed.

Before proceeding you should make sure you have a good working boot floppy in case something goes wrong. If you do not have one see Make A Boot Disk or skip down and make a Grub floppy first.

At a shell prompt, as root, type grub if you get command not found try typing /usr/local/sbin/grub you should then see something like:

Probing devices to guess BIOS drives. This may take a long time.

Followed by:

GRUB version 0.92 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ]

grub>

At the Grub prompt do the following steps:

grub> root (hd1,0) ---- Where /boot/grub is located

grub> setup (hd0) ---- Where the bootloader will be installed

grub> quit

That's all there is to it, The Grub bootloader is now installed.
Grub is a powerful tool with a command line mode and lots more options than are covered here, for more information try:

[doug@linux]$ man grub

or

[doug@linux]$ info grub

A Grub Boot Floppy

Put a blank floppy in the drive but do not mount it yet:

[doug@linux]$ fdformat /dev/fd0

[doug@linux]$mkfs -t ext2 /dev/fd0

This will low level format the disk then verify the format, and creat the file system, if the verify shows any errors then throw the disk away and try another.

Now mount the floppy and do the following:

[doug@linux]$ mount /dev/fd0

[doug@linux]$ mkdir -p /mnt/floppy/boot/grub

[doug@linux]$ cp /boot/grub/stage* /mnt/floppy/boot/grub

[doug@linux]$ cp /boot/grub/menu.lst /mnt/floppy/boot/grub

[doug@linux]$ umount /dev/fd0

note that some distros use "/floppy" instead of "/mnt/floppy". Now run Grub.


[doug@linux]$ grub

grub> root (fd0)

grub> setup (fd0)

grub> quit

You now have a Grub boot floppy, test it to be sure it works properly.

Back to the Main Page