Linux boot process (boot sequence)

First Step - Loading BIOS When you turn
on the computer, the computer will first load the BIOS information. The BIOS information is so important that the computer must find it at the very beginning. This is because the BIOS contains CPU-related information, device startup sequence information, hard disk information, memory information, clock information, PnP features, and so on. After this, the computer has a spectrum in its heart and knows which hardware device it should read.

Start the second step - read MBR
As we all know, the first sector of the is called MBR , that is, Master Boot Record, that is, the master boot record, its size is 512 bytes, don't look at the place. , but it stores pre-boot information and partition table information.
After the system finds the MBR of the hard disk specified by the BIOS, it will copy it to the physical memory where the address 0×7c00 is located. In fact, the content copied to the physical memory is Boot Loader, and specifically to your computer, it is lilo or grub.

Start the third step - Boot Loader
Boot Loader is a small program that runs before the operating system kernel runs. Through this small program, we can initialize the hardware device and establish the mapping map of the memory space , so as to bring the software and hardware environment of the system to a suitable state , so as to prepare everything for the final call to the operating system kernel .
There are several kinds of Boot Loaders, among which Grub, Lilo and spfdisk are common Loaders.
Let's take Grub as an example to explain, after all, not many people use lilo and spfdisk.
The system reads the grub configuration information (usually menu.lst or grub.lst) in the memory, and starts different operating systems according to this configuration information.

Start the fourth step - load the kernel
According to the path of the kernel image set by grub, the system reads the memory image and decompresses it . At this point, the screen will generally output the prompt "Uncompressing Linux". When decompressing the kernel is complete, the screen outputs "OK, booting the kernel".
The system places the decompressed kernel in the memory , and calls the start_kernel() function to start a series of initialization functions and initialize various devices to complete the establishment of the Linux kernel environment. So far, the Linux kernel has been established, and Linux-based programs should be able to run normally.

Start the fifth step - user-level init sets the run level according to the inittab file.
After the kernel is loaded, the first program to run is /sbin/init , which will read /etc/inittab file and base it on this file. to initialize.
In fact, the main function of the /etc/inittab file is to set the operating level of Linux , its setting form is ":id:5:initdefault:", which indicates that Linux needs to run on level 5. The Linux run levels are set as follows:
0: Shutdown
1: Single-user mode
2: Multi-user mode without network support
3: Multi-user mode with network support
4: Reserved, unused
5: Network support and X-Window support Multi-user mode
6: rebooting the system, that is, restarting. There is actually a lot to learn
about the /etc/inittab file.

Start the sixth step -- the init process executes rc.sysinit
. After the run level is set, the Linux system executes the first step. A user layer file is the /etc/rc.d/rc.sysinit script program, which does a lot of work, including setting the PATH, setting the network configuration (/etc/sysconfig/network), starting the swap partition, setting /proc and so on. If you are interested, you can go to /etc/rc.d to check the rc.sysinit file, the script inside is enough for you to watch for a few days.

Start the seventh step - start the kernel module.
Specifically, it is based on the /etc/modules.conf file or /etc/modules.d directory to load kernel modules.

Start the eighth step--Execute script programs of different operating levels
According to the different operating levels, the system will run the corresponding script programs in rc0.d to rc6.d to complete the corresponding initialization work and start the corresponding services.

Start the ninth step - execute /etc/rc.d/rc.local
If you open this file, there is a sentence in it. After reading it, you will understand the function of this command at a glance:
# This script will be executed * after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
rc.local is what Linux leaves to the user after all the initialization work Personalized place . You can put things you want to set up and start up here.

Start the tenth step - execute the /bin/login program to enter the login state
At this point, the system has entered the time to wait for the user to enter the username and password, and you can log in to the system with your own account. :)
===
The long startup process is over, and everything is quiet...
In fact, behind this, there are more complex underlying function calls, waiting for you to study... This article is even a good idea :)
This article refers to the following articles, refined Assembled:
http://bbs.chinaunix.net/thread-835918-1-1.html
http://hi.baidu.com/fembed/blog/item/b9f0881f51145866f624e4be.html
http://baike.baidu.com/view/9485.htm

Guess you like

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