http://www.mandrakeuser.org/docs/install/iboot2.html

MandrakeUser.Org - Your Mandrake-Linux Knowledge Base!

 
 

*DocIndex - Installation

Booting GNU/Linux - GRUB

* Advantages Of Using GRUB
* Installing GRUB
* GRUB Configuration
* Booting Other Kernels / Distributions / Operating Systems Via GRUB

Related Resources:

info grub
Multi-Boot with GRUB mini-HOWTO

Revision / Modified: Sept. 19, 2001 / May 14, 2002
Author: Tom Berger

 

* Advantages Of Using GRUB

LiLo (Linux Loader) is the standard GNU/Linux boot loader, usually installed at system installation time. Despite its name, you may use it for booting other operating systems on the same or other system disks, too.

Since ML 7.1, you can use GNU GRUB, the GRand Unified Bootloader, instead. It has several advantages over LiLo:

  • The possibility to edit boot parameters at boot time.
  • A small boot shell.
  • Support for the 'hidden' flag which comes in handy, if you have multiple MS-DOS/Windows primary partitions.
  • The configuration file ('/boot/grub/menu.lst') allows changes 'on the fly'. No extra installation step after editing needed.
  • Booting disk-less clients over a network.

The only - minor - drawback is that GNU GRUB uses it's own syntax, but you will see that it is very easy to grasp. But I think most people will prefer LiLo because of the fancy boot screen it offers ;-). If you prefer function over form, however, read on.

* section index * top

* Installing GRUB

First check if GRUB is already installed with rpm -q grub. If it isn't, install it using urpmi grub.

Having done this, issue (as 'root') the command:

grub-install /dev/[device]

'device' is the name of the device whose boot sector should be used. In most cases this will be 'hda', i.e. the master boot record of the first IDE hard drive.

You should get a message like this:

[some text]
(fd0) /dev/fd0
(hd0) /dev/hda

This lists the bootable device GRUB has found: a floppy drive on the first controller and a disk at the first IDE master channel. Of course this may look different on your machine. The first field denotes GRUB's syntax, the second the syntax Linux uses to describe a device. GRUB doesn't discriminate between SCSI and IDE hard-disks, it just takes their boot-order into account. Thus an entry on a system with one SCSI disk:

(fd0) /dev/fd0
(hd0) /dev/sda

And on system with one SCSI and one IDE hard drive where the BIOS is set to boot from the SCSI drive:

(fd0) /dev/fd0
(hd0) /dev/sda
(hd1) /dev/hda

If you change the boot order between the disks, you will have to edit '/boot/grub/devices.map' to reflect the change.

In case the 'grub-install' script should fail, you can install the boot sector from within the GRUB shell:

grub
[some text]
grub> root (hdw,x)
[some text]
grub> setup (hdy,z)

'w', 'x', 'y' and 'z' are numbers. 'w' signifies the hard disk, 'x' the partition on which the '/boot/grub' directory is located, 'y' the hard disk where the boot sector should be installed and 'z' is necessary if you want to install the boot sector to a partition and not to the master boot sector of 'y'. It is important to note that GRUB always starts counting from '0'.
Example 1: Install GRUB to the master boot record of the first IDE disk. The '/boot' directory is on the same disk, on /dev/hda3.

grub> root (hd0,2)
grub> setup (hd0)

Example 2: Install GRUB to the boot sector of a root partition. This root partition is located on a SCSI hard disk, booted from after an IDE disk and is located on '/dev/sda1'.

grub> root (hd1,0)
grub> setup (hd1,0)

Basically, that's it. Reboot and you will be presented with a grub> prompt. Type help to get a listing of the available commands (yes, GRUB gives you a fully-fletched boot shell, complete with commandline history and auto completion!), and help [command] to get help for a specific command.

Well, but how to boot Linux? Obviously you will have to tell GRUB where it should look for the root partition and the kernel. And then you have to append a parameter telling Linux' init where to find its kernel (remember, GRUB and Linux uses different syntaxes!). This is what Grub's kernel command is for. Assuming the root partition is the first primary partition on an IDE drive:

kernel (hd0,0)/boot/vmlinuz root=/dev/hda1

Can't remember on which partition your kernel was? Easy: find /boot/vmlinuz will tell you. Now type boot, hit ENTER and your system will boot.

OK, that may be nice for the first time, but there sure is a way to make this more comfortable? Read on ...

* section index * top

* GRUB Configuration

GNU GRUB's configuration file is '/boot/grub/menu.lst'. You can edit or create it either by loading it into an editor, or by using the 'DrakBoot' tool in 'DrakConf' (Mandrake Control Center). In contrast to 'LiLo', you don't have to run any command after editing. To get an overview on available GNU GRUB commands, just start a GNU GRUB shell as 'root' by typing

grub

on a virtual terminal. Then type help to list commands and help [command] to get help on a specific command. For more extensive documentation, have a look at info grub as well.

Like 'lilo.conf', 'menu.lst' consists of a general section and of entries for the several operating systems /distributions / kernels you want to boot. A typical general section may look like this:

timeout 5
color black/cyan yellow/cyan
i18n (hd0,0)/boot/grub/messages
keytable (hd0,0)/boot/us.klt
default 0

This tells GRUB:

  • to wait five seconds before booting the default entry,
  • which colors to use in the boot menu,
  • which boot messages file to use,
  • which key table to use (generated by keytab-lilo.pl [key map] > [file]),
  • which entry to boot by default.

(hd0,0) denotes the first partition on the first hard disk. The first hard disk is the disk you boot from, either IDE or SCSI. GNU GRUB counts the disk by their place in the boot order, starting from null. So if you have an IDE and a SCSI disk on your system, the first will be which your system is set up to boot from, the other will be the second. If you have more than one IDE or SCSI disk, the numbering depends on the place of the place of the disk of the controller: either the IDE channel and port (first disk on first port, second disk on first port etc), or the SCSI ID.
Partition numbering also starts with null. Note that the first logical partition is always '4', regardless of how many primary partitions are actually on the disk.

An entry for Linux would look like this:

title Linux
kernel (hd0,0)/boot/vmlinuz root=/dev/hda1

The title field marks the name under which this entry will appear in the boot menu. kernel (hd0,0)/boot/vmlinuz-[...] tells GNU GRUB to load a kernel with the name 'vmlinuz-[...]' in the directory '/boot' from the first partition of the first disk. root=/dev/hda1 is a boot parameter for init, which basically says the same, but this time using a syntax init can understand. You can append any boot parameters you need or want.

* section index * top

* Booting Other Kernels / Distributions / Operating Systems Via GRUB

Other Kernels

Create another entry like the one above (with a different 'title', of course).

Other Linux Distributions

Install LiLo to the boot sector of the root partition (not the MBR) of that distribution. Add an entry like the one discussed in the next paragraph to your '/boot/grub/menu.lst' on your Mandrake Linux system.

Other Operating Systems

An entry for operating systems like DOS, BeOS, Win9x/NT or OS/2 looks a bit different:

title Windows
rootnoverify (hd0,0)
makeactive
chainloader +1

rootnoverify (hd0,0) tells GNU GRUB where your Windows 'C: drive' is, but not trying to mount it ('noverify', optional). makeactive sets the 'active' flag in the partition table, needed by some old versions of DOS/Windows to boot correctly. chainloader +1 tells GNU GRUB not to try to load Windows by itself (which it can't), but instead hand over the boot process to the first sector of 'C:', which contains the native DOS/Windows boot code.

Onto floppy

(Contributed by Marc Indekeu)

The following is a grub install to a floppy for emergency purposes. It's done with grub installed on my MDK 8.1 system and '/mnt/floppy' is the mountpoint for my floppy.

  1. Insert empty floppy into drive and create a directory with the name 'boot' on that floppy.

  2. Copy the contents of your '/boot/grub' directory to that floppy:

    cp -R /boot/grub/ /mnt/floppy/boot/

  3. Start the 'grub' configuration shell as 'root' with:

    grub

  4. Inside the shell, run these two commands to make the floppy bootable:

    root (fd0)
    setup (fd0)

  5. Enter quit to exit the grub shell.

info grub contains example configurations as well as such fun stuff as booting MS operating systems from disks other than the first or from multiple primary partitions.

* section index * top

* Other boot loaders, uninstalling

 
Legal: All texts on this site are covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB (Tom Berger) and Mandrakesoft 1999-2002.