For no matter what the system, but can not open the power so simple thing, a lot of things will happen in a few seconds or dozens of of a short time, understand this process will be a complete guide to solve the problem of any or improve the boot speed of the premise. Next, we will specialize in looking for Linux processes:
1. Load the BIOS hardware information and self-test, and according to obtain the first bootable device;
2. Read and run the boot Loader (such as grub, spfdisk, etc.) of the MBR in the first boot device;
3. The kernel will start to detect the hardware and load the driving procedure according to the Boot Loader kernel.
4. After the hardware driver succeeds, kernel will call the INIT program, and INIT will get run-level information;
5. Init executes the/etc/rc.d/rc.sysinit file to prepare the environment for software execution (e.g. network, time zone, etc.);
6. Init runs the run-level of each service start (script mode);
7. Init runs the/etc/rc.d/rc.local file;
8. Init runs the terminal emulator Mingetty to start the login program, and the user will be able to log in at the end;
Next, the above steps are described in detail:
1. Load the BIOS hardware information and self-test, and according to obtain the first bootable device;
Under the X86 platform, assuming that the system is running, you must first let the system load the Bois and load the CMOS information through the Bois program. Through the CMOS settings to obtain the host hardware configuration: such as CPU and interface device communication frequency, boot device search order, the size and type of the hard disk, the system time, the peripheral bus is started Plug and Play (PnP,
Plug-and-use devices), the I/O address of each interface device, and the IRQ fork that communicates with the CPU, and so on.
Here we need to understand the concepts of Bois and CMOS:
BOIS: Basic Input Output System. Its content is integrated on a ROM chip on the motherboard, the main storage system is the most important basic input and output programs, including: Terminal Services, System setup, power on the self-test program and system startup bootstrap program.
CMOS: Complementary Metal oxide semiconductor memory (complementary Metal Oxide Semiconductor). is the motherboard on a read-write RAM chip, mainly used to save the current system hardware configuration and operator to some of the parameters of the set (in layman's terms, it saves your computer's hardware configuration information and your computer's parameter settings and other information). CMOS RAM chips are powered by the system through a backup battery, so no CMOS information is lost, regardless of the shutdown state or the system power-down condition. (This is also the principle of discharge cracking boot password ^-^)
Bois and CMOS Contact:
CMOS is a medium for storing Bois set system parameters, and Bois is the means to change CMOS.
Then the above content continues to introduce, Bois loaded CMOS information, start the post, and then start to run the hardware initialization, and set up PNP, then define the power on the device sequence, then read the data from the specified boot device. At this point, the first step is complete.
2. Read and run the boot Loader (such as grub, spfdisk, etc.) of the MBR in the first boot device;
When the first step is complete, the system starts reading the MRB from the first boot device and runs boot Loader. Here, let's briefly explain the concept of MBR and boot Loader:
MRB: Main boot Record area (master boot recording). 0 Track 0 Cylinder 1 sectors on the entire hard drive. Only in a total of 512 bytes of the main boot sector, the MBR occupies only 446 bytes, the other 64 bytes to the DPT (disk Partition table hard disk partition table), the last two bytes "", AA "is the end of the partition flag. This overall constitutes the main boot sector of the hard disk.
Boot Loader:bois designated boot device, we will be able to read the system files on the device, but different operating systems, its file format is generally not the same, so we have to use a boot management program to handle the core file loading problem, this boot manager is the boot Loader. The program is installed in the first sector of the boot device, which is the MBR. In other words, the MBR is where the boot loader is stored.
With the introduction of the MBR and boot loader, we know that the boot loader is always stored in a certain location, so when the BIOS recognizes the disk, it is able to jump to the established location with the INT 13th interrupt to run the boot loader program into the core file of the operating system. At this point, the second step is complete.
3. Kernel will start to detect the hardware and load the driver kernel the Boot Loader is loaded into the program.
After the second step, Boot loader will be able to upload from the specified disk into the kernel, kernel decompression into memory, using the kernel function, start testing and drive hardware devices. At the same time, kernel also detects hardware once again, not necessarily using the hardware information that the BIOS detects. At this point, the kernel boot takes over the BIOS after the work. Here, we need to introduce the Linux kernel.
In Linux, kernel is stored in the/boot partition and is named Vmlinuz.
Then the above introduction, in this step, kernel will load the driver, but there will be a problem, these drivers are generally stored in the/lib/modules/folder,and kernel to identify the disk, you must load the disk driver, and the disk driver stored in the disk (/lib/modules), there is a dilemma, so that the system will never continue to boot, for such a problem, Linux predecessors, Come up with a fantastic way to solve the problem-----The virtual file system, here's a brief introduction to the virtual file system.
The virtual file system (Initial RAM Disk) typically uses a file name of INITRD, which is stored in the/boot/folder, which is characterized by the ability to load into memory via boot loader, which is then decompressed into memory and emulated into a root folder , and this emulation root folder in the memory of the file system can provide a running program, through the program to load the boot process required by the core modules, generally USB, RAID, LVM, SCSI and other file system and disk interface driver, after loading, kernel will again load/ Sbin/init to start the normal boot process. At this point, the third step is complete.
INITRD file contents such as the following:
Drwxrwxr-x Freeman Freeman 4096 October 14:50./DRWXRWXRWT root root 4096 October 18 14:47. /drwxr-xr-x 2 Freeman Freeman 4096 October 14:50 bin/drwxr-xr-x 3 Freeman Freeman 4096 October 14:50 conf/dr Wxr-xr-x 7 Freeman Freeman 4096 October 14:50 etc/-rwxr-xr-x 1 Freeman Freeman 7237 October 14:50 init*-rw- r--r-- 1 Freeman Freeman 51981312 October 14:46 initrddrwxr-xr-x 7 Freeman Freeman 4096 October 14:50 LIB/DRW Xr-xr-x 2 Freeman Freeman 4096 October 14:50 lib64/drwxr-xr-x 2 Freeman Freeman 4096 October 14:50 run/d Rwxr-xr-x 2 Freeman Freeman 4096 October 14:50 sbin/drwxr-xr-x 7 Freeman Freeman 4096 October 14:50 SCRI pts/
is not very like the folder structure of the Linux file System (^-^)
4. After the hardware driver is successful, kernel calls the INIT program to initialize the execution environment of the software.
After the third step, kernel started calling the INIT program, which is also the first program in the system, so its pid=1, so why call this program?
Here, we need to look at the role of this init program:
The main function of the NIT program is to prepare the environment for the software to run, including the host name of the system, network settings, language selection, file system format and other service startup. All of these actions are planned through the init configuration file, which is/etc/inittab, and another very important setting in Inittab, which is the default runlevel (boot run level). So,/etc/inittab file to instruct the INIT program to run detailed actions.
Below we look at the contents of the/etc/inittab file:
[email protected]:~$ Cat/etc/inittabid:3:initdefault: #设置默认执行等级. Init reads this line first to determine the execution level. SI::SYSINIT:/ETC/RC.D/INIT.D/RC sysinit# executes the/etc/rc.d/init.d/rc.sysinit script, which sets the hostname, hangs on the file system, Start the swap partition, and so on. 0:0:WAIT:/ETC/RC.D/INIT.D/RC 01:S1:WAIT:/ETC/RC.D/INIT.D/RC 12:2:WAIT:/ETC/RC.D/INIT.D/RC 23:3:wait:/etc/ RC.D/INIT.D/RC 34:4:wait:/etc/rc.d/init.d/rc 45:5:wait:/etc/rc.d/init.d/rc 56:6:WAIT:/ETC/RC.D/INIT.D/RC 6# corresponding to/etc Script in/rc.d/rc[0-6].d. #配置行的排列语法为: # id:runlevels:action:process [argument] #id为标志字段, typically 2 to 4 characters. #runlevel定义本行适用的执行等级. General example of the following #---------------------------------------------------------------------#执行等级 | Description #---------|------------------------------------------------------------# 0 | Halt, shut down the system. # 1 | Single user, when Grub is started, add the kernel plus the number of parameters to enter this execution level # 2 | No network multi-user mode. # 3 | There is a network multiuser mode. # 4 | There is a network multiuser mode. # 5 | X Mode # 6 | Reboot reboot System # S/S | Same execution level # A,b,c | Define your own hierarchy, usually without using. #---------------------------------------------------------------------#action定义採取的行动. #---------------------------------------------------------------------# Action | Description #---------------------------------------------------------------------# Respawn | Just to stop the process, the process starts again. # Wait | The process executes only once, and Init waits for it to end before executing other commands. # Once | The process executes only once. # Boot | During the system boot process, the process executes, and INIT ignores the execution level. # Bootwait | During system boot, process execution , Init waits for the process to end. # Off | No matter what action, the function is equal to the line with the # stare. # OnDemand | Only if init invokes any of the execution levels in A,b,c, the process executes. #initdefault | system set default execution level The. Process field is ignored. # Sysinit | Only the system boot, the process executes, takes precedence over boot and bootwait.# powerwait | When init receives the SIGPWR signal, the process starts executing, typically in the case of a power failure. # Powerfail | Same as powerwait, but Init does not wait for the process to complete. #powerokwait | Executes when a power failure is repaired. # Ctrialdel | When init receives the SIGNT signal (press Ctrl+alt+del), the process executes. # Kbrequest | When init receives the keyboard processing keyboardsignal signal, the process executes. #---------------------------------------------------------------- ------Ca:12345:ctrlaltdel:/sbin/shutdown-t1-a-R now# starts the system again when the Ctrl+alt+del is pressed in the 1-5 execution level. Su:s016:once:/sbin/sulogin #在S, Sulogin is executed under the 0,1,6 level. #一般而言, assuming that when booting with grub or LILO, it is assumed that kernel plus singleThe number of participants is directly entered into single-user mode without the need for password. This can be solved by adding this line of work. 1:2345:respawn:/sbin/agetty-i ' \033 (K ' tty1 96002:2345:respawn :/sbin/agetty-i ' \033 (k ' Tty2 96003:2345:respawn:/sbin/agetty-i ' \033 (k ' Tty3 96004:2345:respawn:/sbin/agetty-i ' \033 (k ' Tty4 96005:2345:respawn:/sbin/agetty-i ' \033 (k ' tty5 96006:2345:respawn:/sbin/agetty-i ' \033 (k ' Tty6 9600# Set the number of TTY consoles, generally for tty[1-6],x form systems generally performed in Tty7
By looking at the content in/etc/inittab, we know very well that INIT will prepare the environment (such as network, time zone, etc.) for the software execution by executing the/etc/rc.d/rc.sysinit script. At this point, the fourth step is complete.
5. Init runs the run-level of each service start (script mode);
After the fourth step is complete, init will start the corresponding service according to the run-level specified in the Inittab file. Details of what services, we can according to different run-level corresponding script file to view,
Each run-level the corresponding script file is described in the Inittab, as seen in the following:
0:0:WAIT:/ETC/RC.D/INIT.D/RC 01:S1:WAIT:/ETC/RC.D/INIT.D/RC 12:2:WAIT:/ETC/RC.D/INIT.D/RC 23:3:wait:/etc/rc.d/ INIT.D/RC 34:4:WAIT:/ETC/RC.D/INIT.D/RC 45:5:WAIT:/ETC/RC.D/INIT.D/RC 56:6:WAIT:/ETC/RC.D/INIT.D/RC 6
At this point, we take run-level as a 5 simple look at the corresponding script file content:
[Email protected]:/etc/rc5.d$ ls-llrwxrwxrwx 1 root root : September 18:00 s20kerneloops. /init.d/kerneloopslrwxrwxrwx 1 root root : September 18:00 s20rsync. /init.d/rsynclrwxrwxrwx 1 root root September 18:00 s20speech-dispatcher. /init.d/speech-dispatcherlrwxrwxrwx 1 root root : September 18:00 s50saned. /init.d/sanedlrwxrwxrwx 1 root root : September 18:00 S70dns-clean. /init.d/dns-cleanlrwxrwxrwx 1 root root : September 18:00 s70pppd-dns. /init.d/pppd-dnslrwxrwxrwx 1 root root : September 18:00 S99grub-common. /init.d/grub-commonlrwxrwxrwx 1 root root : September 18:00 s99ondemand. /init.d/ondemandlrwxrwxrwx 1 root root : September 18:00 s99rc.local. /init.d/rc.local
A brief description of the name of this file means: s is the start, k means kill, the following number indicates the order of execution, and then the next word is the execution of the program name.
At this point, the fifth step is complete.
6. Init runs the/etc/rc.d/rc.local file;
After the fifth step, the system is basically able to say that it has run, for this step, just run some user tasks before the system starts, so suppose the user wants to do some work before entering the system,
Then you can get your feet in the rc.local file.
7. Init runs the terminal emulator Mingetty to start the login program, and the user will be able to log in at the end;
After the sixth step is complete, the system needs to be started, and Linux will start the terminal or X Window. At this point, the entire system boot process is complete.
References:
Bird's private cuisine (third edition)
BIOS difference from CMOS
/etc/inittab file Analysis
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
A detailed explanation of the Linux boot process