Linux boot program insider - turn

xiaoxiao2021-03-06  66

Linux boot program insider copyright statement: 9CBS is this BLOG managed service provider. If this paper involves copyright issues, 9CBS does not assume relevant responsibilities, please contact the copyright owner directly with the article Author.

Since the operating system is getting more complex, the process of booting and shutting down power is increasingly intelligent. From a simple DOS system to the Windows NT system, people have experienced these changes - this is more than just the start of the core operating system starts boot and off, and it is also included to start or close a considerable number of service items at the same time. Similar to Windows NT, the Linux system launching process requires an open service project to be large.

Here, we have assumed that you have been familiar with the boot process of other operating systems, understand the self-inspection steps of the hardware, starting from the boot loader of the Linux operating system (usually lilo for personal computers), introduce Linux boot booting steps .

Loading the kernel

After LILO starts, if you have selected Linux as an operating system ready to boot, the first loaded thing is the kernel. Remember that there is no operating system in the computer memory at this time, and the PC (because of their natural design defects) has no way to access all of the machines on the machine. Therefore, the kernel must be fully loaded into the first megabyte available RAM. In order to achieve this, the kernel is compressed. The head of this file contains the necessary code, first set the CPU to enter the security mode (to release the memory limit), and then decompress the remainder of the kernel.

Core

After the kernel decompresses in memory, you can start running. The kernel at this time only knows the various functions itself in its own, that is, the kernel portion that is compiled into the module cannot be used. The most basic thing is that the kernel must have enough code to set your own virtual memory subsystem and root file system (usually the EXT2 file system). Once the kernel is running, the detection of the hardware will determine which device drivers will be initialized. From here, the kernel can hill the root file system (this process is similar to Windows recognition and accessing the C disk). After the kernel is hung, the root file system will start and run a program called InIT.

Note: Here we deliberately go to many details of Linux kernels, which are only interested in kernel developers. If you are curious, you can visit the "Kernel Hackers Guide" at http://www.redhat.com:8080 address.

Init process

The init process is the first start-up operation in the non-kernel process, so its process number PID is always 1. INIT reads its profile / etc / inittab, decides to start the run level (Runlevel). Fundamentally, the running level specifies the behavior of the entire system, each level (representation of 0 to 6, respectively) meets a specific purpose. If the INITDEFAULT level is defined, this value is selected directly, otherwise you need to enter a value of a representative run level by the user.

After entering the number of run levels, initiates an command script program based on the definition in the / etc / inittab file. The default run level depends on the selection of the login program in the installation phase: uses text-based or use X-Window-based login programs.

RC command scriptor

We already know that when the run level changes, it will be required to run which command script that needs to run by the / etc / inittab file. These command scripts are responsible for launching or stopping the run level specific services. Since there are many services that need to be managed, you need to use the RC command script. Among them, the most important one is /etc/rc.d/rc, which is responsible for calling the corresponding command script for each run level in the correct order. We can imagine that such a command scriptor is easy to control! In order to prevent such events from occurring, it is necessary to use a well-designed solution. For each run level, there is a corresponding sub-directory in the /etc/rc.d subdirectories. The naming method of these run-level subdirectors is RCX.D, where x is a number representing the run level. For example, all command scripts for running level 3 are saved in the /etc/rc.d/rc3.d subdirectory.

In the subdirectory of each run level, a symbolic link in the /etc/rc.d/init.d subdirectory is created, but these symbol links do not use the command script in / etc / rc. D / INIT.D The original name in the sub-directory. If the command scriptor is used to start a service, the name of its symbol link is headed by letter S; if the command scriptor is used to turn off a service, his symbolic link is headed at a letter K.

In many cases, the order of execution of these command scripts is important. If you don't configure the network interface first, there is no way to use the DNS service to resolve the host name! In order to arrange their execution order, it is tightly followed by a two digit after the letter S or K, and the value is small in front of the value. For example: /etc/rc.d/rc3.d/s50ine will execute before /etc/rc.d/rc3.d/s55named (S50inet configuration network settings, S55NAMED start DNS server).

Store in the /etc/rc.d/init.d subdirectory, the command script on the symbolic link is a real trunk, which is the operation of starting or stopping a variety of services. When the /etc/rc.d/rc runs through each particular run level subdirectory, it calls each command scripter according to the order of the numbers. It first runs the command scriptor headed by the letter K, and then runs the command script that headed by the letter S. For a command script, the command script that is headed by the letter K will pass the Stop parameter; similarly to the command script that heads with the letter S, the Start parameter is passed.

Write your own RC command script

In the days to maintain the LINUX system, it will definitely encounter the case where the system administrator is modified to the boot or shutdown command script. There are two ways to achieve the purpose of modification:

● If the modification is only played when booting, and if the change is not changed, you can consider simply edit the /etc/rc.d/rc.local script. This command scriptor is executed in the last step of the boot process.

● If the modification is more meticulous, or if the shutdown process is required to make it clearly stopped, you will need to add a command scriptor in the /etc/rc.d/init.d subdirector. This command script must accept Start and STOP parameters and complete the appropriate operation.

The first method, edit /etc/rc.d/rc.local script, of course, is relatively simple in both methods. If you want to add content in this command script, you only need to use the favorite editor program to open it, and then attach the intended command to the end of the file. This is really convenient for the modification of one or two lines.

If you really need to use a command script, you must select the second method. The process of writing an RC command script is not as difficult as imagination. Let's give an example below to see how it is implemented (by way of manner, you can use our example as a model, modify and add it according to your needs). Suppose you intend to call a special program every 60 minutes to pop up a message, remind yourself that you need to leave a break from the front of the keyboard for a while, the command script will include the following sections:

● About this command script program (this will not forget it after a year);

● Verify this command script prior to trying to run it;

● Accept Start and STOP parameters and perform the required action.

After the parameter given, we can write the script program for commands. This app is simple, you can write it yourself, I will not give it here.

After writing a new command script, then add the necessary symbolic links from the related run level subdirectory to control the startup or stop of this command script. In my impression, just launch it in running level 3 or running level 5 because I think there is only the two run levels to work everyday work. Finally, I hope this command script is turned off when entering the run level 6 (restart).

Activate or prohibit service items

Sometimes it will find that there is no need for a particular service when booting. This is even more like this if you are considering using Linux to replace Windows NT files and print servers.

We already know that the service can be changed to the symbolic link in a specific run level subdirectory, allowing the service to be not started, such as the first letter of its name is changed to K. Once you are proficient in command lines and symbolic links, you will find the fastest way to activate or prohibit service.

When learning this change method, you may think that the graphical operation interface ksysv is easier to master. Although it is designed to be used in the KDE environment, it is also very good in the Gnome environment installed in the default installation of the Red Hat Linux 7.2. If you want to start it, just simply open an XTERM window, and enter the ksysv command. A window will appear on the screen, which lists all parameters that can be modified, and it is also included when you need it.

WARNING: If you learn this article on a real system, you should use common sense. When trying to modify the startup script, you have to remember that the modifications you may cause your system to work properly and cannot be restored by restarting. Don't experiment with new settings on the normal operation system, you should back up all the files you prepare to modify. Most importantly, you have to prepare a guidance disk on your hand to prevent it.

转载请注明原文地址:https://www.9cbs.com/read-112216.html

New Post(0)