Originally Published: Thursday, 19 July 2001 Author: Subhasish Ghosh
Published to: learn_articles_firststep/General Page: 3/6 - [Printable]

Bootstrapping a Linux system - An Analysis

Ever wonder what happens between powering on your system and the logon prompt? You see all the screen messages, but what do they mean? Linux.com writer Subhasish Ghosh wondered the same thing, and went to find out in Bootstrapping a Linux System.

Boot Loader  << Page 3 of 6  >>

Boot Loader. What's that? What does it do?

The BIOS invokes (note: does NOT execute) a special program whose only task is to load the image of an operating system Kernel into RAM. This program is called the Boot Loader. Before we proceed any further let's take a brief look at the different ways a system can be booted.

  1. Booting Linux from a Floppy disk
  2. Booting Linux from a Hard disk

Booting Linux from Floppy Disk.

When booting from a floppy disk, the instructions stored in the first sector of the floppy disk are loaded into RAM and executed. These instructions then copy all the remaining sectors containing the Kernel image into RAM.

The Linux Kernel fits into a single 1.44-MB floppy disk. (In fact, there exists a type of Red Hat Linux installation known as "stripped-off" type, where it requires approx. 2 MB physical RAM and approx. 1.44 MB hard disk space for running a Red Hat Linux system.) But the only way to store a Linux Kernel on a single floppy disk is to compress the "Linux Kernel Image". The point to remember here is that compressing is done at compile time, while decompressing is done at boot time by the loader.

In the case of booting Linux from a floppy disk the boot loader's job is very simple. It has been coded in the /usr/src/linux-2.4.2/arch/i386/boot/bootsect.S assembly language file. When we compile the Linux Kernel source, and obtain a new kernel image, the executable code yielded by this assembly language file is place at the beginning of the Kernel image file. This makes it easy to produce a floppy disk containing the Linux Kernel.

Copying the kernel image starting from the first sector of the disk can create the floppy. When the BIOS loads the first sector of the floppy disk, it actually copies the code of the boot loader. The boot loader, which is invoked by BIOS (by jumping to the physical address 0x00007c00) performs the following operations:

  1. Moves itself from address 0x00007c00 to address 0x00090000.
  2. Using address 0x00003ff4, sets up the "Real Mode" stack.
  3. Sets up the disk parameter table. This is used by BIOS to handle the floppy device driver.
  4. Displays the message "Loading" by invoking a BIOS procedure.
  5. Then the boot loader invokes a BIOS procedure to load the setup( ) code of the Kernel Image from the floppy disk. It puts this into RAM starting from address 0x00090200.
  6. Next the boot loader invokes a BIOS procedure. This procedure loads the rest of the Kernel image from the floppy disk and puts the image in RAM starting from either address 0x00010000 (called "low address" for small Kernel Images compiled with "make zImage") or address 0x00100000 (called "high address" for big Kernel Images compiled with "make bzImage").
  7. Then, it finally jumps to the setup( ) code.

Booting Linux from Hard Disk.

When booting from the hard disk, the booting procedure is different. The first sector of the hard disk, called the Master Boot Record (MBR) includes the partition table and a small program. This program loads the first sector of the partition containing the operating system to be started. Linux is highly flexible and sophisticated piece of software, thus it replaces this small program in the MBR with a sophisticated program called LILO (LInux boot LOader). LILO allows users to select the operating system to be booted.

Usually the Linux Kernel is loaded from a hard disk. This requires a two-stage boot loader. On Intel systems, the most commonly used Linux boot loader is named LILO. For other architectures, other Linux boot loaders exist. LILO may either be installed on the MBR (Please note: During Red Hat Linux Installation there comes a step where the user has to either write LILO to the MBR or put it in the boot sector) or in the boot sector of an active disk partition.

LILO is broken into two parts otherwise it would be too large to fit into the MBR. The MBR (or the disk partition boot sector) includes a small boot loader, which is loaded into RAM starting from address 0x00007c00 by the BIOS. This small program moves itself to the address 0x0009a000, then sets up the Real Mode stack, and then finally loads the second part of the LILO boot loader. (Please note: The Real Mode stack ranges from address 0x0009b000 to 0x0009a200).

The second part of LILO reads all the available operating systems from disk and offers the user a prompt so that he or she can choose any of them from the available list. After the user has chosen any Kernel (on my system, one can opt for any 1 Linux Kernel out of 8 Custom Kernels) to be loaded, the boot loader may either copy the boot sector of the corresponding partition into RAM and execute it or directly copy the Kernel image into RAM.

Since the Linux Kernel image must be booted the Linux boot loader performs essentially the same operations as the boot loader integrated into the Kernel image. The boot loader invoked by BIOS (by jumping to the physical address 0x00007c00) performs the following operations:

  1. Moves itself from address 0x00007c00 to address 0x00090000.
  2. Using address 0x00003ff4, sets up the "Real Mode" stack.
  3. Sets up the disk parameter table. This is used by BIOS to handle the hard disk device driver.
  4. Displays the message "Loading Linux" by invoking a BIOS procedure.
  5. Then, invokes a BIOS procedure to load the setup( ) code of the Kernel Image. It puts this into RAM starting from address 0x00090200.
  6. Finally it invokes a BIOS procedure. This procedure loads the rest of the Kernel image and puts the image in RAM starting from either address 0x00010000 (called "low address" for small Kernel Images compiled with "make zImage") or address 0x00100000 (called "high address" for big Kernel Images compiled with "make bzImage").
  7. Then, it finally jumps to the setup( ) code.




Boot Loader  << Page 3 of 6  >>