Detailed explanation of the Linux startup process

Reprinted in: http://blog.chinaunix.net/uid-26495963-id-3066282.html




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 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 layer init to set the run level according to the inittab file
After the kernel is loaded, the first program to run is /sbin/init , which will read the /etc/inittab file, and according to 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: Multi-user mode with network support and X-Window support
6: Reboot the system, that is, restart
the knowledge about the /etc/inittab file, there are actually many more

Start the sixth step - the init process executes rc.sysinit
After the run level is set, the first user layer file executed by the Linux system is the /etc/rc.d/rc.sysinit script program, which does a lot of work , including setting PATH, setting network configuration (/etc/sysconfig/network), starting swap partition, setting /proc, etc. 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 see the seventh step

of starting a few days - starting the kernel module
is based on the /etc/modules.conf file or /etc/modules.d directory to load kernel modules.

Start the eighth step - Execute the 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 at a glance what this command does:
# 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 where Linux leaves the user to personalize after everything has been initialized . 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. :)


Guess you like

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