Gentoo Logo

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


10. Configuring the Bootloader

Content:

10.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 GRUB2, LILO and GRUB Legacy.

But before we install the bootloader, we inform you how to configure framebuffer (assuming 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 default kernel configuration), you can activate it by adding a a video statement to your bootloader configuration file.

First of all, you need to know your framebuffer device. You should have used uvesafb as the VESA driver.

The video statement controls framebuffer display options. It needs to be given the framebuffer driver followed by the control statements you wish to enable. All variables are listed in /usr/src/linux/Documentation/fb/uvesafb.txt. The most-used options are:

Control Description
ywrap Assume that the graphical card can wrap around its memory (i.e. continue at the beginning when it has approached the end)
mtrr:n Setup MTRR registers. n can be:
0 - disabled
1 - uncachable
2 - write-back
3 - write-combining
4 - write-through
mode Set up the resolution, color depth and refresh rate. For instance, 1024x768-32@85 for a resolution of 1024x768, 32 bit color depth and a refresh rate of 85 Hz.

The result could be something like video=uvesafb:mtrr:3,ywrap,1024x768-32@85. Write this setting down; you will need it shortly.

Now continue by installing GRUB, GRUB2 or LILO.

10.b. Default: Using GRUB2

Installing GRUB2

GRUB2 is provided through the sys-boot/grub package.

Code Listing 2.1: Installing GRUB2

# emerge sys-boot/grub

The GRUB2 software is now installed on the system, but not activated yet.

Configuring GRUB2

First, let us install the necessary GRUB2 files in /boot/grub. Assuming the first disk (the one where the system boots from) is /dev/sda, the following command will do this for us:

Code Listing 2.2: Installing the GRUB2 files in /boot/grub

# grub2-install /dev/sda

Next, we can generate the GRUB2 configuration based on the user configuration specified in the /etc/default/grub file and /etc/grub.d scripts. In most cases, no configuration is needed by users as GRUB2 will automatically detect which kernel to boot (the highest one available in /boot) and what the root file system is.

To generate the final GRUB2 configuration, run the grub2-mkconfig command:

Code Listing 2.3: Generating GRUB2 configuration

# grub2-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/kernel-3.3.8-gentoo
Found initrd image: /boot/initramfs-genkernel-x86-3.3.8-gentoo
done

The output of the command must mention that at least one Linux image is found, as those are needed to boot the system. If you use initramfs or used genkernel to build the kernel, the correct initrd image should be detected as well. If this is not the case, go to /boot and check the contents using the ls command. If the files are indeed missing, go back to the kernel configuration and installation instructions.

10.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 3.1: Installing LILO

# emerge 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 3.2: 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 use the example partitioning scheme.

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

Note: If your root filesystem is JFS, you must add a append="ro" line after each boot item since JFS needs to replay its log before it allows read-write mounting.

Code Listing 3.3: Example /etc/lilo.conf

boot=/dev/sda             # 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

image=/boot/kernel-3.3.8-gentoo
  label=gentoo            # Name we give to this section
  read-only               # Start with a read-only root. Do not alter!
  root=/dev/sda4          # Location of the root filesystem

image=/boot/kernel-3.3.8-gentoo
  label=gentoo.rescue     # Name we give to this section
  read-only               # Start with a read-only root. Do not alter!
  root=/dev/sda4          # Location of the root filesystem
  append="init=/bin/bb"   # Launch the Gentoo static rescue shell

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

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

If, while building the Linux kernel, you opted to include an initramfs to boot from, then you will need to change the configuration by referring to this initramfs file and telling the initramfs where your real root device is at:

Code Listing 3.4: LILO snippet for initramfs-enabled kernel builds

image=/boot/kernel-3.3.8-gentoo
  label=gentoo
  read-only
  append="real_root=/dev/sda4"
  initrd=/boot/initramfs-genkernel-x86-3.3.8-gentoo

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

Code Listing 3.5: Using append to add kernel options

image=/boot/kernel-3.3.8-gentoo
  label=gentoo
  read-only
  root=/dev/sda4
  append="video=uvesafb:mtrr,ywrap,1024x768-32@85"

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 sda=stroke. Replace sda with the device that requires this option.

genkernel users should know that their kernels use the same boot options as is used for the Installation CD. 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 run /sbin/lilo every time you install a new kernel or make any changes to the menu.

Code Listing 3.6: Finishing the LILO installation

# /sbin/lilo

If you have more questions regarding LILO, please consult its wikipedia page.

You can now continue with Rebooting the System.

10.d. Alternative: Using GRUB Legacy

What is Legacy?

GRUB has been reworked and a new release dubbed GRUB2 is made available. The new GRUB2 codebase is quite different from the current GRUB, which is why this GRUB version is now dubbed as "GRUB Legacy".

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/sda2 will most likely be called (hd0,1) under GRUB. Notice the parentheses around the hd0,1 - 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.) When you ask the BIOS to boot from a different hard disk (for instance your primary slave), that harddisk is seen as hd0.

Assuming you have a hard drive on /dev/sda and two more on /dev/sdb and /dev/sdc, /dev/sdb7 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 Legacy, let's first emerge it:

Code Listing 4.1: Installing GRUB

# emerge sys-boot/grub:0

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

Code Listing 4.2: Creating /boot/grub/grub.conf

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

Now we are going to write up a grub.conf. Make sure you use your kernel image filename and, if appropriate, your initrd image filename.

Note: Grub assigns device designations from the BIOS. If you change your BIOS settings, your device letters and numbers may change, too. For example, if you change your device boot order, you may need to change your grub configuration.

Note: If your root filesystem is JFS, you must add " ro" to the kernel line since JFS needs to replay its log before it allows read-write mounting.

Note: If dualboot with Windows is used, the partitioning example used in this book will not be sufficient (our example uses all four primary partitions for Linux, whereas at least one would need to be extended if Windows is installed on a logical partition). Please proceed with caution and consider the listing to be an example that needs to be modified to suit your own needs.

Code Listing 4.3: Example grub.conf

# 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,1)/boot/grub/splash.xpm.gz

title Gentoo Linux 3.3.8
# Partition where the kernel image (or operating system) is located
root (hd0,1)
kernel /boot/kernel-3.3.8-gentoo root=/dev/sda4

title Gentoo Linux 3.3.8 (rescue)
# Partition where the kernel image (or operating system) is located
root (hd0,1)
kernel /boot/kernel-3.3.8-gentoo root=/dev/sda4 init=/bin/bb

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

If, while building the Linux kernel, you opted to include an initramfs to boot from, then you will need to change the configuration by referring to this initramfs file and telling the initramfs where your real root device is at:

Code Listing 4.4: GRUB snippet for initramfs-enabled kernel builds

title Gentoo Linux 3.3.8
root (hd0,1)
kernel /boot/3.3.8 real_root=/dev/sda4
initrd /boot/initramfs-genkernel-x86-3.3.8-gentoo

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

Besides, if you chose to use a different partitioning scheme and did not put /boot in a separate partition, the /boot prefix used in the above code samples is really required. If you followed our suggested partitioning plan, the /boot prefix it not required, but a boot symlink makes it work. In short, the above examples should work whether you defined a separate /boot partition or not.

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/sda4 or real_root=/dev/sda4), but you can pass others as well, such as the video statement for framebuffer as we discussed previously.

If your bootloader configuration file contains the real_root parameter, use the real_rootflags parameter to set root filesystem mount options.

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 sda=stroke. Replace sda with the device that requires this option.

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

Now save the grub.conf file and exit. You still need to install GRUB in the MBR (Master Boot Record) so that GRUB is automatically executed when you boot your system.

The GRUB developers recommend the use of grub-install. However, if for some reason grub-install fails to work correctly you still have the option to manually install GRUB.

Continue with Default: Setting up GRUB using grub-install or Alternative: Setting up GRUB using manual instructions.

Default: Setting up GRUB using grub-install

To install GRUB you will need to issue the grub-install command. However, grub-install won't work off-the-shelf since we are inside a chrooted environment. We need to create /etc/mtab which lists all mounted filesystems. Fortunately, there is an easy way to accomplish this - just copy over /proc/mounts to /etc/mtab, excluding the rootfs line if you haven't created a separate boot partition. The following command will work in both cases:

Code Listing 4.5: Creating /etc/mtab

# grep -v rootfs /proc/mounts > /etc/mtab

When using Linux virtio disks, we need to tell grub where to find the disks as the grub-install command will otherwise fail. This is done by adding the device definition to the device.map file:

Code Listing 4.6: Adding the virtio disk to the device map table

# echo "(hd0)	/dev/vda" >> /boot/grub/device.map

Now we can install GRUB using grub-install:

Code Listing 4.7: Running grub-install

# grub-install --no-floppy /dev/sda

If you have more questions regarding GRUB, please consult the GRUB FAQ, the GRUB Wiki, or read info grub in your terminal.

Continue with Rebooting the System.

Alternative: Setting up GRUB using manual instructions

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 4.8: Starting the GRUB shell

# grub --no-floppy

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/sda2, 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,1).

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

Code Listing 4.9: Installing GRUB in the MBR

grub> root (hd0,1)    (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/sda4, then the command becomes setup (hd0,3). Few users however want to do this.

If you have more questions regarding GRUB, please consult the GRUB FAQ, the GRUB Wiki, or read info grub in your terminal.

Continue with Rebooting the System.

10.e. Rebooting the System

Exit the chrooted environment and unmount all mounted partitions. Then type in that one magical command you have been waiting for: reboot.

Code Listing 5.1: Unmounting all partitions and rebooting

# exit
cdimage ~# cd
cdimage ~# umount -l /mnt/gentoo/dev{/shm,/pts,}
cdimage ~# umount -l /mnt/gentoo{/boot,/proc,}
cdimage ~# reboot

Of course, don't forget to remove the bootable CD, otherwise the CD will be booted again instead of your new Gentoo system.

Once rebooted in your Gentoo installation, finish up with Finalizing your Gentoo Installation.


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


Print

View all

Page updated December 31, 2013

Summary: Several bootloaders exist for the x86 architecture. Each one of them has its own way of configuration. We step you through the process of configuring a bootloader to your needs.

Sven Vermeulen
Author

Grant Goodyear
Author

Roy Marples
Author

Daniel Robbins
Author

Chris Houser
Author

Jerry Alexandratos
Author

Seemant Kulleen
Gentoo x86 Developer

Tavis Ormandy
Gentoo Alpha Developer

Jason Huebel
Gentoo AMD64 Developer

Guy Martin
Gentoo HPPA developer

Pieter Van den Abeele
Gentoo PPC developer

Joe Kallar
Gentoo SPARC developer

John P. Davis
Editor

Pierre-Henri Jondot
Editor

Eric Stockbridge
Editor

Rajiv Manglani
Editor

Jungmin Seo
Editor

Stoyan Zhekov
Editor

Jared Hudson
Editor

Colin Morey
Editor

Jorge Paulo
Editor

Carl Anderson
Editor

Jon Portnoy
Editor

Zack Gilburd
Editor

Jack Morgan
Editor

Benny Chuang
Editor

Erwin
Editor

Joshua Kinard
Editor

Tobias Scherbaum
Editor

Xavier Neys
Editor

Joshua Saddler
Editor

Gerald J. Normandin Jr.
Reviewer

Donnie Berkholz
Reviewer

Ken Nowack
Reviewer

Lars Weiler
Contributor

Donate to support our development efforts.

Copyright 2001-2014 Gentoo Foundation, Inc. Questions, Comments? Contact us.