Skip to main content

Booting process of LINUX ( step by step )

There are lot of forum links , articles which explains the booting process of Linux. I am not going to tell any thing different but I would like to show my point of perspective on some extra details of the Linux Booting procedure.

Here we go !



The stages involved in Linux Booting Process are:
BIOS
Boot Loader
    - GRUB
Init
Runlevel scripts
BIOS
  • This is the first thing which loads once you power on your machine.
  • When you press the power button of the machine, CPU looks out into ROM for further instruction.
  • The ROM contains JUMP function in the form of instrucion which tells the CPU to bring up the BIOS
  • BIOS determines all the list of bootable devices available in the system.
  • Prompts to select bootable device which can be Hard Disk, CD/DVD-ROM, Floppy Drive, USB Flash Memory Stick etc (optional)
  • Operating System tries to boot from Hard Disk where the MBR contains primary boot loader.
Boot Loader 
  • It is the first sector of the Hard Disk with a size of 512 bytes.
  • The first 434 - 446 bytes are the primary boot loader, 64 bytes for partition table and 6 bytes for MBR validation timestamp.
This loads the kernel in 3 stages
  • The primary boot loader takes up less than 512 bytes of disk space in the MBR - too small a space to contain the instructions necessary to load a complex operating system. 
  • Instead the primary boot loader performs the function of loading either the stage 1.5 or stage 2 boot loader.
  • Stage 1 can load the stage 2 directly, but it is normally set up to load the stage 1.5. 
  • This can happen when the /boot partition is situated beyond the 1024 cylinder head of the hard drive. 
  • GRUB Stage 1.5 is located in the first 30 KB of Hard Disk immediately after MBR and before the first partition.
  • This space is utilized to store file system drivers and modules.
  • This enabled stage 1.5 to load stage 2 to load from any known location on the file system i.e./boot/grub
  • This is responsible for loading kernel from /boot/grub/grub.conf and any other modules needed
  • Loads a GUI interface i.e. splash image located at /grub/splash.xpm.gz with list of available kernels where you can manually select the kernel or else after the default timeoutvalue the selected kernel will boot
Sample /boot/grub/grub.conf
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.18-194.26.1.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=/dev/VolGroup00/root clocksource=acpi_pm divisor=10
        initrd /initrd-2.6.18-194.26.1.el5.img
title Red Hat Enterprise Linux Server (2.6.18-194.11.4.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.11.4.el5 ro root=/dev/VolGroup00/root clocksource=acpi_pm divisor=10
        initrd /initrd-2.6.18-194.11.4.el5.img
title Red Hat Enterprise Linux Server (2.6.18-194.11.3.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.11.3.el5 ro root=/dev/VolGroup00/root clocksource=acpi_pm divisor=10
        initrd /initrd-2.6.18-194.11.3.el5.img
Kernel
  1. Kernel as soon as it is loaded configures hardware and memory allocated to the system.
  1. Next it uncompresses the initrd image (compressed using zlib into  zImage or bzImage formats) and mounts it and loads all the necessary drivers.
  1. Loading and unloading of kernel modules is done with the help of programs like insmod, and rmmod present in the initrd image.
  1. Looks out for hard disk types be it a LVM or RAID.
  1. Unmounts initrd image and frees up all the memory occupied by the disk image.
  1. Then kernel mounts the root partition as specified in grub.conf as read-only.
  1. Next it runs the init process
Init Process
  • Executes the system to boot into the run level as specified in /etc/inittab
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
         run-level 3  Jan 28 23:29                   last=S
  • Next as per the fstab entry file system's integrity is checked and root partition is re-mountedas read-write (earlier it was mounted as read-only).
Runlevel scripts
0 /etc/rc.d/rc0.d
1 /etc/rc.d/rc1.d
2 /etc/rc.d/rc2.d
3 /etc/rc.d/rc3.d
4 /etc/rc.d/rc4.d
5 /etc/rc.d/rc5.d
6 /etc/rc.d/rc6.d
  • Based on the selected runlevel, the init process then executes startup scripts located in subdirectories of the /etc/rc.d directory.
  • Scripts used for runlevels 0 to 6 are located in subdirectories /etc/rc.d/rc0.d through/etc/rc.d/rc6.d, respectively.
  • Lastly, init runs whatever it finds in /etc/rc.d/rc.local (regardless of run level). rc.localis rather special in that it is executed every time that you change run levels.


    - MBR
Kernel


To be very brief this phase includes loading of the boot loader (MBR and GRUB/LILO) into memory to bring up the kernel.

MBR (Master Boot Record)
NOTE: Now MBR directly cannot load the kernel as it is unaware of the filesystem concept and requires a boot loader with file system driver for each supported file systems, so that they can be understood and accessed by the boot loader itself.

To overcome this situation GRUB is used with the details of the filesystem in /boot/grub.conf and file system drivers

GRUB (GRand Unified Boot loader)


GRUB stage 1: 
GRUB Stage 1.5: 

GRUB Stage 2:
The original file is /etc/grub.conf of which you can observe a symlink file at/boot/grub/grub.conf

default=0


This can be considered the heart of operating system responsible for handling all system processes.

Kernel is loaded in the following stages:

Sample output defining the default boot runlevel inside /etc/inittab
# Default runlevel. The runlevels used by RHS are:
As per above O/P system will boot into runlevel 5

You can check current runlevel details of your system using below command on the terminal
# who -r

A no. of runlevel scripts are defined inside /etc/rc.d/rcx.d
Runlevel  Directory
NOTE: rc.local is not used in all the distros as for example Debian.

Next if everything goes fine you should be able to see the Login Screen on your system.

Popular posts from this blog

HOW TO EDIT THE BCD REGISTRY FILE

The BCD registry file controls which operating system installation starts and how long the boot manager waits before starting Windows. Basically, it’s like the Boot.ini file in earlier versions of Windows. If you need to edit it, the easiest way is to use the Startup And Recovery tool from within Vista. Just follow these steps: 1. Click Start. Right-click Computer, and then click Properties. 2. Click Advanced System Settings. 3. On the Advanced tab, under Startup and Recovery, click Settings. 4. Click the Default Operating System list, and edit other startup settings. Then, click OK. Same as Windows XP, right? But you’re probably not here because you couldn’t find that dialog box. You’re probably here because Windows Vista won’t start. In that case, you shouldn’t even worry about editing the BCD. Just run Startup Repair, and let the tool do what it’s supposed to. If you’re an advanced user, like an IT guy, you might want to edit the BCD file yourself. You can do this

DNS Scavenging.

                        DNS Scavenging is a great answer to a problem that has been nagging everyone since RFC 2136 came out way back in 1997.  Despite many clever methods of ensuring that clients and DHCP servers that perform dynamic updates clean up after themselves sometimes DNS can get messy.  Remember that old test server that you built two years ago that caught fire before it could be used?  Probably not.  DNS still remembers it though.  There are two big issues with DNS scavenging that seem to come up a lot: "I'm hitting this 'scavenge now' button like a snare drum and nothing is happening.  Why?" or "I woke up this morning, my DNS zones are nearly empty and Active Directory is sitting in a corner rocking back and forth crying.  What happened?" This post should help us figure out when the first issue will happen and completely avoid the second.  We'll go through how scavenging is setup then I'll give you my best practices.  Scavenging s

AD LDS – Syncronizing AD LDS with Active Directory

First, we will install the AD LDS Instance: 1. Create and AD LDS instance by clicking Start -> Administrative Tools -> Active Directory Lightweight Directory Services Setup Wizard. The Setup Wizard appears. 2. Click Next . The Setup Options dialog box appears. For the sake of this guide, a unique instance will be the primary focus. I will have a separate post regarding AD LDS replication at some point in the near future. 3. Select A unique instance . 4. Click Next and the Instance Name dialog box appears. The instance name will help you identify and differentiate it from other instances that you may have installed on the same end point. The instance name will be listed in the data directory for the instance as well as in the Add or Remove Programs snap-in. 5. Enter a unique instance name, for example IDG. 6. Click Next to display the Ports configuration dialog box. 7. Leave ports at their default values unless you have conflicts with the default values. 8. Click N