Article title: Linux boot program (1 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Author: ink right hand
As the operating system is becoming more and more complex, the power-on and power-off processes become more and more intelligent. From a simple DOS system to a Windows NT system, people have already personally experienced these changes-not just starting and shutting down the core operating system, A considerable number of service projects must be started or closed at the same time. Similar to Windows NT, the number of service projects that need to be opened during Linux startup is also large.
Here, we assume that you are familiar with the boot process of other operating systems and understand the self-check boot steps of the hardware, just from the boot loader of the Linux operating system (usually LILO for personal computers) start with Linux boot guide.
Load the kernel
After LILO is started, if you choose Linux as the operating system for boot, the first thing to be loaded is the kernel. Remember that there is no operating system in the computer memory at this time, and PC (because of their natural design flaws) has no way to access all the memory on the machine. Therefore, the kernel must be fully loaded into the first MB of available RAM. For this purpose, the kernel is compressed. The header of this file contains the necessary code. first set the CPU to enter safe mode (to lift the memory limit), and then extract the remaining part of the kernel.
Run the kernel
After the kernel is decompressed in the memory, it can start to run. At this time, the kernel only knows its built-in functions, that is, the kernel part compiled as a module cannot be used. Basically, the kernel must have enough code to set its own virtual memory subsystem and root file system (usually ext2 file system ). Once the kernel starts running, the hardware detection determines which device drivers need to be initialized. From here on, the kernel can mount the root file system (this process is similar to Windows's process of identifying and accessing the C drive ). After the root file system is mounted to the kernel, a program called init will be started and run.
Note: Here we intentionally omitted many details about Linux kernel startup, which are of interest only to kernel developers. If you're curious, visit the "Kernel Hackers Guide" at http://www.redhat.com: 8080 ".
Init process
The init process is the first non-kernel process to be started, so its process id pid value is always 1. Init reads its configuration file/etc/inittab and determines the Runlevel to be started ). Basically, the running level specifies the behavior of the entire system. each level (represented by an integer ranging from 0 to 6) meets a specific purpose. If the initdefault level is defined, this value is directly selected. Otherwise, you must enter a value that represents the running level.
After entering a number indicating the running level, init executes a command script program according to the definition in the/etc/inittab file. The default running level depends on the selection of logon programs in the installation phase: whether to use text-based or X-Window-based logon programs.
Rc command script program
We already know that when the running level changes, the/etc/inittab file will define which command script program to run. These command script programs start or stop various services at the specific running level. Because the number of services to be managed is large, you need to use the rc command script program. Among them, the most important one is/etc/rc. d/rc, which is responsible for calling the corresponding command script program for each running level in the correct order. As we can imagine, such a command script program can easily become difficult to control! A well-designed plan is required to prevent such incidents.
For each running level, there is a corresponding sub-directory in the/etc/rc. d sub-directory. The sub-directories at the running level are named as rcX. d. X indicates the number at the running level. For example, all the command script programs of running level 3 are saved in the/etc/rc. d/rc3.d subdirectory.
In the sub-directories of each running level, the/etc/rc is created. d/init. d sub-directory command script program symbolic links, however, these symbolic links do not use the command script program in/etc/rc. d/init. the original name in the d sub-directory. If the command script program is used to start a service, its symbolic link name starts with the letter S. If the command script program is used to close a service, the name of the symbolic link starts with K.
In many cases, the execution sequence of these script programs is very important. If you do not configure the network interface first, you cannot use DNS to resolve the host name! In order to arrange their execution sequence, a two-digit character is followed by the letter S or K, and a small value is followed by a large value. For example,/etc/rc. d/rc3.d/S50inet will be executed before/etc/rc. d/rc3.d/S55named (S50inet configures network settings and S55named starts the DNS server ).
Stored in/etc/rc. d/init. the command script programs in the d sub-directory and on the symbolic link are real practitioners who have completed the operations to start or stop various services. When/etc/rc. d/rc runs through each specific sub-directory of the running level, it calls each command script program for execution in order of numbers. It first runs the command script program with the letter K headers, and then runs the command script program with the letter S headers. The Stop parameter is passed for the command script program that starts with letters K. Similarly, the Start parameter is passed for the command script program that starts with letters S.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service