The Linux Boot Process


The process of starting the Computer or Operating System is generally termed as Boot Process. Linux boot process can be divided in five stages :

  1. BIOS
  2. Boot Sectors (MBR)
  3. Boot Loaders (Grub, LILO etc)
  4. Linux Kernel
  5. User Space

BIOS

When the system is first booted the processor executes some instructions located at one known address in personal computers this location is Basic Input Output System. BIOS keeps record of many things including the peripheral devices, first boot device, memory etc. When the boot device is found boot sectors of the device are scanned. Boot device can be a hard drive, CD-ROM, USB Disk or even Floppy Disks.

typical BIOS view

typical BIOS view

Boot Sectors

The boot sector loader that resides in the MBR is a 512-byte image containing both program code and a small partition table (see Figure). The first 446 bytes are the primary boot loader, which contains both executable code and error message text. The next sixty-four bytes are the partition table, which contains a record for each of four partitions (sixteen bytes each). The MBR ends with two bytes that are defined as the magic number (0xAA55). The magic number serves as a validation check of the MBR.

MBR

The job of the primary boot loader is to find and load the boot loader. It does this by looking through the partition table for an active partition. When it finds an active partition, it scans the remaining partitions in the table to ensure that they’re all inactive. When this is verified, the active partition’s boot record is read from the device into RAM and executed.

Boot Loaders

The task of boot loader is mainly to load Linux Kernel and optional initial RAM Disk. Linux mainly comes with two boot loaders namely GRUB (Grand Unified Boot Loader) and LILO(Linux Loader).

When loaded boot loader optionally displays a list of available kernels. The list is usually defined in /etc/grub.conf file. With the boot loader in memory, the file system is consulted, and the default kernel image and initrd image are loaded into memory. With the images ready, the boot loader invokes the kernel image.

 

Boot Loader

 

Linux Kernel

As default kernel image and initrd image are ready in memory, the kernel stage begins here. Typically this is not any executable kernel but a compressed version of the kernel image. At the beginning of this compressed image one routine is present which initializes some hardware and then starts decompressing the kernel, after decompression the kernel is placed into memory by that routine. If an initial RAM disk image is present, this routine moves it into memory and notes it for later use. The routine then calls the kernel and the kernel boot begins. The kernel boot involves many things like setting up interrupts, peripheral initialization, setting up hardware clock. The kernel boot process is visible to users if the boot is set in verbose mode. The following figure gives a quick view of boot process in verbose mode.

Linux Boot Verbose mode.

During the boot of the kernel, the initial-RAM disk (initrd) that was loaded into memory by the boot loader is copied into RAM and mounted. This initrd serves as a temporary root file system in RAM and allows the kernel to fully boot without having to mount any physical disks. Since the necessary modules needed to interface with peripherals can be part of the initrd, the kernel can be very small, but still support a large number of possible hardware configurations. After the kernel is booted, the root file system is pivoted (via pivot_root) where the initrd root file system is unmounted and the real root file system is mounted.

Init

After the kernel is booted and initialized, the kernel starts the first user-space application. This is the first program invoked that is compiled with the standard C library. Prior to this point in the process, no standard C applications have been executed.

In a desktop Linux system, the first application started is commonly /sbin/init. But it need not be. Rarely do embedded systems require the extensive initialization provided by init (as configured through /etc/inittab). In many cases, you can invoke a simple shell script that starts the necessary embedded applications.

For more details following references will be really useful :

Advertisements

About Amol

I'm blogger, avid read, photographer and book lover. Reading a lot of good stuff and sharing it with the world are my passions.
This entry was posted in Linux, Tricks and Tips. and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s