Mandriva

Booting GNU/Linux - GRUB

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. This is very handy if, for example, you play with some parameters that are essential at booting. Let's say that you modify the NOACPI option in ~LiLo and thereafter you are unable to get into linux. As you cannot modify boot parameters at boot time, if you use ~LiLo you will need a bootable disk, mount the partitions and change the parameters.
  • 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

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 completion1.1 ), 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 syntaxes1.1 ). 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

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<br> color black/cyan yellow/cyan<br> i18n (hd0,0)/boot/grub/messages<br> keytable (hd0,0)/boot/us.klt<br> 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 &#123;key map&#125; > &#123;file&#125;
    ),
  • 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<br> 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-&#123;...&#125;
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.

An usefull parameter is PROFILE that allows to boot a specific profile (defined in the Mandrake Control Center). This is particularly interesting in the case of a laptop used in different network environments (for example DHCP and static IP allocation), in this case you have the possibility to chose the right profile at boot-time. An entry booting a profile called dhcp would look like this:

title Linux<br> kernel (hd0,0)/boot/vmlinuz root=/dev/hda1 PROFILE=dhcp

For a linux entry it is sometimes needed to preload some modules of the kernel. In this case a compressed image disk is used to load in RAM the desired modules and is oftenly called initrd. In this case a third line is to be added to the simplest case described earlier and would look like this:

title Linux<br> kernel (hd0,0)/boot/vmlinuz root=/dev/hda1<br>initrd (hd0,0)/boot/initrd.img

section index

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 Linux Distributions on an USB hard drive

If you want to boot a distribution installed on an USB drive and if the bios of your computer don't allows to boot on USB, one can build a custon initrd image including modules needed to mount partitions of your USB hard drive. This can be done using the program mkinitrd with root privileges and can be done booting in rescue mode using an instalation CD or even from your primary linux distribution. You have to mount the partition containing the root partition of the distribution installed on USB, link the /dev of this partition to the one of your running distribution, then you can chroot the distribution on USB, assuming directory /mnt/hdusb1 already exist, this can be done with root privileges using the following three commandlines:

mount /dev/sda1 /mnt/hdusb1<br>mount -o bind /dev /mnt/hdusb1/dev<br>chroot /mnt/hdusb1

In the chrooted environment you can now build the customized initrd, if you intend to use kernel 2.6.8.1-12mdk the full command line would look like this:

mkinitrd &#150;&#150;preload=ehci-hcd &#150;&#150;preload=usb-storage &#150;&#150;preload=scsi_mod &#150;&#150;preload=sd_mod /boot/usbinitrd.img  2.6.8.1-12mdk

This will create the compressed image disk /boot/usbinitrd.img. You can now exit the chroot environment and copy the initrd image usbinitrd.img and the kernel to the /boot directory of the root partition of your running distribution:

cp /mnt/hdusb1/boot/vmlinuz /boot/vmlinuz-usb<br>cp /mnt/hdusb1/boot/usbinitrd.img /boot

Assuming that your distribution is installed using two partitions: root partition on the first partition and home on the sixth partition, an entry that would boot this distribution on USB would look like this:

title linux_on_USB <br>kernel (hd0,0)/boot/vmlinuz-usb root=/dev/sda1 resume=/dev/sda6<br>initrd (hd0,0)/boot/usbinitrd.img

If your computer contains a SATA hard drive, you may have to replace /dev/sda* by /dev/sdb* as /dev/sda will be used by tha SATA drive.

Other Operating Systems

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

title Windows<br> rootnoverify (hd0,0)<br> makeactive<br> 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.

  • Insert empty floppy into drive and create a directory with the name 'boot' on that floppy.
  • Copy the contents of your '/boot/grub' directory to that floppy:
cp -R /boot/grub/ /mnt/floppy/boot/
  • Start the 'grub' configuration shell as 'root' with:
grub
  • Inside the shell, run these two commands to make the floppy bootable:
root (fd0)
setup (fd0)
  • 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

Next Item: Other boot loaders, uninstalling

Related Resources:

info grub

Multi-Boot with GRUB mini-HOWTO

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

Legal: This page is covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB and Mandrakesoft.

KB - Booting GNU/Linux - GRUB
Versão a ser apresentada 1.19 last modified by ptyxs on 26/11/2006 at 15:31

 


en pt fr

RSS

Criador: AdminWiki on 2004/03/22 09:44
(c) Mandriva 2007
18888888