Wednesday, March 27, 2013

Linux Boot Process

 

 

1.BIOS (Basic Input Out System)

The first step of the BIOS is the power-on self test (POST).
The second step is to locate boot device which is both active and bootable .
If all goes well, the BIOS reads the MBR of the boot device(HDD) and loads the program into memory.


2. MBR (Master Boot Record)



The MBR is 512 bytes of the boot device.
446 bytes contain Boot loader (GRUB for Linux).
64 bytes contains partition table,
2 bytes for error check.



3. GRUB (GRand Unified Bootloader)


The purpose of a bootloader is to load the operating system.


GRUB works in stages called Stage1, and Stage 2.


Stage1
  1. The stage1 code of GRUB is written within the 512 bytes of the MBR.Its sole job is to locate the second stage boot loader .

Stage 2
  1. This stage presents users with a Graphical screen showing different OS.
  2. From this screen user can select which OS to boot,if no selection made the boot loader loads the default OS


The configuration file for the above screen is written in the /boot/grub/grub.conf





    Once user has determined which kernel to boot.It locates the corresponding kernel binary in the /boot/ directory ie: /boot/vmlinuz-<kernel-version>

Then the bootloader load initramfs images into memory.The initramfs is used by the kernel to load drivers and modules necessary to boot the system.

Once the kernel and the initramfs image(s) are loaded into memory, the boot loader hands control of the boot process to the kernel.


4. Kernel

Kernel image is not an executable file, but a compressed image. Typically this is a bzImage or zImage.

During the boot of the kernel, the initial-RAM disk (initrd) also loads into memory.This initrd serves as a temporary root file system in RAM and allows the kernel to access disks and the file systems on those disks.

Then the kernel initializes and configures the computer's memory and configures the various hardware attached to the system, including all processors, I/O subsystems, and storage devices .

It then looks for the compressed initramfs image(s) in a predetermined location in memory, decompresses it directly to /sysroot/, and loads all necessary drivers.

The kernel then creates a root device, mounts the root partition read-only, and frees any unused memory. At this point, the kernel is loaded into memory and operational.
kernel starts the first user-space application which is in /sbin/init

5. INIT - initialization


On system bootup, the init process runs the /etc/rc.d/rc.sysinit script to setup the system.rc.sysinit reads the /etc/sysconfig/clock ,/etc/rc.serial file. 
 
Next, the init command sets the source function library, /etc/rc.d/init.d/functions, for the system, which configures how to start, kill, and determine the PID of a program.


The init command then runs the /etc/inittab script .



Runlevels are a state, or mode, defined by the services listed in the SysV /etc/rc.d/rc<x>.d/ directory, where <x> is the number of the runlevel.
 
SysV runlevels define how the system is started and what services are available in the running system.


Run Level 0 Halt
Run Level 1 Single user mode
Run Level 2 Multiuser but without NFS
Run Level 3 Full multiuser mode (text mode login)
Run Level 4 unused / User-definable
Run Level 5 X11 (graphical login )
Run Level 6 reboot


After booting, the system starts as defined in /etc/inittab in the line initdefault
 
As per default runlevel settings, system will reads and execute the programs from
following directories.

  1. Run Level 0 – /etc/rc.d/rc0.d/
  2. Run Level 1 – /etc/rc.d/rc1.d/
  3. Run Level 2 – /etc/rc.d/rc2.d/
  4. Run Level 3 – /etc/rc.d/rc3.d/
  5. Run Level 4 – /etc/rc.d/rc4.d/
  6. Run Level 5 – /etc/rc.d/rc5.d/
  7. Run Level 6 – /etc/rc.d/rc6.d/
/etc/rc0.d/ is linked to /etc/rc.d/rc0.d/ directory. Under /etc/rc.d/rc0.d/ directory we could see programs starting with S and K which means startup and kill respectively.



Then /etc/inittab script forks an /sbin/mingetty process for each virtual console (login prompt) allocated to the runlevel. 
 
Runlevel 2 through 5 have all six virtual consoles
Runlevel 1 (single user mode) has one,
Runlevels 0 and 6 have none. 
 
The /sbin/mingetty process opens communication pathways to tty devices sets their modes,

This prints the login prompt, accepts the user's username and password, and initiates the login process.






No comments:

Post a Comment