Linux startup process: init details

Source: Internet
Author: User
Linux startup process: init 1. what is INIT: init is one of the indispensable programs in Linux system operations. The init process is a user-level process started by the kernel. The kernel is started by itself (it has been loaded into the memory, started to run, and has initialized all...
Linux startup process: init 1. what is INIT: init is one of the indispensable programs in Linux system operations. 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 ). The www.2cto.com kernel looks for it in several places where init was used in the past. the correct location (for Linux systems) 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.
2. 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 (do not set initdefault to 0) #1-single-user mode #2-multi-user, no NFS #3-full multi-user mode (standard operation level) #4-not used #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 www.2cto.com 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)
3. run-level configuration the run-level configuration is performed in the/etc/inittab line, as shown below: l2: 2: wait:/etc/rc. d/rc 2 the first field is an arbitrarily specified label; the second field indicates the row is applicable to the running level (2 here); the third field indicates that when the running level is reached, 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 will search for a line of code in the/etc/inittab, which specifies the default running level: id: 2: initdefault: you can ask init at startup, enter the non-default running level, 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 configurations in/etc/inittab have 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 allows init to shut down the system when the power supply is cut off. 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. Www.2cto.com 2. ctrlaltdel allows 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 Ct r + A l t + D e l combination keys as other actions, such as ignore. 3. the command to be run when the sysinit system is started. 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. in single-user mode, an important operation level is single-user mode (Operation Level 1). In this mode, only one system administrator uses a specific machine, and run 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 fsck. 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 an appropriate line of code for L www.2cto.com 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 at the start lilo prompt to enable the machine to run Level 1 and mount the root file system to 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. Author bough22
Related Article

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.