GRUB Boot Loader
On this page the Linux boot process and GRUB boot loader are covered. It explains how to run different operating systems or load different kernels at boot time.
Introduction to boot loaders
When a Linux system running on PC hardware is started, the first code to be run is the BIOS (Basic Input Output System) which is loaded from ROM. After it has finished testing the system's memory and discovering what hardware is installed, it attempts to pass control to an operating system boot loader to continue the boot process. The boot loader is a tiny program that may prompt the user to choose which OS to run, and then loads the rest of the operating system kernel from a hard drive, floppy disk or some other source.
On a normal system, the boot loader is loaded by the BIOS from the first block on the primary hard drive, called the master boot record or MBR. However, the BIOS may (depending on its configuration) check the floppy drive or CD-ROM for a boot loader first, so that the system can be booted off a removable disk. This is usually only done when installing a new operating system - for normal everyday use, almost every system boots from hard disk.
There are several boot loaders available for Linux, but the two most common and the two which will be covered in this chapter are LILO and GRUB. Both work only on x86-compatible PC hardware, so if you are running Linux on an Apple, SPARC or Alpha system, this chapter will not be much use to you. Each non-PC hardware platform has its own specialized Linux boot loader, designed to deal with the particular quirks and requirements of the platform.
Other operating systems (such as Windows, FreeBSD and Solaris) have their own boot loaders, which do basically the same thing as LILO or GRUB, but are designed to load the kernel of a different OS instead. Webmin does not support the configuration of any non-Linux boot loader, so if you are running a different version of Unix this chapter can be skipped.
On a Linux system, the boot loader's primary responsibility is the loading of the kernel. Once the kernel has been loaded into memory and control has been transferred to it, the boot loader's job is done. The kernel then mounts the root filesystem, initialized drivers, and finally runs the init program to continue the boot process as explained in chapter 9.
The boot loader can also start the process of loading a totally different OS on systems that have more than one installed. It does this by loading the other operating system's boot loader from the first block of a partition or other hard disk, and then transferring control to it. The other OS then loads exactly as it would if its boot loader were run directly by the BIOS. Being able to decide which operating system to load at boot time makes it practical to have two or more installed on the same system, such as Windows and Linux.
Both LILO and GRUB can be configured to display a menu of boot options when they are loaded, allowing the user to select which particular kernel to load or other operating system to load. Being able to choose from several different kernels can be particularly useful when you have installed a new one and want to have the option of booting into both new and old. It is even possible to have several boot options that all load the same kernel version, but with different command-line options.
All Linux distributions will give you the option of automatically setting up a boot loader at installation time. You can usually choose to boot other installed operating systems as well, for example if you are adding Linux to a system with Windows already installed on a different partition. If this default configuration is working for you, be very careful when changing the LILO or GRUB configuration manually or through Webmin. A single mistake may render your system un-bootable, and necessitate the use of a rescue disk to recover.
GRUB usually uses the configuration file /boot/grub/grub.cfg (previously menu.lst) and unlike LILO it does understand the format of ext2, ext3, ext4 and vfat filesystems and so can read the menu.lst and kernel files without the need for a block map. For this reason and because GRUB can load a kernel stored anywhere on the hard disk, it is usually considered to be a superior boot loader, and has been overtaking LILO on most Linux distributions.
GRUB2 as used in many (all?) newer distro's uses configuration files in /etc/grub.d/. Module configuration could be modified, but doesn't work yet.
The GRUB Boot Loader module
As the name suggests, this module allows you to set up GRUB. Like the LILO module, when you enter it from the Hardware category the main page shows a list of icons, one for each boot-time option. This screenshot shows an example.
The module's icon will only appear if Webmin detects that GRUB is installed on your system. If it is not visible or if an error is displayed when you enter the module, GRUB is not installed. If so, LILO is probably being used instead and so you should use the Linux Boot Loader module.
One peculiarity of GRUB is that internally it refers to all hard disks by their BIOS disk number. hd0 is the first drive identified by the BIOS, and hd0,0 is the first partition on that drive. On a system with only IDE hard drives, this numbering is quite simple - BIOS disk 0 is the primary master, or /dev/hda on Linux. Disk 2 (called hd1 by GRUB) is the primary slave, and so on. However, on a system with SCSI and IDE drives, things get more complex. IDE disks usually come before SCSI in the BIOS ordering, but this may be reversed on some systems. Fortunately, the GRUB module in recent versions of Webmin can automatically detect the relationship between Linux device files and BIOS disk numbers.
Booting a new Linux kernel or BSD with GRUB
If you have just compiled a new kernel and want to be able to use it, you will need to add a new GRUB boot option.
A similar process should be followed if you have both Linux and FreeBSD, NetBSD or OpenBSD installed on your system and want to be able to choose one of them at boot time. To set this up, the steps to follow are:
- To boot a Linux kernel, after compiling copy its compressed kernel image file (usually found under the source directory at arch/i386/bzImage) to the /boot directory. Normally it should be renamed to vmlinuz-_xx.yy.zz_, where xx.yy.zz is the kernel version number.
- On the main page of the GRUB Boot Loader module, click on the Add a new boot option link to go to the option creation form.
- Enter a unique name for your new kernel into the Option title field, such as linux-xx.yy.zz. Whatever you enter will appear in the GRUB menu at boot time.
- Set the Boot image partition field to Selected and choose the partition that contains your kernel from the list next to it. If the partition does not appear in the menu, you will need to choose Other instead and enter the disk and partition into the field next to it, in the hd_X_,_Y_ format used by GRUB. For example, hd2,1 would be the second partition on BIOS drive 3.
- For Operating system to boot, select Linux kernel and enter the path to the kernel's compressed image file into the field next to it. To pass additional arguments to the kernel, enter them into the Kernel options field below it. For FreeBSD, you must also select Linux kernel and enter /boot/loader into the field. No additional kernel arguments are allowed. For NetBSD or OpenBSD, select Linux kernel as well and enter type=netbsd /netbsd-elf.
- If the root directory on your system is mounted from a device that is not compiled into the Linux kernel (such as a SCSI disk or hardware RAID controller), you will need to create an initial RAM disk containing the kernel modules needed to access the root filesystem. The simplest way of checking to see if this is necessary is to look at other existing boot kernel configurations. To create an initial RAM disk file under the /boot directory for kernel version xx.yy.zz, you will need to run a command like : mkinitrd /boot/initrd-_xx.yy.zz_ xx.yy.zz Then set the Initial ramdisk file field to the path to the newly created file.
- Finally, click the Create button. As long as there were no errors detected in your input, you will be returned to the module's main page which will now contain an addition icon for the new kernel.
- To boot into the new kernel, you will need to re-start your system. When GRUB loads at boot time, it will display a menu of available boot options, from which you can select the newly added kernel. Be sure to watch the debugging output and error messages that the kernel displays while booting, so that if anything goes wrong you can diagnose the problem. If there is a problem, you may need to re-boot and select the old kernel option, then use Webmin to fix the GRUB configuration.
Once you have created a new kernel boot option, you can edit it by clicking on its icon on the module's main page. On the editing form, any of the fields can be edited and the changes saved by clicking the Save button, or the kernel can be removed by clicking Delete instead. Always be careful editing any kernel configurations that you did not create yourself, as a mistake may make the system unbootable.
Booting another operating system with GRUB
If your system has another operating system installed on a different hard disk or partition, you can configure GRUB so that it can be chosen and started at boot time instead of Linux. If you want to boot FreeBSD, NetBSD or OpenBSD see the *Booting a new Linux kernel or BSD* section above instead - but for Windows, UnixWare or any other OS the steps to follow are:
- On the module's main page, click on Add a new boot option to bring up the boot option creation form.
- Enter a unique name for into the Option title field, such as windows.
- Set the Boot image partition field to Selected and choose the partition that contains the other OS from the list next to it. If the partition does not appear in the menu, you will need to choose Other instead and enter the disk and partition into the field next to it, in the hd_X_,_Y_ format used by GRUB.
- Change the Operating system to boot to Other OS.
- Normally, GRUB will simply run the boot loader in the first sector of the chosen partition. However, there may not always be a boot loader there, if for example the operating system normally writes its loader to the master boot record. If the other operating system is Windows, select the *From chainloader file* and enter +1 into the field next to it. You must also check the Make root partition action? option. If booting SCO UnixWare, you need to also select the *From chainloader file* and enter force +1 into the field next to it. The *Make root partition action?* option must also be selected.
- Click the Create button to have the new OS added. Your browser will return to the module's main page, which will now include an icon for your new boot option.
- To boot into the other operating system, re-start your system and select it from the GRUB menu at boot time.
As with boot options for Linux kernels, your can edit or delete the option for another operating system by clicking on its icon on the module's main page. Any changes will take effect immediately, to be used when the system is next re-booted.
Editing global GRUB options
GRUB has several options that apply to all bootable kernels and operating systems. To edit these global options, the steps to follow are:
- Click the Edit Global Options button on the module's main page, which will take you to the options form.
- To control which kernel is booted automatically if the user does not choose one from the GRUB menu within the configured time limit, change the Default boot option field. If the option you choose cannot be loaded, GRUB will fall back to whatever is selected in the Fallback boot option field.
- To change the amount of time that GRUB will wait for the user to choose a boot option before it uses the default instead, edit the *Timeout before using default *field.
- The GRUB boot menu allows users to do things like change kernel parameters and read arbitrary files on Linux filesystems. To prevent this, enter a password into the Boot password field. This will limit users to the available boot options unless the password is entered. Furthermore, boot options in which the Password locked? field has been set will not be selectable either.
- When done, click the Save button and you will be returned to the module's main page.
If you have been using the LILO boot loader and want to switch to GRUB, you will need to install it on the same master boot record or partition that LILO is currently using. This only has to be done once, unlike LILO which has to be effectively re-installed every time its configuration is changed.
To install GRUB, the steps to follow are:
- On the module's main page, click on the Edit Global Options button.
- From the Install GRUB on disk/partiton menu, select the disk or partition onto which you want GRUB installed. This will typically be the first hard drive on your system.
- Click the Save button to return to the module's main page.
- Click on the Install GRUB button to have it written to the drive or partition chosen in step 2.
- So that your system can be booted into Linux from now on, create any necessary kernel boot options as explained in the *Booting a new Linux kernel or BSD* section. If you re-boot before doing this, it will be impossible to start Linux again!