Detailed explanation of Linux startup process (inittab, rc.sysinit, rcX.d, rc.local)

Start the first step - load the BIOS

When you turn on the computer, the computer loads the BIOS information first, and 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 0th track on the hard disk is called MBR, that is, Master Boot Record, that is, the master boot record. Its size is 512 bytes. Although it is not big, it stores pre-boot information. , 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 0x7c00 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 / Grup

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 in the memory (usually menu.lst or grub.lst), 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 sets the run level according to the inittab file

After the kernel is loaded, the first program to run is /sbin/init, which reads the /etc/inittab file and performs initialization work according to this file.

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 runlevels 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, i.e. reboot

There is actually a lot more to learn about the /etc/inittab file.

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 the PATH, setting the network configuration (/ etc/sysconfig/network), start swap partition, set /proc, etc. If you are interested, you can check the rc.sysinit file in /etc/rc.d, the script in it is enough for you to read for a few days.

Start the seventh step - start the kernel module

Specifically, the kernel modules are loaded according to the /etc/modules.conf file or the files in the /etc/modules.d directory.

Start the eighth step - execute scripts of different run levels (/etc/rc.d/rc $RUNLEVEL # $RUNLEVEL is the default running mode)

Depending on the operating level, 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

你如果打开了此文件,里面有一句话,读过之后,你就会对此命令的作用一目了然:

# 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就是在一切初始化工作后,Linux留给用户进行个性化的地方。你可以把你想设置和启动的东西放到这里。

启动第十步--执行/bin/login程序,进入登录状态

此时,系统已经进入到了等待用户输入username和password的时候了,你已经可以用自己的帐号登入系统了。


--------------------------------------------

转载处:https://www.cnblogs.com/sysk/p/4778976.html

Guess you like

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