Introduction to Linux Startup principle and Setup Startup script method

Source: Internet
Author: User

Transfer from my personal blog: http://www.xgezhang.com/linux_init_shell.html


Before always on the entire boot context of Linux do not understand, the problem to see very mysterious, yesterday a little research, in fact, is very simple.

When Linux starts, all startup scripts are placed under/etc/init.d/, and these scripts are mapped to each/ETC/RCX.D, which represents 0-6, corresponding to different system levels:

    • 0 on behalf of the shutdown (halt)
    • Level 1 is single-user mode
    • 2 levels are multi-user level, this is the default level
    • 3,4,5 undefined, can be provided to users to define other multi-user levels
    • 6 on behalf of restart (restart)
    • The single-user recovery model defined internally by the S-level system.

In other words, each RCX.D file will have some startup items, the number of files in each directory is less than the total number of/ETC/INIT.D directory. For different system environments, only the processes in the corresponding directory will be run. Users can view the native system RunLevel through the runlevel directive.

In each RCX.D directory, the files are soft-connected through scripts in the/ETC/INIT.D, and are named in the following ways:

[k| S][0-9,0-9][name]

K represents the Stop service, and S represents the start service, such as S20HOSTAPD S91APACH2

The two-digit number in the back is the run order and the small number takes precedence. such as the above startup items, it is obvious that the APACHE2 server needs to be opened before the previous network process, DNS process, and so on.

For different files, it is always executed in the order of K decimal->k large number->s decimal->s large number, and all files will be executed.

In addition, most Linux uses a mechanism called System V to start the runlevel, there will be a inittab file to change the default configuration, and before the process starts, the processes under the Sysinit directory are executed. And Ubuntu is another mechanism called startup, since the 9.10 version is not compatible with Inittab, and so on, so can not find these things.

After the introduction, how do we set up a boot script? There are two ways of doing this:

1. Edit the Rc.local file

This is a custom startup file for the user, starting at the end, which is executed after RCX.D is started, a bit similar to the startup item under Windows. We can edit the contents of our script directly into the rc.local file. The advantage of this approach is more convenient, the disadvantage is that if the script too much is not easy to manage

2. Add a script file to INIT.D and build a soft link

We can copy the written script to the/ETC/INIT.D directory. Then look at the operating level of this machine, for example, 2. Then add a soft link, for example:

Ln-s/etc/init.d/myshell/etc/rc2.d/s60mysqld

Or here is a UPDATE-RC.D directive that is specifically used to establish a soft link for a startup item, and to set the level and order of the instruction:

1. Set Startup items that specify the boot order, specified runlevel: update-rc.d <service> start <order> <runlevels>
2. Set at specified run level, stop in specified order: UPDATE-RC.D <service> stop <order> <runlevels>
3. Remove the specified startup items from all RunLevel: update-rc.d-f <script-name> Remove

For example: Update-rc.d Myshell start 90 1 2 3 4 5. Stop 52 0 6.
Start 90 1 2 3 4 5. : in 1, 2, 3, 4, 5 of these five runlevel, in order, from small to large, execution order is 90.
Stop 52 0 6. : Indicates that at 0, 6 of these two runlevel, in order, from small to large, 52nd stop this script to run.

Finally, if you want to delete a run level to run the service, you can put the corresponding RCX.D folder in the first letter of the soft connection name lowercase (This is the Debian article recommended practice, is also bum), you can also delete the soft connection ( This is the practice of sysv-rc-conf). How to do it depends on you.

Welcome reprint, please indicate the source.


Introduction to Linux Startup principle and Setup Startup script method

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.