Linux Boot from boot

Source: Internet
Author: User
Tags numeric value

First,rc.local

The rc.local script is a script that will be executed automatically after Linux is powered on, and we can add command-line directives to the script. The script is located under the/etc/path and requires root privileges to be modified.

#!/bin/*after*inif you don'tdo/var /Lock/subsys/local

Generally speaking of their own boot execution script placed in the/etc/init.d/下,然后可在此文件中添加:

cd/etc/init.d/sudo update

Here 90 indicates a priority, and the higher the performance, the later the execution.

To execute scripts at logon or logoff, you need to use ~.bash_profile and ~.bash_logout files respectively. In most cases, the latter needs to be created manually. At the bottom of each file, add the calling script code, as shown in the previous example, to implement this functionality.

Third, the INIT process

The init process is first run in a non-kernel process, so its process number PID value is always 1. Init reads its configuration file/etc/inittab, which determines the RunLevel (Runlevel) that needs to be started. Fundamentally, the runlevel specifies the behavior of the system as a whole, with each level (represented by an integer from 0 to 6) that satisfies a specific purpose. If the initdefault level is defined, the value is directly selected, otherwise the user is required to enter a numeric value that represents the run level. After entering a number representing the run level, Init executes a command script based on the definition in the/etc/inittab file. The default runlevel depends on the selection of the logon program during the installation phase: whether to use text-based or X-window-based login programs.

RC Command Script we already know that when the runlevel changes, it is up to the/etc/inittab file to define which command script to run. These command scripts are responsible for starting or stopping various services that are specific to that runlevel. Because of the large number of services that need to be managed, you need to use the RC command script. One of the most important is/ETC/RC.D/RC, which is responsible for invoking the appropriate command script for each runlevel in the correct order. We can imagine that such a command script could easily become unmanageable! In order to prevent such events from happening, a well-designed scheme is needed.

For each runlevel, there is a subordinate directory in the/ETC/RC.D subdirectory. The naming method for the subordinate subdirectories of these runlevel is RCX.D, where x is the number representing the run level. For example, all command scripts running level 3 are stored in the/ETC/RC.D/RC3.D subdirectory. In sub-directories at each runlevel, there are symbolic links to the command scripts in the/ETC/RC.D/INIT.D subdirectory, but these symbolic links do not use the original name of the command script in the/ETC/RC.D/INIT.D subdirectory. If the command script is used to start a service, its symbolic link name begins with the letter S; if the command script is used to close a service, its symbolic link will begin with the letter K. For each runlevel, there is a subordinate directory in the/ETC/RC.D subdirectory. The naming method for the subordinate subdirectories of these runlevel is RCX.D, where x is the number representing the run level. For example, all command scripts running level 3 are stored in the/ETC/RC.D/RC3.D subdirectory. In sub-directories at each runlevel, there are symbolic links to the command scripts in the/ETC/RC.D/INIT.D subdirectory, but these symbolic links do not use the original name of the command script in the/ETC/RC.D/INIT.D subdirectory. If the command script is used to start a service, its symbolic link name begins with the letter S; if the command script is used to close a service, its symbolic link will begin with the letter K.

In many cases, the order in which these command scripts are executed is important. If you do not 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 sequence, the letter S or K is followed by a two-digit number, the value is small in front of the large number of execution. For example:/etc/rc.d/rc3.d/s50inet will be executed before/etc/rc.d/rc3.d/s55named (s50inet configure network settings, 55named to start the DNS server). The command scripts stored in the/ETC/RC.D/INIT.D subdirectory, which are symbolic links, are the real doers, and they complete the process of starting or stopping various services. When/ETC/RC.D/RC runs through each specific run-level subdirectory, it invokes each command script execution sequentially, in order of the number. It runs the command script that starts with the letter K, and then runs the command script that begins with the letter S. For a command script that starts with the letter K, the stop parameter is passed, and the start parameter is passed similarly to a command script that begins with the letter S. Writing your own RC command scripts in the days of maintaining a Linux system, you will certainly encounter situations in which the system administrator needs to modify the boot or shutdown command scripts.

There are two ways to achieve the purpose of the modification:
If the changes are only useful when booting the boot, and the changes are not significant, consider simply editing the/etc/rc.d/rc.local script. This command script is executed at the last step of the boot process.
If you make a fine-grained modification, or require the shutdown process to be explicitly stopped, you need to add a command script to the/ETC/RC.D/INIT.D subdirectory. This command script must be able to accept the start and stop parameters and complete the appropriate operation.
The first method of editing the/etc/rc.d/rc.local script is, of course, the simpler of the two methods. If you want to add content to this command script, just open it with your favorite editor program and append the command you intend to execute to the end of the file. This is really handy for the one or two-line revision. After you have written a new command script, you can control the start or stop of the command script by adding the necessary symbolic links from the relevant run-level subdirectories.

The startup of the system service is implemented through the script file in "/etc/rc.d/init.d".

Reference: http://www.cnblogs.com/gzggyy/archive/2012/08/07/2626574.html

Linux Boot from boot

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.