next up previous contents
Next: RAM Disks Up: Linux Boot Loaders Compared Previous: How Boot Loaders Work   Contents


Example Installations

Example root file system and kernel

In my article ``Getting Linux into Small Machines'' I described how to build a kernel and a root file system to put on a Linux diskette.

The relevant files are:

You can download a boot disk image myboot.img.gz from my home page and extract these files from it, so you can try them out with various other boot loaders.

gunzip myboot.img.gz
mount -o loop myboot.img /mnt
cd /home/lennartb/myboot
cp /mnt/boot/zImage .
cp /mnt/boot/root.img.gz .
umount /mnt

In the following sections I will show how to install this kernel and a RAM disk with this root file system on a diskette using each of the boot loaders discussed in this article. Whenever possible I will provide a boot time choice between the RAM disk and an alternative root file system that could be on a hard disk partition. i have tried each of the diskettes, just to make sure they really work.

Linux Boot Sector

The oldest way to boot Linux is the kernel's own boot sector. This method has several limitations:

It cannot boot from overformatted diskettes (1680kB on a 3.5''HD diskette), but it has zero file system overhead.

If the kernel and RAM disk together are 1200kB or less you can dd the exact same disk image to both a 5.25'' and a 3.5'' diskette and they will both work. There are few if any boot loaders that can do that!

First transfer the kernel and the compressed RAM disk image to the diskette. As the kernel is less than 450kB in size, we can specify an offset for the RAM disk of 450kB (seek option to dd). This way the kernel and the RAM disk do not overlap on the diskette.

dd if=zImage of=/dev/fd0
dd if=root.img.gz of=/dev/fd0 bs=1k seek=450

We need one more thing to get this working: we need to set the RAM disk offset in the kernel. First calculate 16384 plus the offset you used with dd, in our case it is 16384+450=16834. Use this number in the following rdev commands:

rdev /dev/fd0 /dev/fd0
rdev -r /dev/fd0 16834
It is important also to set the root device to /dev/fd0, otherwise it won't work.

We could have put the RAM disk image on a separate diskette. In this case we should not specify an offset with dd and the rdev commands must be as follows:

rdev /dev/fd0 /dev/fd0
rdev -r /dev/fd0 49152

When this diskette is booted, the RAM disk will be loaded after the kernel initialization messages are shown, as opposed to the initial RAM disk that will be shown in other examples, which will be loaded by the boot loader before the kernel starts initializing. This type of RAM disk can also be used with other boot loaders.

Though the Linux boot sector cannot load a Linux kernel from an overformatted diskette there is no such restriction for the RAM disk. It is important that you rdev the kernel to the correct diskette type. For a RAM disk on a separate diskette, use the following commands:

rdev /dev/fd0 /dev/fd0u1722
rdev -r /dev/fd0 49152

For the RAM disk on the same diskette there are several solutions:

These bootable disks are limited to 21 sectors per track. The 24 sectors per track formats use fewer, but bigger sectors, which the boot loader does not understand. The absolute maximum amount of Linux to put on a single 3.5'' HD diskette can be achieved as follows: Success with your copy-protected Linux boot diskette!


LILO is one of the first boot loaders for Linux that was capable of booting from the hard disk, dating back to 19924. It's still the market leader and over the years it was updated with new features such as a nice boot menu and the use of the new BIOS functions that eliminate the 1024 cylinder limit. The basic working principle of LILO has stayed the same. This means that most work is done by the installer and not by the boot time code. LILO is the only boot loader that supports booting from a RAID system.

All Linux distributions already have LILO installed, but not necessarily the latest version. In this example we will download the latest version of LILO. At the time of writing, the latest version of LILO was 22.3.1. Unpack the source tarball and make. This is easy as long as you have a sufficiently recent version of bin86 installed. The file README.common.problems tells you where to get it. We won't install LILO for now, but run it from the source directory where it was built.

If you have read the ``Getting Linux into Small Machines'' article, the following may be familiar to you, but we will do a few things differently:

First create the file lilo-initrd.conf with the following contents:


Note the following:

Finally type the following commands to format the diskette, make a minix file system on it, copy the files and run LILO:

fdformat /dev/fd0u1722
mkfs.minix /dev/fd0u1722
mount /dev/fd0u1722 /mnt
mkdir /mnt/boot
cp zImage /mnt/boot
cp root.img.gz /mnt/boot
cp lilo-22.3.1/boot-menu.b /mnt/boot/boot.b
lilo-22.3.1/lilo -C lilo-initrd.conf
umount /mnt
Instead of boot-menu.b there is still the old-style boot-text.b, giving exactly the same interface as old LILO versions and boot-bmp.b to show a bitmapped screen. You can try all three of course.


GNU GRUB is the boot loader of the GNU project. It was the first boot loader to use the new BIOS features to boot beyond 1024 cylinders and it had a menu interface before LILO. Also it could detect more then 64MB of RAM when other systems could not yet do this.

In an ideal world all operating system kernels would conform to a certain standard so that any kernel could be loaded by any boot loader. The Multiboot standard is such a proposed standard, but very few operating systems conform to it (primarily the GNU HURD operating system). GRUB is designed to conform to the Multiboot standard. Besides Multiboot, it can boot Linux and BSD kernels and chainload anything else. For BSD kernels the latest features of the latest version are not supported, but Linux support is up to date.

GRUB is huge compared to both LILO and SYSLINUX. This is mainly because it can read most file system types by itself. Besides it serves as its own installer and it has many useful and less useful commands. You can recompile it with some file systems and other features configured out to save space.

Just for fun and to show how flexible GNU GRUB really is, we will install the Multiboot compliant GRUB Invaders game as well. Skip this if you don't like it. Unpack the tar archive and just use the invaders binary.

Download the latest version of GRUB (0.92), unpack it and type the following commands in the source directory:


Create the file menu.lst with the following contents.

root (fd0)
title Linux with RAM disk
   kernel /boot/zImage
   initrd /boot/root.img.gz
title Linux without RAM disk
   kernel /boot/zImage root=/dev/fd0
title GRUB Invaders
   kernel /boot/invaders

Create a diskette and copy the usual stuff to it. The fact that we create a DOS diskette is arbitrary. We could have performed the same procedure with almost any other file system that Linux supports. The files stage1 and stage2 are components of grub that are traditionally installed in the directory /boot/grub on the boot device. The configuration file is menu.lst is also copied to this directory. As opposed to LILO, GRUB reads the configuration file at boot time.

fdformat /dev/fd0H1440
mkfs.msdos  /dev/fd0
mount -t vfat /dev/fd0 /mnt
mkdir /mnt/boot
mkdir /mnt/boot/grub
cp zImage /mnt/boot
cp root.img.gz /mnt/boot
cp invaders/invaders /mnt/boot
cp grub-0.92/stage1/stage1 /mnt/boot/grub
cp grub-0.92/stage2/stage2 /mnt/boot/grub
cp menu.lst /mnt/boot/grub
umount /dev/fd0

Now we only need to make this diskette bootable. There are three ways to do it:

Run the GRUB shell:


In the GRUB shell type the following commands:

root (fd0)
setup (fd0)

The setup command installs a boot sector program on the given device. Note that GRUB can install its own boot sector, but it cannot write, and hence cannot copy, the required files stage1 and stage2 to the target device. This must have been done before by an operating system.

After you have installed GRUB onto the diskette, you can copy other kernels to it and edit the menu.lst file as much as you like, without the need to reinstall. Only the file stage2 may not be moved.

When you boot the GRUB diskette, you get a menu with three entries. You can do any of the following:


SYSLINUX is a boot loader specially suited for diskettes. It boots only from DOS formatted disks (could be hard disk partitions as well). It supports custom help screens to introduce the user into using the diskette. DOS diskettes have the advantage that they are not considered defective by most PC users and therefore they less likely thrown away or reformatted. Like GRUB, SYSLINUX reads its configuration file at boot time.

In theory SYSLINUX can be installed in a FAT partition on the hard disk and it can boot Linux kernels from there and it can chain load MSDOS and similar operating systems. However, SYSLINUX is not the natural choice for booting Linux from the hard disk.

First obtain the latest version of SYSLINUX. (version 1.75 at the time of writing). Unpack and run make. Note that you need a recent version of nasm to rebuild the boot loader from source and that the binaries are already included, so you do not really need nasm just to install this boot loader.

Create a text file syslinux.cfg with the following contents:

prompt 1
timeout 100
say Available options: linux and noram
label linux
kernel zimage
append initrd=root.gz
label noram
kernel zimage
This file specifies the usual options for loading a kernel with an initial RAM disk and a kernel without an initial RAM disk (where a root device should be specified on the command line).

Next format a disk and copy all relevant files to it. An overformatted disk can be used and an MSDOS file system must be used. The syslinux command installs the boot sector program.

fdformat /dev/fd0u1722
mkfs.msdos /dev/fd0u1722
cd syslinux-1.75
syslinux /dev/fd0u1722
cd ..
mount -t msdos /dev/fd0u1722 /mnt
cp zImage /mnt/zimage
cp root.img.gz /mnt/root.gz
cp syslinux.cfg /mnt
umount /mnt
You can copy other kernels and initial RAM disk and edit syslinux.cfg as much as you like without any form of re-installation, just as you can do with GRUB. The GRUB binary on the example disk was 95k while the SYSLINUX binary is only 7k. That's the difference.


LOADLIN is a program that can boot Linux from DOS. Since the advent of Windows ME and Windows XP, it is no longer natural that PC users have DOS installed on their PCs. Windows versions up to and including Windows 98 came with a DOS version that was usable for LOADLIN. In my opinion LOADLIN is primarily of historical interest for this reason. The primary reasons to use LOADLIN were the following:

Loadlin can be downloaded from Hans Lermen's home page. Download the file lodln16.tgz and unpack it. We will use only the file loadlin.exe.

In order to run LOADLIN, we need DOS. Create a bootable DOS diskette with just the bare system and COMMAND.COM on it. For those of you who have either Windows NT/ME/2000/XP or no Microsoft OS at all, you can use Freedos. Download the file FDB8_144.DSK (the rawrite image) and transfer it to a diskette

dd if=FDB8_144.DSK of=/dev/fd0
Next remove everything but KERNEL.SYS and COMMAND.COM from this diskette.
mount /dev/fd0 /mnt
cd /mnt
rm -rf config.sys *.bat kernel32.sys kernel16.sys readme\
    docs fdos games install util
umount /mnt

Now that we have a minimal DOS diskette, copy LOADLIN.EXE, the linux kernel and the initial RAM disk to it:

mount /dev/fd0 /mnt
cd /home/lennartb/myboot
cp loadlin.exe /mnt
cp zImage /mnt/zimage
cp root.img.gz /mnt/root.gz
umount /mnt

Next try to boot from the diskette. You should boot into DOS. As there is no AUTOEXEC.BAT, you will be prompted for date and time. Press enter twice. Now you should be at the A> prompt. Type the following line to boot Linux:

loadlin zimage initrd=root.gz
Of course you can put this line in a batch file or even in AUTOEXEC.BAT.

Where Can Boot Loaders Live

Table 1 summarizes where boot loaders can be installed.

Table 1: Where boot loaders can be installed
Boot Loader DOS FS Other FS Overformatted FD Hard disk Overhead
Kernel boot sector No No No No 0
LILO No Yes Yes Yes FS + 15k
GRUB Yes Yes No Yes FS + 96k
SYSLINUX Yes No Yes Yes FS + 8k
LOADLIN Yes No Yes Yes FS + DOS + 32k

next up previous contents
Next: RAM Disks Up: Linux Boot Loaders Compared Previous: How Boot Loaders Work   Contents
Lennart Benschop 2003-05-29