Linux Interview Q&A #58 - Explain Linux Boot Process ? #linux #viral
Summary
TLDRThis video script offers an insightful guide to the Linux boot process, essential for troubleshooting and system repair. It begins with the server power-up, followed by the BIOS's POST hardware check and bootable device search. The MBR's role in loading the bootloader, GRUB, is explained, detailing its stages and configuration. The script then delves into the kernel's responsibilities, including initializing hardware, loading drivers, and preparing the root file system. Finally, it touches on systemd's role in managing system services and reaching the operational state, providing a comprehensive overview of Linux's startup sequence.
Takeaways
- š The Linux boot process begins with powering up the server, which triggers the BIOS to perform POST (Power-On Self-Test) to check hardware integrity.
- š BIOS, located in ROM, scans for bootable devices and looks for the MBR (Master Boot Record), the first sector of a bootable disk, to locate the bootloader.
- š The MBR consists of a small program (446 bytes), a partition table (64 bytes), and a magic number (2 bytes) for error detection.
- š ļø The bootloader, historically Lilo and now commonly GRUB or GRUB2, is responsible for loading the operating system.
- š GRUB has multiple stages: stage 1 is in the MBR, stage 1.5 acts as an intermediary for filesystem interpretation, and stage 2 is the main GRUB image.
- š The bootloader reads configuration from files like '/boot/grub/grub.conf' or '/boot/grub2/grub.cfg' to determine how to load the kernel and initrd images.
- š¾ The kernel initializes hardware, locates and decompresses the initrd image, loads necessary drivers, and initializes virtual devices like LVM or RAID.
- š Once the kernel has set up the system, it creates a root device, mounts the root partition, and starts the first process (pid 1), which is now systemd in modern systems.
- š Systemd, known as the 'mother of all processes,' manages the boot process by mounting filesystems, starting services, and bringing the system to a productive state.
- š The boot process concludes with systemd reading '/etc/systemd/system/default.target' to determine the system's target state, such as graphical for desktops.
Q & A
What is the first step in the Linux boot process?
-The first step in the Linux boot process is powering up the server, after which the hardware transfers control to the BIOS.
What are the two important tasks performed by BIOS during the boot process?
-BIOS performs a Power-On Self-Test (POST) to check the health of all hardware components and then scans for bootable devices.
What is the significance of the Master Boot Record (MBR) in the boot process?
-The MBR is the first sector of a bootable storage device, containing a small program that points to a bootloader, a partition table, and a magic number for error detection.
What is the role of the bootloader such as GRUB or GRUB2 in the Linux boot process?
-The bootloader, like GRUB or GRUB2, is responsible for loading the operating system by reading configuration settings and identifying the kernel and initrd images.
What are the different stages of GRUB and what do they do?
-GRUB has stages 1, 1.5, and 2. Stage 1 is in the MBR, stage 1.5 is an intermediate stage for file system interpretation, and stage 2 is the main GRUB image that loads the operating system.
What does the kernel do after it is loaded during the boot process?
-Once the kernel is loaded, it initializes and configures the computer's memory and hardware, decompresses itself, locates and loads the initrd image, and initializes drivers for file systems like LVM or RAID.
What is the purpose of the initrd image in the boot process?
-The initrd image contains drivers and system information needed during the boot process before the main system's root file system is available.
How does the kernel prepare the system for the final boot steps?
-The kernel creates a root device, mounts the root partition in read-only mode, freezes unused memory, and starts the first process (pid 1), which is managed by init or systemd in modern systems.
What is the role of systemd in the boot process of a Linux system?
-Systemd is responsible for managing the boot process by starting services, mounting file systems, and bringing the Linux host to a state where productive work can be done.
How does systemd determine the system's boot target?
-Systemd reads the /etc/systemd/system/default.target file to identify the default target, which could be a graphical target for desktop workstations, equivalent to run level 5 in older systems.
Outlines
š„ļø Linux Boot Process Overview
The paragraph discusses the Linux boot process, starting from powering up the server to the initial steps of the boot sequence. It explains how the control is transferred from the hardware to the BIOS, which is located in the ROM. BIOS performs a POST (Power-On Self-Test) to check the health of all hardware components and then scans for bootable devices. It looks for the boot sector or boot loader, which is typically found in the MBR (Master Boot Record) of the first sector of a bootable device. The MBR consists of the initial 446 bytes of low-level code that points to a boot loader like GRUB or GRUB2, followed by a 64-byte partition table, and ending with a magic number for error detection. The paragraph also covers the evolution of bootloaders from LILO to GRUB and GRUB2, explaining that GRUB has multiple stages, with stage 1 being in the MBR and stage 1.5 and 2 handling file system interpretation and loading the operating system respectively.
š§ Kernel and System Initialization
This paragraph delves into the role of the kernel in the boot process once the bootloader has transferred control. It describes how the kernel initializes and configures the computer's memory and hardware, uncompresses itself, and looks for the initrd (initial RAM disk) image. The kernel then loads necessary drivers, initializes virtual devices related to the file system such as LVM or RAID, and unmounts the initrd to free up memory. The kernel proceeds to create a root device, mounts the root partition in read-only mode, and freezes unused memory. The final step involves starting the first process (pid 1), which in modern systems is handled by systemd, replacing the traditional init process. Systemd is responsible for managing various aspects of the running Linux system, including mounting file systems, starting services, and devices. It reads from /etc/fstab to mount devices and identifies the default target from /etc/systemd/system/default.target, which determines the system's boot target, such as a graphical target for desktops.
Mindmap
Keywords
š”BIOS
š”POST
š”Boot Sector
š”MBR
š”Bootloader
š”GRUB
š”Kernel
š”Initrd
š”Systemd
š”Boot Process
Highlights
Understanding the Linux boot process is crucial for troubleshooting and fixing the operating system.
The boot process begins when the server is powered up and control is transferred to BIOS.
BIOS performs POST to check the health of all hardware components.
BIOS scans for bootable devices and looks for the boot sector to provide the bootloader.
MBR is the first sector of a bootable media, containing a small low-level code pointing to a bootloader.
GRUB or GRUB2 is commonly used as the bootloader in modern systems.
Bootloader stages include stage 1 in MBR, stage 1.5 for filesystem interpretation, and stage 2 for the main GRUB image.
GRUB configuration settings are found in /boot/grub/grub.conf or /boot/grub2/grub.cfg.
The kernel initializes and configures computer memory and hardware during the boot process.
The kernel looks for the initrd image, decompresses it, and loads required drivers.
Initrd is used for initializing drivers for filesystems like LVM or RAID.
The kernel mounts the root partition in read-only mode after initializing drivers.
Systemd is the first process started with pid 1, responsible for bringing the Linux host up.
Systemd manages mounting file systems, starting services, and devices attached to the Linux system.
Systemd starts by mounting devices defined in /etc/fstab and identifying the default target to boot into.
The boot process is completed by systemd starting the required dependencies and reaching the specified target.
Transcripts
Hello Everyone.Ā Ā
This is one of the interesting question which youĀ will find in most of the interviews. If you leaveĀ Ā
apart interviews one need to understand the bootĀ process if they want to troubleshoot the LinuxĀ Ā
or in bad you have to fix the operating system,Ā you should undertand exactly how linux boots. Ā
So, rather than lot of text with theory we wouldĀ try to cover them with help of some diagramaticĀ Ā
steps. Now, very first step start with your serverĀ and you Power up the server, then the step ofĀ Ā
event that happen is your hardware basicallyĀ tranfer the control to a program called BIOS.Ā Ā
Now, this bios resides in the ROM, so it has toĀ perform two important task. The first one is POST,Ā Ā
where it will perform the check of, the healthĀ check of all the hardware component attachedĀ Ā
to your server, so that in case any of theĀ hardware component is bad, it will stop systemĀ Ā
from starting. And you will notice a beep ofĀ sounds. Once the hardware are good then, it willĀ Ā
start scanning the list of bootable devices. Your system might be attached with lot of devicesĀ Ā
like floppy drive, optical drives, or usb orĀ anything else. SO it would start looking for theĀ Ā
bootable devices. And it will start looking forĀ the first sector or you would say a BOOT SECTOR,Ā Ā
which can provide you the boot loader. So, onceĀ it can find the boot sector or the boot loader,Ā Ā
then it will read the MBR on that disk orĀ whatever device it is, and load the program. Ā
Now, if you don't know what MBR is, it'sĀ basically the first sector or the first 512 bytes,Ā Ā
usually it finds in the first sector ofĀ your bootable media. If it's a hard disk,Ā Ā
it's path is something as /dev/hda or maybeĀ something like /dev/sda. Now, it comprises ofĀ Ā
first 446 bytes, which is a small low level code,Ā which basically points to a boot loader, whateverĀ Ā
it is GRUB GRUB2. or anything else, or on a diskĀ it can point to another hard disk as well. Ā
Now the next 64 bytes, these are the partitionĀ table and rest 2 are the magic number, theseĀ Ā
are sometime used for the error detection or evenĀ for the sanity of the media which you are using.Ā Ā
Now if we speak about bootloader previouslyĀ there was Lilo so we would not discuss muchĀ Ā
on the Lilo but nowadays it's grubĀ or the recent one have the grub2Ā Ā
so its major rule is just to load the operatingĀ system. It's a program basically written in theĀ Ā
MBR and /boot partition and basically orĀ hard disk and it loads operating system.Ā Ā
So this code in the past basically used to fitĀ in the first four four six bytes of your MBR,Ā Ā
but since the size is increasing the complexity ofĀ the operating system is increasing and sometimesĀ Ā
we have to boot almost any operating systemĀ this size is increasing with size with time.Ā Ā
Now BOOT again, the grub is not a single programĀ it has several stages so the stage 1, basicallyĀ Ā
it's the code in the first this is the main codeĀ which is found in the first 512 bytes of MBRĀ Ā
so the size is limited so usually it points toĀ the next stage of grub that can be 1.5 or 2.Ā Ā
Now this 1.5 stage is the intermediateĀ stage basically it allows us the fileĀ Ā
system to be interpreted properlyĀ then you will find the in stage 2.Ā Ā
So it's a main grub image and it's usually decidedĀ on the file system in the slash boot partitionĀ Ā
or add the slash boot grub whatever path itĀ is it usually reads the boot grub2/grub.comnfĀ Ā
or the old systems bootcrubgrub.com for theĀ configuration settings that how it will loadĀ Ā
the kernel or something like that. And also it will try to identify fromĀ Ā
the slash boot or grub.conf will try toĀ find the kernel and the initrd images. Ā
Now what kernel is and what willĀ perform later let's see further. Ā
Now when grub transfer the controlĀ to the kernel and kernel is booting,Ā Ā
we can see a lot of messages and it can be easilyĀ suppressible through a RHGB quiet. So, when aĀ Ā
kernel is loaded it immediately initializes andĀ configure the computer memory and various HardwareĀ Ā
attached to the system. That includes somethingĀ like processors, I/O systems, storage devices.Ā Ā
Then it has to uncompress itself so itĀ start looking for the initrd image in aĀ Ā
predetermined location in the memory, nowĀ decompresses it mount it and load all theĀ Ā
required drivers for the next steps. Then itĀ would initialize a virtual device related toĀ Ā
your file system so your storage whatever fileĀ system you have carried over storage like lvm,Ā Ā
raid. Because once initRd is removed or unmountedĀ it cannot be accessed, so it basically initializesĀ Ā
all these drivers and then free up all theĀ memory that disk image has occupied. Ā
Now, once these steps are doneĀ it create a root(/) deviceĀ Ā
it mounts your root partition in a read-onlyĀ mode and then freeze all the unused memory.Ā Ā
so everything is done a root is there but stillĀ there's no other steps remained with kernel too.Ā Ā
So the last step what it will perform is start youĀ a process that start with the pid1 in the previousĀ Ā
sysvinit systems that process is called init butĀ for the now the new systems that is a systemd. Ā
Now systemd,Ā Ā
if you say it's a mother of all the processesĀ and is responsible for bringing the Linux hostĀ Ā
up to a state in which the productive work canĀ be done. Some of its function which are moreĀ Ā
extensive than the old init program are to manageĀ many aspects of a running Linux host, includesĀ Ā
mounting file system starting the services and theĀ devices attached to a particular linux system. Ā
so now what we'll do for firstly it willĀ start mounting the devices defined in theĀ Ā
/etc/fstab. So any swap files or anĀ additional partition it start mounting.Ā Ā
Now it will start having the access ofĀ /etc/ so let's start reading the fileĀ Ā
/etc/systemd/system/default.target to identifyĀ in which default Target I have to boot.Ā Ā
Now once the default default is nothing justĀ a symbolic link to the true target file,Ā Ā
so for a desktop workstation it wouldĀ be like a graphical Target which wasĀ Ā
equivalent to run level 5 in the oldĀ systems. so once identify the TargetĀ Ā
in which it has to boot it start lookingĀ for the file for the required dependenciesĀ Ā
and once all the dependencies are up, your systemĀ will start putting into the required Target. thatĀ Ā
is in short a small version how the completeĀ boot process happens anything else you haveĀ Ā
or any questions you have always feel freeĀ to put in the comment section thank you bye.
Browse More Related Video
5.0 / 5 (0 votes)