Linux starts full line speed

xiaoxiao2021-03-06  42

The Linux system is a very excellent operating system, but the startup time is one of the shortcomings of the system. So can you shorten the startup time of the Linux system through some settings? of course can. This article will show the reader how to shorten the startup time of the system without sacrificing the availability of Linux system. To achieve this goal, you need to understand all kinds of services between the system and their dependence, which in turn starts simultaneously under conditions allowed, thereby greatly saving system startup time.

Ready to work

If you want to use the methods described in this article to set the Linux system, you must first be familiar with the setup language of the Linux system. Setting up the system's startup process is a relatively dangerous behavior, which is easy to cause the system unable to start. Once this happens, it is best to restart the system after selecting a single user mode to restore the system and restart. Of course, the most important thing is to back up important data before setting.

Second, it is recommended that the user is best to modify the test before modifying the unit system. If the user has only one computer, then this is recommended to use the User Mode Linux System (UML) to test. UML is a kernel patch that allows kernel translation of the Linux system to binary so that users can run the Linux system as using ordinary software. Once an unexpected situation occurs, the loss is only UML, and the original system can be safe.

LUNUX system startup sequence and Runlevel

The launch of the Linux system includes multiple steps, which mainly introduces the system startup step after the kernel load. Users can view the system's current RunLvel by running the / sbin / runlevel command. Runlevel is the number of Linux systems to distinguish between the system advanced startup setting type. These numbers are very common, and the vast majority of them have a clear meaning. Take the Red Hat Linux system as an example, its Runlevel has the following few types (see Table 1):

How I initialize the system

INIT can learn how to change the system's Runlevel through an ASCII setting file. Typically, the setting file can guide the init to perform the /etc/rc.d/rc command to obtain the relevant information of RunLvel.

system service

The various system services required by the user are started by the RC instruction program. System potential services are complicated. Most Linux systems typically only provide features such as SSHD (SecureShell Service), Syslog (System Log Tools), and LPD (Print Services).

Users can find all services from the /etc/rc.d/ directory. If you open this directory, you will find that many services are just a shell, which just boots other programs to complete the work. Maybe someone will ask, how does the RC program know which programs do every runlevel? The answer is in the /etc/rc.d/ directory below with the init.d / directory, and they each correspond to their own Runlevel. Their names are RC * .D /, such as Runlevel 5 is /etc/rc.d/rc5.d/. Two symbolic links are included in each rc * .d / directory, which can be connected to the specified service program in the /etc/init.d/ directory.

Hands-on transformation

Service startup and termination

If the user decides to start the Linux system and enter graphics mode (Runlevel 5), the RC command program will be pair /etc/rc.d/rc5.d when the INIT boot RC instruction program runs and informs the Runlevel level. Viewed, then it will perform all links from this directory. The process of the RC instruction program executes the link can be divided into two parts. First it will execute all the names of "K" header, pass the "STOP" parameter to all services, and stop all of these links to point to all services. After these services are stopped, the RC instruction program will perform all the names of "S" head, and pass the "start" parameter to them, start the services you point to these links.

In addition, the RC instruction program can determine the execution order of the link and the digital small execution according to the two decimal numbers of the link name. An example will be given to help users have deeply understood. When the user starts the system into Runlevel 5, the first link to be executed is K05SASLATHD, since it is headed by "K", and the latter two decimal numbers are less than other links with "K". The first start link to be executed is S05KUDZU. Finally, the execution will be S99LOCAL. Below is a link to the program in the Runlevel 5 state.

# cd /etc/rc.d/rc5.d

# ls -al

Total 8

DRWXR-XR-X 2 root root 4096 JUL 15 09:29.

DRWXR-XR-X 10 root root 4096 jun 21 08:52..

LRWXRWXRWX 1 root root 19 Jan 1 2000 K05SASLATHD -> ../init.d/saslauthd

LRWXRWXRWX 1 root root 20 Feb 1 2003 k15postgreSQL -> ../init.d/postgreSQL

LRWXRWXRWX 1 root root 13 Jan 1 2000 K20NFS -> ../init.d/nfs

LRWXRWXRWX 1 root root 14 Jan 1 2000 K24IRDA -> ../init.d/irda

LRWXRWXRWX 1 root root 17 Jan 1 2000 k35winbind -> ../init.d/winbind

LRWXRWXRWX 1 root root 15 JAN 1 2000 K50SNMPD -> ../init.d/snmpd

......

LRWXRWXRWX 1 root root 18 Feb 8 11:15 k92iptables -> ../init.d/iptables

LRWXRWXRWX 1 root root 19 Feb 1 2003 K95FirstBoot -> ../init.d/firstboot

LRWXRWXRWX 1 root root 15 Jan 1 2000 S05kudzu -> ../init.d/kudzu

LRWXRWXRWX 1 root root 14 jun 21 08:55 s09isdn -> ../init.d/isdn

LRWXRWXRWX 1 root root 17 Jan 1 2000 S10Network -> ../init.d/network

LRWXRWXRWX 1 root root 16 Jan 1 2000 S12Syslog -> ../init.d/syslog

LRWXRWXRWX 1 root root 17 Jan 1 2000 S13portmap -> ../init.d/portmap

LRWXRWXRWX 1 root root 17 Jan 1 2000 S14NFSLOCK -> ../init.d/nfslock

LRWXRWXRWX 1 root root 18 Jan 1 2000 S17keyTable -> ../init.d/keytable

LRWXRWXRWX 1 root root 16 Jan 1 2000 S20random -> ../init.d/random

LRWXRWXRWX 1 root root 16 jun 21 08:52 S24pcmcia -> ../init.d/pcmcia

LRWXRWXRWX 1 root root 15 Jan 1 2000 S25Netfs -> ../init.d/netfs

LRWXRWXRWX 1 root root 14 Jan 1 2000 S26APMD -> ../init.d/apmdlrwxrwxrwx 1 root root 16 Jan 1 2000 S28AUTOFS -> ./init.d/autofs

LRWXRWXRWX 1 root root 14 Jan 1 2000 S55SSHD -> ../init.d/sshd

LRWXRWXRWX 1 root root 20 Jan 1 2000 S56RawdeVices -> ../init.d/RAWDEVICES

LRWXRWXRWX 1 root root 16 Jan 1 2000 S56XINETD -> ../init.d/xinetd

LRWXRWXRWX 1 root root 14 Feb 1 2003 S58NTPD -> ../init.d/ntpd

LRWXRWXRWX 1 root root 13 Jun 21 10:42 S60AFS -> ../init.d/afs

......

LRWXRWXRWX 1 root root 18 Jan 1 2000 S80sendmail -> ../init.d/sendmail

LRWXRWXRWX 1 root root 13 Jan 1 2000 S85GPM -> ../init.d/gpm

LRWXRWXRWX 1 root root 15 mar 22 08:24 s85httpd -> ../init.d/httpd

......

LRWXRWXRWX 1 root root 14 jul 15 09:29 s98wine -> ../init.d/wine

LRWXRWXRWX 1 root root 13 Feb 8 17:26 s99db2 -> ../init.d/db2

LRWXRWXRWX 1 root root 11 jun 21 08:52 S99LOCAL -> ../rc.local

If the user wants to temporarily terminate a service of a RunLvel, just delete the corresponding link. However, manual settings for links are a heavy and wrong work, but there is a very useful helper, its name is ChkConfig.

Differentiated services that are not terminated

To see which services are not terminated, the user needs to run the / sbin / chkconfig -list command. The display result after the command execution is shown below, and the user can clearly see eight items in each row. The chkconfig command can also be used to open or terminate a service.

AFS 0: OFF 1: OFF 2: OFF 3: on 4: Off 5: on 6: OFF

Anacron 0: OFF 1: OFF 2: on 3: on 4: on 5: On 6: Off

APMD 0: OFF 1: OFF 2: On 3: on 4: on 5: on 6: Off

ATD 0: OFF 1: Off 2: OFF 3: On 4: on 5: on 6: OFF

Autofs 0: Off 1: Off 2: OFF 3: On 4: on 5: on 6: OFF

Crond 0: OFF 1: Off 2: on 3: on 4: on 5: on 6: OFF

.........

The first column above the left is displayed is the name of the service, and the next second column shows the Runlevel and the current state in which it is. For example, NTPD (Network Time No Connection Bar Program) Services is set to be turned on only in Runlevel 3 and Runlevel 5, while SSHD services are turned on in Runlevel 2, 3, 4, and 5.

Perhaps the user will find that there is no service in Runlevel 0 and Runlevel 6 because Runlevel 0 and Runlevel 6 indicate that the system is terminated, of course, has not been served.

belong

As mentioned above, the system will run each Runlevel service at the time of startup. Maybe the user is easy to think of, if multiple services can be run at the same time, will inevitably save a lot of system startup time. But unfortunately, this method is not good, the reason is that there is a dependency between services. Traditional Linux systems do not give users a dependence relationship between services.

Now explain how to clarify the dependence between the service through a simple example. From NTPD services, a network basis can be concluded - NTPD service to rely on network services, this relationship can be represented by the following statement:

NTPD: NetWork

Users can determine that Netfs services must rely on network services, and AutoFS services must rely on network services, and now you can list a simple dependency table:

NTPD: NetWork

Netfs: network

Autofs: Network

Its meaning is that once the network service is turned on, NTPD, NETFS, and AutoFS services can be run at the same time. Assuming that the startup of each service takes 10 seconds, it takes 40 seconds to start the above four services in the traditional method, and the method mentioned above is enough for only 20 seconds. In fact, the startup time of the services is different, but the reason is the same.

For example, the LPD service (S60LPD) is run after the network service, but for a home system with an inkjet printer interface, it is not necessary to set the network connection and install the printer. In this case, a more reasonable condition should be the printer service first on the network service. In addition, the Crond service (S90crond) should also run after the network service. However, the Crond service does not have to run before the network service unless the user has a Cron file that can use the remote computer file.

It can be seen that some services have to rely on other services to run, and some services are completely independent, and they have nothing to do with other services. Therefore, these services that have no slave relationship with other services can be operated simultaneously. When these services are activated, the user can start with other services that are running premise, so that the ring loop is buckled, step by step until the entire system is started.

It seems that this seems to be a very complex process, but has prepared a very good tool for the user, this is the "make" program. "Make" program is generally used with compilation software. It can provide users with the full architecture required, and users only need to tell the dependence between the services between services.

in conclusion

In summary, the method of shortening the system startup is to first grave the dependence between the services, then arrange the reasonable startup order, and make the same service as much as possible at the same time, of course, don't forget to start the services that only starts. . Due to the different types of Linux systems, the effects of this approach are not the same, and everyone must concrete analysis in the process of use.

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

New Post(0)