How a Linux Machine Boots?
How A Linux Machine Boots?
The sequence that takes place during booting up a Linux machine is as.
BIOS :- Basic Input / Output System:
- Performs some system integrity checks.
- Searches, loads, and executes the boot loader programme.
- It looks for the bootloader in floppy, cd-rom or hard drive. We have options to change the boot sequence by pressing F2
- Once the bootloader program is detected and loaded into memory, BIOS gives the control to it.
- So, BIOS loads and executes the MBR bootloader
MBR: Master Boot Record:
- It is located in the 1st sector of the bootable disk, typically /dev/hda or /sda.
- MBR is less than 512 bytes, this has 3 components.
- Primary bootloader info in 1st 446 bytes
- Partition table info in next 64 bytes.
- MBR validates check in last 2 bytes.
It contains information about GRUB (LILO is old systems)
GRUB: Grand Unified Bootloader
- If you have multiple kernel images installed on your system, you can choose which one to be executed.
- GRUB displays a splash screen. Waits for a few seconds, if you don`t enter anything, it loads the default kernel image as specified in the grub configuration file.
- GRUB has the knowledge of the filesystem.
- Grub configuration file is /boot/grub/grub/grub.conf (/etc/grub.conf is a link to this).
- Eg for CentOS the grub.conf is.
So, as shown above, both kernel and initrd image are available on grub.conf file.
- Mounts the root file system as specified in the “root=” in grub.conf
- Kernel executes the /sbin/init program
- Since init was the 1st program to be executed by Linux kernel, it has the process ID (PID).
- Do, ps –ef | grep init and check the PID
- Initrd = Initial RAM Disk.
- Initrd is used by the kernel as temporary root file system until the kernel is booted and the root file system is mounted. It also contains necessary drivers compiled inside which helps it to access the hard drive partitions and other hardware.
Looks at the /etc/inittab file to decide the Linux run Level.
Following are the available run levels.
- 1-Single User Mode
- 2- Multiuser without NFS.
- 3-Full multiuser mode
- 5- X11
- 6- reboot
- Init identifies the default inilevel from /etc/inittab and uses that to load all appropriate program.
- Execute “grep initdefault /etc/inittab” on your system to identify the default run level.
- Don`t set your default run level to 0 and 6.
- Set to 3 or 5.
- When the Linux system is booting up, you might see various services getting started, For Example, it might say “Starting sendmail .. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
- Depending on your default init level settings, the system will execute the programs from one of the following directories.
Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 6 – /etc/rc.d/rc6.d/
Please note that there are also symbolic links available for these directories under /etc
So, /etc/rc0.d is linked to /etc/rc.d/rc0.d
- Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
- The program starts with “S” are used during Startup; S= Start-up.
- The program starts with “K” are used during Shutdown; K = KILL.
There are numbers right to “K” & “ S”, they are the sequence number in which the program should start or kill.
- S12syslog is to start the syslog daemon, which has the sequence number of 12.
- S80Sendmail is to start the Sendmail daemon, which has the sequence number of 80.
So, syslog program will be started before sending mail.