10.5 Installing Your Kernel with a Boot Loader


10.5 Installing Your Kernel with a Boot Loader

Boot loaders load kernel images into memory and hand control of the CPU over to the newly loaded kernel. To make your new kernel work, you must tell the boot loader about the kernel.

If you have never worked with a boot loader before, you need to know how a PC boots from the hard disk. On a normal Microsoft-based system, the boot process works like this:

  1. After performing the power-on self test (POST), the BIOS loads sector 1 of the hard disk into memory and runs whatever landed in that memory. On most Windows-based systems, this sector is called the Master Boot Record (MBR).

  2. The MBR extracts the partition table from the disk and identifies the "active" partition.

  3. The MBR loads and runs yet another boot sector from the active partition, setting the operating system in motion.

On a Linux system, you can install the kernel boot loader on the active partition or you can replace the MBR with the boot loader. If you decide to replace the MBR with a boot loader such as GRUB or LILO, it is important to remember that the active partition has little meaning ” these boot loaders address partitions based on their own configuration systems.

From a practical point of view, your decision to overwrite the MBR (and thus circumvent the active partition) makes little difference. If your machine runs Linux, you probably want GRUB or LILO as your default boot loader. Even if you have a dual-boot machine, you still want to use GRUB or LILO, because both boot loaders are capable of loading boot sectors from other operating systems.

The important point is that you know exactly where your boot loader resides. Let's say that your disk is /dev/hda and you have a Linux root partition at /dev/hda3 . If you replace the MBR by writing GRUB to /dev/hda , you need to remember that the active partition is now irrelevant; GRUB uses its own configuration system to access partitions. However, if you decide to write the boot loader to /dev/hda3 instead, keeping the old MBR, your system will get to that boot loader only if /dev/hda3 is the active partition.

Note  

If you need to replace the MBR on a hard disk, run the DOS command FDISK /MBR .

When configuring a boot loader, be sure that you know the location of the root partition and any kernel parameters.

10.5.1 Which Boot Loader?

Because there are two popular Linux boot loaders, you may wonder which one you should choose:

  • LILO Linux Loader. This was one of the very first Linux boot loaders. Its disadvantages are that it is not terribly flexible and that you must run lilo to install a new boot block every time you install a new kernel. However, LILO is fairly self-contained.

  • GRUB Grand Unified Boot Loader. This is a newer boot system gaining in popularity, and it does not need a reconfiguration for every new kernel because it can read many kinds of filesystems. This feature is especially handy for situations where you might need to boot from an old kernel. Initially, GRUB is slightly trickier to configure than LILO, but it is much easier to deal with once installed, because you do not need to replace the boot sector for every new kernel. I recommend GRUB.

10.5.2 GRUB

With GRUB, you need only install the boot loader code on your machine once; after that, you can modify a GRUB menu file for any new kernel that you want to boot on a permanent basis.

The GRUB boot files are in /boot/grub . GRUB loads the various stage files into memory during the boot process. If you already have GRUB on your machine, you just need to modify the /boot/grub/menu.lst file when you add a new kernel image under a new name. (If you install a new kernel image with the same name as the old kernel, you do not need to modify the menu file.)

Some distributions preinstall GRUB but have a different name for menu.lst . You may need to dig around in /boot to find the correct filename. In any case, the menu file looks like this:

 default 0 timeout 10 title Linux   kernel (hd0,0)/boot/vmlinuz root=/dev/hda1 title backup   kernel (hd0,0)/boot/vmlinuz.0 root=/dev/hda1 

The parameters in the menu file are as follows :

  • default The title entry that GRUB should boot by default. 0 is the first entry, 1 is the second, and so on.

  • timeout How long GRUB should wait before loading the default image.

  • title A label for a kernel.

  • kernel The kernel image and parameters, possibly including the root device.

In GRUB, (hd0) is the first hard disk on your system, usually /dev/hda . GRUB assigns disk mappings in the order that they appear on your system, so if you have /dev/hda and /dev/hdc devices but no /dev/hdb , GRUB would assign (hd0) to /dev/hda and (hd1) to /dev/hdc . The first number in the GRUB name is for the disk, and the second is for the partition (if there is a partition). Check the /boot/grub/device.map file for your system's hard drive mapping.

The kernel images in the preceding example are on the root partition of the primary master ATA hard disk. There are two kernel images: a regular kernel at /boot/vmlinuz and a backup at /boot/vmlinuz.0 .

Root Device Confusion

You may find it odd that the root partition is actually specified twice in the kernel line in the preceding example (you can see (hd0,0) and /dev/hda1 ). This is easy to explain: the (hd0,0) is where GRUB expects to find the kernel image, and root=/dev/hda1 is a Linux kernel parameter that tells the kernel what it should mount as the root partition. These two locations are usually, but not always, the same. However, the GRUB and Linux device names are completely different, and so you need them in two places in the configuration file.

Unfortunately, you may see this alternate syntax in menu.lst :

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

This is confusing, because GRUB does not pass its root parameter (hd0,0) to the Linux kernel. Omitting the GRUB root parameter can prevent some head scratching.

Booting Other Operating Systems

There are all sorts of other things you can do with GRUB, like load splash screens and change the title (use info grub to see all of the options). However, the only other essential thing you should know is how to make a dual-boot system.

Here is a definition for a DOS or Windows system on /dev/hda3 :

 title dos   rootnoverify (hd0,2)   makeactive   chainloader +1 

Remember how the PC boot loaders usually work, by first loading whatever is on the first sector of the disk, then loading the first sector of the active partition.

Installing GRUB

To put GRUB on your system for the first time, you must make sure that you have a menu.lst file. The GRUB installation process does not create menu.lst ; you must come up with this file on your own. If you don't, you can still boot your system, but you must type a series of commands resembling entries in menu.lst to do so, as follows:

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

To install the GRUB software, run this command to put the boot sector on your disk:

 grub-install  device  

Here, device is your boot device, such as /dev/hda . However, if you have aspecial /boot partition, you need to do something like this:

 grub-install --root-directory=/boot  device  

After running grub-install , review your /boot/grub/device.map file to make sure that the devices relevant to booting the kernel are in the map file and agree with your menu.lst file.

10.5.3 LILO

To load your kernel with LILO, you must settle on a permanent location for your kernel image and install a new boot block for every change you make to the kernel configuration.

Let's say that you want to boot /vmlinuz as your kernel with a root partition of /dev/hda1 . Furthermore, you want to install the boot loader on /dev/hda (replacing the MBR). Do the following:

  1. Move the new image into place at /boot/vmlinuz .

  2. Create the LILO configuration file, /etc/lilo.conf . An elementary configuration might look like this:

     boot=/dev/hda root=/dev/hda1 install=/boot/boot.b map=/boot/map vga=normal delay=20 image=/boot/vmlinuz     label=Linux     read-only 
  3. Run lilo -t -v to test the configuration without changing the system.

  4. Run lilo to install the boot loader code at /dev/hda .

You can add more images and boot sectors to the LILO configuration. For example, if you saved your previous kernel as /boot/vmlinuz.0 , you could add this to your lilo.conf to make the old image available as backup at the LILO prompt:

 image=/boot/vmlinuz.0     label=backup     read-only 

You can use the other keyword for foreign operating systems. The following addition to lilo.conf offers a Windows partition on /dev/hda3 as dos at the LILO prompt:

 other=/dev/hda3     label=dos 

LILO Parameters

Some of the most important lilo.conf parameters are listed here:

  • boot= bootdev Writes the new boot sector to the bootdev device.

  • root= rootdev Uses rootdev as the kernel's default root partition.

  • read-only Mounts the root partition initially as read-only. You should include this for normal boot situations ( init remounts the root partition in read-write mode later).

  • append=" options " Includes options as kernel boot parameters.

  • delay= num Displays the LILO prompt for num tenths of a second at boot time before booting the default kernel image.

  • map= map _ file Stores the kernel's location in map_file . Don't delete this file.

  • install= file Specifies that file is the actual boot loader code that lilo writes to the boot sector.

  • image= file Defines a bootable kernel image with file . You should always use the label parameter directly following this definition to name the image.

  • label= name Uses name to label the current boot entry.

  • other= partition Defines another partition that contains a boot sector; analogous to image for other operating systems. Use label to define a label for the boot sector.

  • linear Remaps the boot sector load references when the BIOS disk geometry is different than the geometry that the Linux kernel sees. This is usually not necessary, because most modern BIOS code can recognize very large disks.

10.5.4 Initial RAM Disks

An initial RAM disk is a temporary root partition that the kernel should mount before doing anything else. Red Hat Linux uses initial RAM disks to support SCSI host controller drivers and other drivers that are compiled as modules.

Note  

You do not need an initial RAM disk if you compile all the drivers necessary to mount your root filesystem directly into your kernel. The overwhelming majority of systems do not need an initial RAM disk.

To install an initial RAM disk on a Red Hat Linux system, follow these steps:

  1. Build your kernel and install the modules. Do not run any boot loader configuration or reboot just yet.

  2. Run this command to create a RAM disk image (where version is your kernel version):

     mkinitrd /boot/initrd-  version version  
  3. If your boot loader is LILO, add this line to your new kernel's section in lilo.conf and run lilo :

     initrd=/boot/initrd-  version  
  4. For GRUB, add the following to the appropriate kernel section:

     initrd /boot/initrd-  version  



How Linux Works
How Linux Works: What Every Superuser Should Know
ISBN: 1593270356
EAN: 2147483647
Year: 2004
Pages: 189
Authors: Brian Ward

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net