1. Introduction to Linux startup process
(1) BIOS power-on self-test
After the computer starts, the firmware (BIOS) self-test is performed first, the so-called post (Power on Self Test), and then the master boot loader stored in the MBR (Master boot record, master boot Records) is put into memory.
(2) loading the master boot loader (MBR)
The Master boot loader finds the active partition through a partitioned table, and then reads the active partition's secondary boot loader from the device into memory and runs it.
(3) Load boot loader (GRUB)
The boot loader displays the GRUB (GRand Unified bootloader,grub) selection interface, which loads the kernel image of the appropriate operating system into memory based on the user's choice (if more than one operating system is installed on the machine).
(4) Linux kernel image
During the boot of the kernel, the necessary system modules are loaded to mount the root file system (/), and after completion the kernel starts the INIT process and hands the booted controller to the INIT process.
(5) Init process
The INIT process mounts all the file systems set up in the/etc/fstab and executes the corresponding script for system initialization according to the/etc/inittab file, so that the Linux system is started and can accept the user's login and operation.
2, the BIOS power-on self-test
x86 computer after boot is preferred to perform a BIOS power-on self-test, to detect the computer's hardware devices, and then in the order of CMOS settings to search the active and bootable device. The boot device can be a floppy disk, an optical drive, a USB device, a hard drive setup, or a device on a network.
The boot loader is saved in master boot record,mbr on the hard disk. The MBR is a 512-byte sector that is located in the first sector of the hard disk.
#dd If=/dev/had of=mbr.dmp bs=512 count=1 to save the contents of the MBR to the file mbr.dmp
1+0 records in reads 1 blocks of data
1+0 records out 1 pieces of data
Bytes (512B) copied,0.0147461 seconds,34.7kb/s copied 512 bytes, 34.7KB per second
#od-xa mbr.dmp Display the contents of the Mbr.dmp file
00000000 48eb d090 00BC fb7c 0750 1f50 BEFC 7c1b
The DD command reads the 512-byte content (that is, MBR) that begins with the hard disk/dev/had (the primary hard disk of the first IDE interface), writes it to the Mbr.dmp file, and then uses the OD command to display the contents of the file in ASCII and hexadecimal format.
The BIOS will load the MBR in the boot loader into memory, and then give control to the bootloader to continue the system startup process.
3. Boot loader program
(1) Boot loader startup
Linux boot is divided into two phases, and the first phase is the loading of the master boot loader that is saved in the MBR. The master boot loader in the MBR is a 512-byte image that contains the binary code of the machine and a small partition table. The main bootloader's task is to find and load the secondary boot loader saved on the hard disk partition, which finds the active partition through the partitioned table, and then reads the active partition's secondary boot loader from the device into memory and runs it into the second phase of the boot loader.
The secondary boot loader is also known as the kernel loader, and the task at this stage is to load the Linux kernel. Once the secondary boot loader is loaded into memory, the grub graphical interface is displayed. If the user does not make a selection, Grub automatically launches the default operating system set in the Grub.conf file within 5 seconds. After grub determines which operating system to start, it locates the/boot/directory where the corresponding kernel image resides. Kernel image files are typically named using the/boot/vmlinuz-< kernel version number >.
Grub then loads the kernel image into memory, because the kernel image is not an executable kernel, but a compressed kernel image, and grub needs to decompress the kernel and load it into memory and execute it. At this point, the boot loader grub completes its task by handing control over to the kernel image, which continues the next system boot work by the kernel.
(2) Grub Configuration
Grub configuration is done primarily by modifying the grub.conf file in the/boot/grub/directory.
Default option: To set the operating system that grub starts by default (if more than one operating system is configured in grub), the user does not make a selection after the time set by timeout is exceeded, and grub automatically starts the operating system configured in default. The count in grub starts with 0, and 0 represents the first.
◇timout option: Sets the default wait time in seconds.
◇splashimage option: Sets the background image of the grub interface.
◇hiddenmenu options: After setting this option, grub hides the operating system selection menu.
◇title option: Sets the name of the operating system in the Grub selection menu.
◇root (hdx,y): Sets the disk partition where the kernel resides. Grub's hard drive representation is different from Linux, where grub is counted by 0, (hd0,0) represents the first primary partition of the first disk, while Linux represents hda1, and (hd0,1) represents the first logical partition of the first hard disk, while Linux is Hda5. And so on
◇kernel option: Sets the name of the kernel file. Linux kernel files are generally stored in the/boot directory, the file naming convention is vmlinuz-< version number >.
4. Init process
The Linux process is the starting point for all processes in the Linux system, and after the kernel is booted, the INIT process is loaded and its process number is 1. After the init process starts, the operating system is initialized and the Autorun program is started at a specific runlevel (Runlevel).
(1) Introduction to the INIT process
Kernel image after the boot is completed, the init process is started, and the execution file for the Init process is/sbin/init, which is the initiator and controller of all the processes in the system, all of which are derived from it. If there is a problem with the INIT process, other processes in the system will be affected as well. Because it is the first running process in the system, the process id,pid of the INIT process is always 1.
(2) boot process of init process
When the init process gains control, it first executes the/etc/rc.d/rc.sysinit script, configures the environment variables according to the code in the script, configures the network, enables swap, checks and mounts the file system, and performs the necessary steps for other system initialization. Next, the INIT process executes the code in the/etc/inittab script. In this script, you define the operating level of the Linux system, and the boot steps corresponding to each level.
Linux system Boot Process