When we power on, the power is supplied to SMPS (Switched mode power supply) which converts AC to DC.
The DC power is supplied to all the devices that are connected to system.
Once the processor gets power, the processor executes BIOS; it is a code stored in flash memory in the motherboard. BIOS determine which hardware need to be loaded for booting.
BIOS will do 2 task: Run POST operation. (Power on self test)
Selecting first boot device.
POST is a process of checking hardware availability.
After POST, it will select first boot device, which has mentioned in BIOS.
The BIOS will load MBR from first boot device. MBR is loacted in first sector of the harddisk (or last sector depending upon vendor). Its size is 512 bytes.
MBR contains following details.
>Primary boot loader code(This is of 446 Bytes)
>Partition table information(64 Bytes)
>Magic number(2 Bytes) ( Validation check). This is used for retrieving the MBR if it corrupted.
MBR contains machine code instructions for booting the machine, called a boot loader, along with the partition table.
Once MBR loads the boot loader into memory, it gives control to boot loader. Here there are 3 stages in the boot loader. Stage 1, 1.5 and 2.
>First stage is a small machine code in MBR and its role is to load stage 1.5 or second stage boot loader and load the first part of it into memory.
>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 utilised to store file system drivers and modules.
This enabled stage 1.5 to load stage 2 to load from any known loaction on the file system i.e. /boot/grub
>Once the second stage boot loader is in memory, it presents the user with a graphical screen showing the different operating systems or kernels it has been configured to boot.
i.e. splash image located at /grub/splash.xpm.gz with list of available kernels where you can manually select the kernel. On this screen a user can use the arrow keys to choose which operating system or kernel they wish to boot and press Enter.
The 2nd stage is responsible for loading kernel from /boot/grub/grub.conf (Grub configuration file) and any other modules needed
Once the second stage boot loader has determined which kernel to boot, it locates the corresponding kernel binary in the /boot/ directory. The kernel binary is named using the following format — /boot/vmlinuz-<kernel-version> file.
The boot loader then places one or more appropriate initramfs images into memory. Next, the kernel decompresses these images from memory to /sysroot/, a RAM-based virtual file system, via cpio. 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.
As said earlier, initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. The kenel loads all necessary drivers used for boting process.
Unmounts initrd image and frees up all the memory occupied by the disk image. 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 executes the /sbin/init program.
When the init command starts, it becomes the parent or grandparent of all of the processes that start up automatically on the system. Since it is the first process, it has the pid 1. First, it runs the /etc/rc.d/rc.sysinit script, which sets the environment path, starts swap, checks the file systems, and executes all other steps required for system initialization.
After The init command then runs the /etc/inittab script, and determine which runlevel should system run.
Depending on the runlevel it will execute the runlevel files from /etc/rc.d/ directory.
These are the runlevels, specified in inittab.
0 – halt
1 – Single user mode
2 – Multiuser, without NFS
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot
When booting to runlevel 5, the init program looks in the /etc/rc.d/rc5.d/ directory to determine which processes to start and stop. Below are the some files in the /etc/rc.d/rc5.d/ directory.
S97rhnsd -> ../init.d/rhnsd
K15httpd -> ../init.d/httpd
/etc/rc0.d/ –Contain Start/Kill scripts which should be run in Runlevel 0
/etc/rc5.d/ –Contain Start/Kill scripts which should be run in Runlevel 5
None of the scripts that actually start and stop the services are located in the /etc/rc.d/rc5.d/ directory. Rather, all of the files in /etc/rc.d/rc5.d/ are symbolic links pointing to scripts located in the /etc/rc.d/init.d/ directory. Symbolic links are used in each of the rc directories so that the runlevels can be reconfigured by creating, modifying, and deleting the symbolic links without affecting the actual scripts they reference.
Here K indicates Kill and S indicates start.
First init command stops all of the K symbolic links and it then starts S synmbolic link, It starts based on the priority number based on the name.
Then init program executes /etc/rc.d/rc.local file. This file is useful for system customization.
The /etc/rc.d/rc.local script is executed by the init command at boot time or when changing runlevels.
Once everything is completed the control is given back to the kernel. Once the Kernel get the control it start multiple instances of “getty” (/sbin/mingetty) which waits for console logins which spawn one’s user shell process and gives you user prompt to login.