[Linux] Startup Process Analysis

Source: Internet
Author: User

The first process started by Linux kernel is/sbin/init, and its configuration file is/etc/inittab. This article will analyze how Linux starts it according to this configuration file, the following is a typical example of this file:

## inittab       This file describes how the INIT process should set up#               the system in a certain run-level.## Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>#               Modified for RHS Linux by Marc Ewing and Donnie Barnes## Default runlevel. The runlevels used by RHS are:#   0 - halt (Do NOT set initdefault to this)#   1 - Single user mode#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)#   3 - Full multiuser mode#   4 - unused#   5 - X11#   6 - reboot (Do NOT set initdefault to this)# id:3:initdefault:# System initialization.si::sysinit:/etc/rc.d/rc.sysinitl0:0:wait:/etc/rc.d/rc 0l1:1:wait:/etc/rc.d/rc 1l2:2:wait:/etc/rc.d/rc 2l3:3:wait:/etc/rc.d/rc 3l4:4:wait:/etc/rc.d/rc 4l5:5:wait:/etc/rc.d/rc 5l6:6:wait:/etc/rc.d/rc 6# Trap CTRL-ALT-DELETEca::ctrlaltdel:/sbin/shutdown -t3 -r now# When our UPS tells us power has failed, assume we have a few minutes# of power left.  Schedule a shutdown for 2 minutes from now.# This does, of course, assume you have powerd installed and your# UPS connected and working correctly.  pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"# If power was restored before the shutdown kicked in, cancel it.pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"# Run gettys in standard runlevels1:2345:respawn:/sbin/mingetty tty12:2345:respawn:/sbin/mingetty tty2#3:2345:respawn:/sbin/mingetty tty3#4:2345:respawn:/sbin/mingetty tty4#5:2345:respawn:/sbin/mingetty tty5#6:2345:respawn:/sbin/mingetty tty6# Run xdm in runlevel 5x:5:respawn:/etc/X11/prefdm -nodaemon
The following is a one-to-one explanation.

1) set the run level

# Default runlevel. The runlevels used by RHS are:#   0 - halt (Do NOT set initdefault to this)#   1 - Single user mode#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)#   3 - Full multiuser mode#   4 - unused#   5 - X11#   6 - reboot (Do NOT set initdefault to this)# id:3:initdefault:

The preceding seven levels of run level are described in detail. Generally, 3 (multi-user mode) and 5 (image Interface) are commonly used ).

2) set the system environment (/etc/rd. d/rc. sysinit)

# System initialization.si::sysinit:/etc/rc.d/rc.sysinit
The rc. sysinit script is used to set the system environment. If you are interested, you can check the script content.

3) Start the System Service (/etc/rc. d/rc N)

l0:0:wait:/etc/rc.d/rc 0l1:1:wait:/etc/rc.d/rc 1l2:2:wait:/etc/rc.d/rc 2l3:3:wait:/etc/rc.d/rc 3l4:4:wait:/etc/rc.d/rc 4l5:5:wait:/etc/rc.d/rc 5l6:6:wait:/etc/rc.d/rc 6
Linux will start the corresponding system service according to the corresponding run level. In this example, we run level = 3, so we will start the service in the/etc/rc. d/rc3.d directory:

Find K ?? * For Files starting with S ?? * Start the file.

Among them ,?? It is a two-digit integer that represents the execution sequence of start or stop.

If you are careful, you will find that all the files under the/etc/rc. d/rc3.d directory are linked to the files under the/etc/init. d directory.

Do you need to process these link files starting with S and K? Of course no. The chkconfig command is used to process these link files.

4) User-Defined boot Startup Program (/etc/rc. d/local)

In/etc/rc. the d/rc d directory must have an S99local file pointing to/etc/rc. d/rc. local, which is used to configure the User-Defined boot Startup Program.

5) set the terminal

# Run gettys in standard runlevels1:2345:respawn:/sbin/mingetty tty12:2345:respawn:/sbin/mingetty tty2#3:2345:respawn:/sbin/mingetty tty3#4:2345:respawn:/sbin/mingetty tty4#5:2345:respawn:/sbin/mingetty tty5#6:2345:respawn:/sbin/mingetty tty6
In the preceding configuration table, when run level = 2345, two terminals (1, 2) are started, and terminals 3, 4, 5, and 6 are commented out, so they are not enabled.

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.