Friday, July 3, 2015

Linux Booting Process

1.Reading the Boot Loader

The boot loader is a small piece of software usually at the very beginning of a large format like a disk or external storage device that contains only enough code to launch the operating system.

"A boot loader, also called a boot manager, is a small program that places the operating system of a computer into memory".

There are two types of boot loader which Linux uses: 

a) LILO(LInux LOader)
  • Is a boot loader for Linux and was the default boot loader for most Linux distributions.
  • Today most distributions use GRUB as the default boot loader. 
b) GRUB(GRand Unified Bootloader)
  • Is a boot loader package from the GNU project.
  • Provides a user the choice to boot one of multiple OS installed on a computer or select a specific kernel configuration.
Screen shot of GRUB boot loader. 

  • The boot loader is located on the Master Boot Record(MBR) or GUID Partition Table(GPT).
  • Firmware (BIOS or UEFI) provides a list of the boot devices to choose from (DVD, USB, Harddisk, Network via PXE).

2.Kernel Initialization

Boot loader opens and initializes the kernel.

  • Compressed kernel image is decompressed.
  • Kernel detects amount of RAM available and creates internal data structures.
  • kernel memory is unavailable to user space programs.

3.Device Detection

Detect and configure devices.

  • Kernel begins probing devices such as processors, I/O subsystems, storage devices.
  • Compressed Initial RAM disk "initrd" is decompressed and mounted.
  • "initrd" is for laoding a temporary root file system into memory, which may be used as a part of the Linux startup process.
  • "initrd" contains various executables and drivers that permit the real root file system to be mounted, after which the initrd is unmounted and its memory is freed.
  • Essential drivers such as RAID, LVM , encrypted file systems are loaded before "initrd" is unmounted and memory is freed. 

In the above screen shot-
  • 1st line tells about the hard-drive to boot from.
  • 2nd line tell what kernel to boot from i.e. the location of compressed kernel image. Here vmlinuz-2.6.32-358.e.16.x86 is the compressed kernel image.
  • 3rd line tells about the "initrd" (Initial RAM disk) location.Here initramfs-2.6.32-358.e.16.x86_64.img is image file of "initrd" to be mounted.


4.Process Creation

  • Kernel creates important processes that it uses internally such as kjournald, kswapd, khubd.
  • The Upstart init daemon, the "parent of all process" is spawned by the kernel with PID (Process ID) 1.
  • Upstart init daemon startup all the other processes on the system.
  • Local, virtual and swap filesystems are mounted.


5.Service startup
  • The init process which is started by the kernel and managed by "upstart" system runs a variety of jobs and scripts to load different system services such as power management, hardware interfaces and network daemon.
  • Traditionally in Linux, the startup process is handled by System V init. System V was old type of UNIX and Linux inherited System V.
  • System V has no. of limitations, starting to be replaced by much more flexible, powerful yet simple daemon called upstart.
  • SysV scripts are in /etc/init.d
  • Upstart maintains its job in /etc/init
  • For each runlevel there is links to /etc/rc?.d directory.