[ << ] [ < ] [ Home ] [ > ] [ >> ]


9. Configuring the Bootloader

Content:

9.a. Making your Choice

Introduction

Now that your kernel is configured and compiled and the necessary system configuration files are filled in correctly, it is time to install a program that will fire up your kernel when you start the system. Such a program is called a bootloader. For x86, Gentoo Linux provides GRUB and LILO. But before we install one of these two bootloaders, we inform you how to configure framebuffer (in case you want it of course). With framebuffer you can run the Linux command line with (limited) graphical features (such as using the nice bootsplash image Gentoo provides).

Optional: Framebuffer

If you have configured your kernel with framebuffer support (or you used genkernel's default kernel configuration), you have to add a vga-statement to your bootloader configuration file if you require framebuffer. The next table lists the available vga-values you can use. In the example configuration files we use 800x600 @ 16bpp, thus 788.

640x480 800x600 1024x768 1280x1024
8 bpp 769 771 773 775
16 bpp 785 788 791 794
32 bpp 786 789 792 795

Remember (or write down) your value; you will need it shortly hereafter.

Now continue by installing GRUB or LILO.

9.b. Default: Using GRUB

Understanding GRUB's terminology

The most critical part of understanding GRUB is getting comfortable with how GRUB refers to hard drives and partitions. Your Linux partition /dev/hda1 is called (hd0,0) under GRUB. Notice the parenthesis around the hd0,0 - they are required.

Hard drives count from zero rather than "a" and partitions start at zero rather than one. Be aware too that with the hd devices, only hard drives are counted, not atapi-ide devices such as cdrom players and burners. Also, the same construct is used with scsi drives. (Normally they get higher numbers than ide drives except when the bios is configured to boot from scsi devices.)

Assuming you have a hard drive on /dev/hda, a cdrom player on /dev/hdb, a burner on /dev/hdc, a second hard drive on /dev/hdd and no SCSI hard drive, /dev/hdd7 gets translated to (hd1,6). It might sound tricky and tricky it is indeed, but as we will see, GRUB offers a tab completion mechanism that comes handy for those of you having a lot of hard drives and partitions and who are a little lost in the GRUB numbering scheme.

Having gotten the feel for that, it is time to install GRUB.

Installing GRUB

To install GRUB, let's first emerge it:

Code listing 1: Installing GRUB

# emerge grub

To start configuring GRUB, you type in grub. You'll be presented with the grub> grub command-line prompt. Now, you need to type in the right commands to install the GRUB boot record onto your hard drive.

Code listing 2: Starting the GRUB shell

# grub

Note: If your system does not have any floppy drives, add the --no-floppy option to the above command to prevent grub from probing the (non-existing) floppy drives.

In the example configuration we want to install GRUB so that it reads its information from the boot-partition /dev/hda1, and installs the GRUB boot record on the hard drive's MBR (master boot record) so that the first thing we see when we turn on the computer is the GRUB prompt. Of course, if you haven't followed the example configuration during the installation, change the commands accordingly.

The tab completion mechanism of GRUB can be used from within GRUB. For instance, if you type in "root (" followed by a TAB, you will be presented with a list of devices (such as hd0). If you type in "root (hd0," followed by a TAB, you will receive a list of available partitions to choose from (such as hd0,0).

By using the tab completion, setting up GRUB should be not that hard. Now go on, configure GRUB, shall we? :-)

Code listing 3: Installing GRUB in the MBR

grub> root (hd0,0)          (Specify where your /boot partition resides)
grub> setup (hd0)           (Install GRUB in the MBR)
grub> quit                  (Exit the GRUB shell)

Note: If you want to install GRUB in a certain partition instead of the MBR, you have to alter the setup command so it points to the right partition. For instance, if you want GRUB installed in /dev/hda3, then the command becomes setup (hd0,2). Few users however want to do this.

Although GRUB is now installed, we still need to write up a configuration file for it, so that GRUB automatically boots your newly created kernel. Create /boot/grub/grub.conf with nano (or, if applicable, another editor):

Code listing 4: Creating /boot/grub/grub.conf

# nano -w /boot/grub/grub.conf

Now we are going to write up a grub.conf. Beneath you'll find two possible grub.conf for the partitioning example we use in this guide, with kernel image kernel-2.4.26-gentoo-r6. We've only extensively commented the first grub.conf. Make sure you use your kernel image filename and, if appropriate, your initrd image filename.

Code listing 5: grub.conf for non-genkernel users

# Which listing to boot as default. 0 is the first, 1 the second etc.
default 0
# How many seconds to wait before the default listing is booted.
timeout 30
# Nice, fat splash-image to spice things up :)
# Comment out if you don't have a graphics card installed
splashimage=(hd0,0)/grub/splash.xpm.gz

title=Gentoo Linux 2.4.26-r6
# Partition where the kernel image (or operating system) is located
root (hd0,0)
kernel /kernel-2.4.26-gentoo-r6 root=/dev/hda3

# The next three lines are only if you dualboot with a Windows system.
# In this case, Windows is hosted on /dev/hda6.
title=Windows XP
rootnoverify (hd0,5)
chainloader +1

Code listing 6: grub.conf for genkernel users

default 0
timeout 30
splashimage=(hd0,0)/grub/splash.xpm.gz

title=Gentoo Linux 2.4.26-r6
root (hd0,0)
kernel /kernel-2.4.26-gentoo-r6 root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=/dev/hda3
initrd /initrd-2.4.26-gentoo-r6

# Only in case you want to dual-boot
title=Windows XP
root (hd0,5)
chainloader +1

Note: If you use a different partitioning scheme and/or kernel image, adjust accordingly. However, make sure that anything that follows a GRUB-device (such as (hd0,0)) is relative to the mountpoint, not the root. In other words, (hd0,0)/grub/splash.xpm.gz is in reality /boot/grub/splash.xpm.gz since (hd0,0) is /boot.

If you need to pass any additional options to the kernel, simply add them to the end of the kernel command. We're already passing one option (root=/dev/hda3 or real_root=/dev/hda3), but you can pass others as well. As an example we use the vga statement for framebuffer we discussed previously:

Code listing 7: Adding the vga-statement as a kernel option

title=Gentoo Linux 2.4.26-r6
  root (hd0,0)
  kernel /kernel-2.4.26-gentoo-r6 root=/dev/hda3 vga=788

If you're using a 2.6.7 or higher kernel and you jumpered your harddrive because the BIOS can't handle large harddrives you'll need to append hdx=stroke.

genkernel users should know that their kernels use the same boot options as is used for the LiveCD. For instance, if you have SCSI devices, you should add doscsi as kernel option.

Now save the grub.conf file and exit. As of now, GRUB is fully configured, and you can continue with Installing Necessary System Tools.

If you have more questions regarding GRUB, please consult the GRUB FAQ or the GRUB Manual.

9.c. Alternative: Using LILO

Installing LILO

LILO, the LInuxLOader, is the tried and true workhorse of Linux bootloaders. However, it lacks some features that GRUB has (which is also the reason why GRUB is currently gaining popularity). The reason why LILO is still used is that, on some systems, GRUB doesn't work and LILO does. Of course, it is also used because some people know LILO and want to stick with it. Either way, Gentoo supports both, and apparently you have chosen to use LILO.

Installing LILO is a breeze; just use emerge.

Code listing 8: Installing LILO

# emerge --usepkg lilo

Configuring LILO

To configure LILO, you must create /etc/lilo.conf. Fire up your favorite editor (in this handbook we use nano for consistency) and create the file.

Code listing 9: Creating /etc/lilo.conf

# nano -w /etc/lilo.conf

Some sections ago we have asked you to remember the kernel-image name you have created. In the next example lilo.conf we assume the imagename is kernel-2.4.26-gentoo-r6. We also use the example partitioning scheme in this example. There are two separate parts:

Make sure you use your kernel image filename and, if appropriate, your initrd image filename.

Code listing 10: Example /etc/lilo.conf

boot=/dev/hda             # Install LILO in the MBR
prompt                    # Give the user the chance to select another section
timeout=50                # Wait 5 (five) seconds before booting the default section
default=gentoo            # When the timeout has passed, boot the "gentoo" section
# Only if you use framebuffer. Otherwise remove the following line:
vga=788                   # Framebuffer setting. Adjust to your own will

# For non-genkernel users
image=/boot/kernel-2.4.26-gentoo-r6
  label=gentoo            # Name we give to this section
  read-only               # Start with a read-only root. Do not alter!
  root=/dev/hda3          # Location of the root filesystem

# For genkernel users
image=/boot/kernel-2.4.26-gentoo-r6
  label=gentoo
  read-only
  root=/dev/ram0
  append="init=/linuxrc ramdisk=8192 real_root=/dev/hda3"
  initrd=/boot/initrd-2.4.26-gentoo-r6

# The next two lines are only if you dualboot with a Windows system.
# In this case, Windows is hosted on /dev/hda6.
other=/dev/hda6
  label=windows

Note: If you use a different partitioning scheme and/or kernel image, adjust accordingly.

If you need to pass any additional options to the kernel, add an append statement to the section. As an example, we add the vga=788 statement to enable framebuffer:

Code listing 11: Using append to add kernel options

image=/boot/kernel-2.4.26-gentoo-r6
  label=gentoo
  read-only
  root=/dev/hda3
  append="vga=788"

If you're using a 2.6.7 or higher kernel and you jumpered your harddrive because the BIOS can't handle large harddrives you'll need to append hdx=stroke.

genkernel users should know that their kernels use the same boot options as is used for the LiveCD. For instance, if you have SCSI devices, you should add doscsi as kernel option.

Now save the file and exit. To finish up, you have to run /sbin/lilo so LILO can apply the /etc/lilo.conf to your system (i.e. install itself on the disk). Keep in mind that you'll also have to rerun /sbin/lilo every time you install a new kernel!

Code listing 12: Finishing the LILO installation

# /sbin/lilo

Now continue with Installing Necessary System Tools.


[ << ] [ < ] [ Home ] [ > ] [ >> ]