Linux Booting
Linux Booting
A kernel is the central part of an operating system. It manages the operations of the computer and
the hardware, most notably memory and CPU time.[1]
The kernel is a computer program at the core of a computer's operating system that has complete
control over everything in the system. It is the "portion of the operating system code that is always
resident in memory", and facilitates interactions between hardware and software components
The Kernel is responsible for low-level tasks such as disk management, memory management,
task management, etc When the computer starts, it goes through some initialization (booting)
functions, such as checking memory. It is responsible for assigning and unassigning memory space
which allows software to run.
BIOS
MBR
MBR stands for Master Boot Record.
MBR contains both program code and partition table details.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components
1) primary boot loader info in 1st 446 bytes
2) partition table info in next 64 bytes
3) mbr validation check in last 2 bytes.
It contains information about GRUB (or LILO in old systems).
So, in simple terms MBR loads and executes the GRUB boot loader.
Master Boot Record, is the first place where boot loaders begins to start. MBR is a 512 byte sector
located in the first sector of hard disk. MBR contains both program code and partition table details.
Please see the image added below:
When allocating disk space for a partition, the first sector or data unit for each partition is always
reserved for programmable code used in booting process. The very first sector of the hard disk is
reserved for same purpose and it’s called the Master Boot Record. In case of a mechanical
spinning disk, sector 1 of cylinder 0, head 0.
First 446 byte are the primary boot loader which contains both executable code and error message
text.
Next 64 bytes contains the partition table. This section contains records for each of four partitions. In
the above image P1 represents Partition 1, P2 for Partition 2 and so on.
4 x 16 bytes = 64 bytes
The last two bytes known as magic number (0xAA55). This number is used for the validation check
of MBR.
When booting from a hard disk, the BIOS starts by loading and executing boot loader code. The
MBR size is not enough sometimes to execute the complete boot loader code. Because, its size is
larger than the available space in MBR. So booting has to be done in different stages. These stages
are different in different boot loader on your system. Yeah, it’s time to move over to Stage 2 boot
loader
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.
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.
The total amount of space allocated for the actual bootstrap code in
a classic generic MBR is 446 bytes. The 446 Byte file for stage 1 is named
boot.img and does not contain the partition table which is added to the boot
record separately.
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 such as the standard EXT and
other Linux filesystems, FAT, and NTFS. and modules.(mounting is done by
system)IMPORTANT
This enabled stage 1.5 to load stage 2 to load from any known location on the file
system i.e. /boot/grub
GRUB Stage 2:
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
timeout value the selected kernel will boot
The original file is /etc/grub.conf of which you can observe a symlink file
at /boot/grub/grub.conf
Sample /boot/grub/grub.conf
default=0
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
This can be considered the heart of operating system responsible for handling all system processes.
After the selected kernel is loaded into memory and begins executing, it must
first extract itself from the compressed version of the file before it can perform
any useful work. Once the kernel has extracted itself, it loads systemd, which
is the replacement for the old SysV init program, and turns control over to it.
1. Kernel as soon as it is loaded configures hardware and memory allocated to the system.
2. Next it uncompresses the Initramfs image (compressed using zlib into zImage or bzImage
formats) and mounts it and loads all the necessary drivers.
3. Loading and unloading of kernel modules is done with the help of programs like insmod, and
rmmod present in the initrd image.
4. Looks out for hard disk types be it a LVM or RAID.
5. Unmounts initrd image and frees up all the memory occupied by the disk image.
6. Then kernel mounts the root partition as specified in grub.conf as read-only.
7. Next it runs the SYSTEMD (REPLACMENT OF init ) process
systemd
systemd is the mother of all processes and it is responsible for bringing the
Linux host up to a state in which productive work can be done
Some of its functions, which are far more extensive than the old init program,
are to manage many aspects of a running Linux host, including
NOTE:-