Linux INIT process details

Source: Internet
Author: User
  1. What is INIT:

Init is an indispensable program in Linux.

The INIT process is a user-level process started by the kernel.

After the kernel is started by itself (it has been loaded into the memory, started to run, and initialized to all the device drivers and data structures), it starts a user-level program init, complete the boot process. Therefore, init is always the first process (its process number is always 1 ).

In the past, the kernel used init to find it. The correct position (for Linux) is/sbin/init. If the kernel cannot find init, it will try to run/bin/sh. If the run fails, the system will also fail to start.

Ii. Operation Level

So what is the runtime level?

Simply put, the running level is the function level currently running in the operating system. This level ranges from 1 to 6 and has different functions.

Different runtime levels are defined as follows: (refer to/etc/inittab in Red Hat Linux)

#0-stop (never set initdefault to 0)

#1-single-user mode

#2-multiple users without NFS

#3-full multi-user mode (Standard Operation Level)

#4-useless

#5-X11 (XWindow)

#6-Restart (do not set initdefault to 6)

These levels are specified in the/etc/inittab file. This file is the main file found by the INIT program. The first service to run is the file stored in the/etc/rc. d directory. In most Linux releases, the startup script is located in/etc/rc. d/init. d. These scripts are connected to the/etc/rc. d/rcN. d directory by using LN commands. (Here N is the running level 0-6), and each directory of different levels is linked to part of the command in init. d.

3. Run-level Configuration

The running-level configuration is performed in the/etc/inittab line, as shown below:

12: 2: Wait:/etc/init. d/RC 2

The first field is an arbitrary tag;

The second field indicates that this row applies to the running level (2 in this example );

The third field indicates that at the running level, init should run the command in the fourth field once, and init should wait until the command ends. Run the/etc/init. d/RC command to start and end the input so that any command required to enter runtime Level 2.

In the fourth field, execute the command to set all "Miscellaneous" during the running level ". It starts a service that is no longer running, and terminates the service that should not run in the new running level. The specific commands used vary depending on the Linux version, and the running-level configuration is also different.

When init is started, it searches for a line of code in the/etc/inittab, which specifies the default running level:

ID: 2: initdefault:

You can require init to enter a non-default running level at startup, which is achieved by specifying a single or emergency command line parameter for the kernel. For example, you can use LILO to specify the kernel command line parameters. In this way, you can select the single-user mode (that is, run level 1 ).

When the system is running, the telinit command can change the running level. When the running level changes, init runs the corresponding command from/etc/inittab.

  4. Special configuration in/etc/inittab

The/etc/inittab has several special features that allow init to reactivate special events. These special features are marked with special keywords in the third field. For example:

1. powerwait

Enable init to shut down the system when the power supply is disconnected. The premise is that the software has u p S and monitors u p S and notifies init that the power supply has been cut off.

2. ctrlaltdel

Enable init to restart the system when you press the c t r l + a l t + d e l key combination on the console keyboard. Note: If the system is deployed in a public place, the system administrator can configure the c t r l + a l t + d e l combination key as another action, such as ignore.

3. sysinit

The command to be run when the system starts. For example, this command will clear/tmp.

The special keywords listed above are incomplete. For other keywords and their usage details, refer to your inittab manual page.

  5. Guided by single-user mode

An important operation level is the single-user mode (Operation Level 1). In this mode, only one system administrator uses a specific machine and runs as few system services as possible, including logon. Single-user mode is necessary for a few management tasks (such as running fsck on A/usr partition), because it needs to detach the partition, but this is impossible, unless all service systems have been killed.

A running system can enter the single-user mode. The specific method is to use init to request the running level 1. When the kernel is started, specify the single or emergency keyword in the kernel command line to enter Level 1. The kernel also specifies the command line for init. init knows from the keyword that it should not use the default running level (the input mode of the kernel command line is related to the mode in which you start the system ).

Sometimes, it is necessary to start in single-user mode. In this way, before you mount a partition, or at least before loading a scattered/usr partition, run fsck manually (any activity on a distributed file system can make it more dispersed, so run fsck as much as possible ).

If the automated fsck fails to be started, the startup script init automatically enters the single-user mode. This is done to prevent the system from using an inconsistent file system, which is not automatically repaired by f s c k. File System inconsistencies are rare, and usually lead to inconsistent hard disks or experimental kernel release, but it is best to prevent problems before they happen.

Due to security considerations, in single-user mode, a properly configured system requires the user to provide the root password before starting the shell script. Otherwise, it will simply enter a proper line of code for l I L O and Log On As R o t (of course, if/etc/passwd is not coherent due to file system problems, it is not suitable for the principle here. To deal with this situation, you 'd better prepare a boot disk at any time ).

Different running levels have different functions and should be set according to different situations.

For example, if the root password is lost, the machine can be started to enter the single-user status. Enter:

Init =/bin/sh RW enables the machine to enter runtime level 1, and the root file system is mounted as read/write. He will skip all system authentication, so that you can use the passwd program to change the root password, and then start to a new running level.

The running-level configuration is performed in the/etc/inittab line, as shown below:

12: 2: Wait:/etc/init. d/RC 2

The first field is an arbitrary tag;

The second field indicates that this row applies to the running level (2 in this example );

The third field indicates that at the running level, init should run the command in the fourth field once, and init should wait until the command ends. Run the/etc/init. d/RC command to start and end the input so that any command required to enter runtime Level 2.

In the fourth field, execute the command to set all "Miscellaneous" during the running level ". It starts a service that is no longer running, and terminates the service that should not run in the new running level. The specific commands used vary depending on the Linux version, and the running-level configuration is also different.

When init is started, it searches for a line of code in the/etc/inittab, which specifies the default running level:

ID: 2: initdefault:

You can require init to enter a non-default running level at startup, which is achieved by specifying a single or emergency command line parameter for the kernel. For example, you can use LILO to specify the kernel command line parameters. In this way, you can select the single-user mode (that is, run level 1 ).

When the system is running, the telinit command can change the running level. When the running level changes, init runs the corresponding command from/etc/inittab.

  4. Special configuration in/etc/inittab

The/etc/inittab has several special features that allow init to reactivate special events. These special features are marked with special keywords in the third field. For example:

1. powerwait

Enable init to shut down the system when the power supply is disconnected. The premise is that the software has u p S and monitors u p S and notifies init that the power supply has been cut off.

2. ctrlaltdel

Enable init to restart the system when you press the c t r l + a l t + d e l key combination on the console keyboard. Note: If the system is deployed in a public place, the system administrator can configure the c t r l + a l t + d e l combination key as another action, such as ignore.

3. sysinit

The command to be run when the system starts. For example, this command will clear/tmp.

The special keywords listed above are incomplete. For other keywords and their usage details, refer to your inittab manual page.

  5. Guided by single-user mode

An important operation level is the single-user mode (Operation Level 1). In this mode, only one system administrator uses a specific machine and runs as few system services as possible, including logon. Single-user mode is necessary for a few management tasks (such as running fsck on A/usr partition), because it needs to detach the partition, but this is impossible, unless all service systems have been killed.

A running system can enter the single-user mode. The specific method is to use init to request the running level 1. When the kernel is started, specify the single or emergency keyword in the kernel command line to enter Level 1. The kernel also specifies the command line for init. init knows from the keyword that it should not use the default running level (the input mode of the kernel command line is related to the mode in which you start the system ).

Sometimes, it is necessary to start in single-user mode. In this way, before you mount a partition, or at least before loading a scattered/usr partition, run fsck manually (any activity on a distributed file system can make it more dispersed, so run fsck as much as possible ).

If the automated fsck fails to be started, the startup script init automatically enters the single-user mode. This is done to prevent the system from using an inconsistent file system, which is not automatically repaired by f s c k. File System inconsistencies are rare, and usually lead to inconsistent hard disks or experimental kernel release, but it is best to prevent problems before they happen.

Due to security considerations, in single-user mode, a properly configured system requires the user to provide the root password before starting the shell script. Otherwise, it will simply enter a proper line of code for l I L O and Log On As R o t (of course, if/etc/passwd is not coherent due to file system problems, it is not suitable for the principle here. To deal with this situation, you 'd better prepare a boot disk at any time ).

Different running levels have different functions and should be set according to different situations.

For example, if the root password is lost, the machine can be started to enter the single-user status. Enter:

Init =/bin/sh RW enables the machine to enter runtime level 1, and the root file system is mounted as read/write. He will skip all system authentication, so that you can use the passwd program to change the root password, and then start to a new running level.

The running-level configuration is performed in the/etc/inittab line, as shown below:

12: 2: Wait:/etc/init. d/RC 2

The first field is an arbitrary tag;

The second field indicates that this row applies to the running level (2 in this example );

The third field indicates that at the running level, init should run the command in the fourth field once, and init should wait until the command ends. Run the/etc/init. d/RC command to start and end the input so that any command required to enter runtime Level 2.

In the fourth field, execute the command to set all "Miscellaneous" during the running level ". It starts a service that is no longer running, and terminates the service that should not run in the new running level. The specific commands used vary depending on the Linux version, and the running-level configuration is also different.

When init is started, it searches for a line of code in the/etc/inittab, which specifies the default running level:

ID: 2: initdefault:

You can require init to enter a non-default running level at startup, which is achieved by specifying a single or emergency command line parameter for the kernel. For example, you can use LILO to specify the kernel command line parameters. In this way, you can select the single-user mode (that is, run level 1 ).

When the system is running, the telinit command can change the running level. When the running level changes, init runs the corresponding command from/etc/inittab.

  4. Special configuration in/etc/inittab

The/etc/inittab has several special features that allow init to reactivate special events. These special features are marked with special keywords in the third field. For example:

1. powerwait

Enable init to shut down the system when the power supply is disconnected. The premise is that the software has u p S and monitors u p S and notifies init that the power supply has been cut off.

2. ctrlaltdel

Enable init to restart the system when you press the c t r l + a l t + d e l key combination on the console keyboard. Note: If the system is deployed in a public place, the system administrator can configure the c t r l + a l t + d e l combination key as another action, such as ignore.

3. sysinit

The command to be run when the system starts. For example, this command will clear/tmp.

The special keywords listed above are incomplete. For other keywords and their usage details, refer to your inittab manual page.

  5. Guided by single-user mode

An important operation level is the single-user mode (Operation Level 1). In this mode, only one system administrator uses a specific machine and runs as few system services as possible, including logon. Single-user mode is necessary for a few management tasks (such as running fsck on A/usr partition), because it needs to detach the partition, but this is impossible, unless all service systems have been killed.

A running system can enter the single-user mode. The specific method is to use init to request the running level 1. When the kernel is started, specify the single or emergency keyword in the kernel command line to enter Level 1. The kernel also specifies the command line for init. init knows from the keyword that it should not use the default running level (the input mode of the kernel command line is related to the mode in which you start the system ).

Sometimes, it is necessary to start in single-user mode. In this way, before you mount a partition, or at least before loading a scattered/usr partition, run fsck manually (any activity on a distributed file system can make it more dispersed, so run fsck as much as possible ).

If the automated fsck fails to be started, the startup script init automatically enters the single-user mode. This is done to prevent the system from using an inconsistent file system, which is not automatically repaired by f s c k. File System inconsistencies are rare, and usually lead to inconsistent hard disks or experimental kernel release, but it is best to prevent problems before they happen.

Due to security considerations, in single-user mode, a properly configured system requires the user to provide the root password before starting the shell script. Otherwise, it will simply enter a proper line of code for l I L O and Log On As R o t (of course, if/etc/passwd is not coherent due to file system problems, it is not suitable for the principle here. To deal with this situation, you 'd better prepare a boot disk at any time ).

Different running levels have different functions and should be set according to different situations.

For example, if the root password is lost, the machine can be started to enter the single-user status. Enter:

Init =/bin/sh RW enables the machine to enter runtime level 1, and the root file system is mounted as read/write. He will skip all system authentication, so that you can use the passwd program to change the root password, and then start to a new running level.

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.