The whole process of booting Linux

1. Brief description

1. Boot BIOS self-test 2. MBR
boot 3.
grub boot menu
4. Load the kernel
5. Start the init process
6. Read the inittab file and execute scripts such as rc.sysinit, rc

7. Start mingetty and enter the system login interface

2. Graphical description


3. System startup process

(1) BIOS self-check

After the power-on self-test is completed, the CPU first reads the BIOS program located in the CMOS, and searches for the bootable devices one by one according to the boot sequence (Boot Sequence) set in the BIOS. After finding the bootable device, go to the first fan of the device. Read the MBR in the area.

(2) MBR boot

MBR (Main Boot Record), MBR exists in the bootable disk: 0 track, 0 cylinder, 1 sector. Occupies 512 bytes, it is mainly used to tell the computer from which partition of the selected bootable device to load the boot loader (Boot loader), the following contents exist in the MBR:
   1) Boot Loader occupies 446 bytes and stores the operating system (OS) related information, such as operating system name, operating system kernel location, etc. Its main function is to load the kernel into memory to run.
   2) Partition Table partition table, occupies 64 bytes, each primary partition occupies 16 bytes, 4*16=64 bytes (this is why a hard disk can only have 4 primary partitions)

   3) The partition table validity mark occupies 2 bytes (the last two bytes "55, AA" are the end mark of the partition)

In this step, the CPU reads the MBR into memory.


(3) GRUB loading

The grub boot process can be divided into three stages:
1) Stage 1 (stage1):
In the traditional conventional MBR, the actual space occupied by the boot code is 446 bytes. This phase 1 446-byte file is usually called the boot image (boot.img).
Since the boot record has to be very small, it can't be very intelligent and cannot understand the file system structure. So the only function of stage 1 is to locate and load the code of stage 1.5.

2) Stage 1.5 (stage1.5):
The code for stage 1.5 must be located between the boot record and the first partition of the device. This space is free for historical technical reasons. The starting position of the first partition leaves 62 sectors of 512 bytes (31744 bytes in total) between sector 63 and MBR (sector 0), which is used to store the code image core.img of stage 1.5 document. 

Because there is more storage space for phase 1.5, which means that phase 2 of GRUB2 can be placed on the standard EXT file system, the function of phase 1.5 is to start executing the driver for the /boot file system that holds the phase 2 files, and load related drivers.

3) Stage 2 (stage2):
The main function of GRUB stage 2 is to locate and load the Linux kernel files in /boot into memory, such as: vmlinuz, initrd, initramfs, etc., and transfer control to the kernel. This stage also needs to load some kernel runtime modules from /boot/grub2/i386-pc directory.



(4) Kernel kernel initialization

After Kerenl gets system control, it must initialize itself, load and run vmlinuz, initrd, initramfs, etc.

(1) Detect all identifiable hardware devices;
(2) Load the hardware driver, that is, load the driver of the device where the real root file system is located (the driver may be loaded by means of ramdisk);
(3) Read-only mode Mount the root file system; if there is a temporary file system (virtual root) with the help of ramdisk, the root switch will be performed after this step; otherwise, the root switch will not be performed.
(4) Run the first application in user space: /sbin/init.

(5) Start the first user process INIT

After the user process, /sbin/init executes the following in sequence:
1) /etc/rc.d/rc.sysinit
1. Obtain the network environment 
2. Mount the device 
3. The boot screen Plymouth (replaces the previous RHGB) 
4. Determine whether SELinux is enabled 
5, the welcome screen displayed during the boot process 
6, initialize the hardware 
7, load the user-defined module 
8, configure the parameters of the kernel 
9, set the host name 
10, synchronous memory 
11, device mapper and related initialization 
12. Initialize the software disk array (RAID) 
13. Initialize the file system function of LVM 
14. Check the disk file system (fsck) 
15. Set the disk quota (quota) 
16. Re-mount the system disk in readable and writable mode 
17. Update the quota (Not necessary) 
18. Start the system virtual random number generator 
19. Configure the machine (not necessary) 
20. Clear the temporary files during the boot process 
21. Create the ICE directory 
22. Start the swap partition (swap) 
23. Write the boot information After init in the /var/log/dmesg file
executes /etc/rc.d/rc.sysinit, it will execute /etc/inittab to set the default level of system operation.

2) /etc/rc.d/inittab
There are seven run levels [0-6] in linux. The default run level of the system is 3,
rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d , so execute rc3.d script, which eventually points to the corresponding program in init.d.

3) /etc/rc.d/rc.local
   Finally, the /etc/rc.d/rc.local script will be executed. You can write some execution commands or scripts into it according to your own needs, and you can load it when you start up.


(6) System login interface

After the system initialization is completed, init gives the user a login prompt (login) or a graphical login interface. After the user enters the user and password to log in, the entire startup process ends.





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325447343&siteId=291194637