Linux inittab file details

Source: Internet
Author: User
Tags linux shell commands sigint signal syslog

 

The init process number is 1 (ps-aux | less). From this point, we can see that the init process is the starting point of all processes in the system. After Linux completes the kernel boot, start to run the init program.

The init program needs to read the configuration file/etc/inittab. Inittab is an unexecutable text file consisting of several lines of commands.

Understand Runlevel:

Runlevel is used to indicate the state of the system after the init process ends. There is no fixed information in the system hardware to indicate runlevel. It is purely a software structure. Init and inittab are the only reasons why runlevel affects the system status. In the preceding example, the inittab file annotator

Used to describe runlevel:

Runlevel 0 enables init to shut down all processes and terminate the system.

Runlevel 1 is used to switch the system to single-user mode. in single-user mode, only system administrators can access the system. In this mode, files that cannot be changed when a user is logged on can be processed, you can change runlevel number 1 to S.

Runlevel 2 allows the system to access multiple users, but does not support file sharing. This mode is rarely used.

Runlevel 3 is the most common running mode. It is mainly used to provide real multi-user mode and is also the default mode for most servers.

Runlevel 4 is generally not used by the system. You can design your own system status and apply it to runlevel 4. Although it is rarely used, you can use this system to implement some specific login requests.

Runlevel 5 is a dedicated X Window terminal that initializes the system. This is not a good choice for a powerful Linux system. However, if you need this, you can enable this solution at runlevel.

Runlevel 6 is used to shut down all running processes and restart the system.

Inittab file content:

### Indicates that the current default running level is 5 (initdefault );

Id: 5: initdefault:/* enter the GUI after startup. If it is set to 3, enter the character Terminal interface */

### Automatically execute the/etc/rc. d/rc. sysinit script (sysinit) at startup)

/*

All rows starting with # In the inittab file are comment rows. The comment line helps you understand the inittab file. The values in the inittab file are in the following format:

Label is 1 ~ A four-character tag that identifies the input value. Some systems only support 2 Characters of tags. For this reason, most people limit the number of tag characters to less than 2. The tag can be a string composed of any characters, but in fact, some specific labels are commonly used. The labels used in Red Hat Linux are:

Code:

Id is used to define the default init running level

Si is the process of system initialization.

In ln, n ranges from 1 ~ 6. indicates the runlevel level that can be used by the process.

Ud is the upgrading process

Ca indicates the process that runs when Ctrl + Alt + Del is pressed.

Pf indicates the process that runs when the UPS instance is powered off.

Pr is the process to run when the UPS sends a signal of power recovery before the system is actually shut down.

X is the process to run when the system is transferred to the X terminal.

The runlevel field specifies the runlevel level. You can specify multiple runlevel levels, or do not specify a specific value for the runlevel field.

The action field defines the status in which the process should run:

Code:

Boot runs when the system starts, ignoring runlevel

Bootwait runs when the system starts and init waits for the process to complete. Ignore runlevel

Ctrlaltdel run when Ctrl + Alt + Del are pressed simultaneously, and the SIGINT signal is sent to init. Ignore runlevel

Initdefault: do not execute this process. It is used to set the default runlevel.

Kbrequest runs when init receives a signal from the keyboard. The keyboard combination is required to comply with KeyBoardSigral (see/usr/share/doc/kbd-* Documents on the keyboard combination)

Off indicates that the process is not running.

Once every runlevel runs once

Ondemand runs when the system specifies A specific running level A, B, and C.

Powerfail runs when init receives the SIGPWR Signal

Powerokwait runs when the SIGPWD signal is received and the power status in the/etc/file contains OK

Powerwait runs when it receives the SIGPWD signal and init waits for the process to end

Respawn restarts the process at any time

Sysinit runs before running the boot or bootwait Process

Wait running process waiting for Input Running Mode

 

The process field contains the process executed by init. The process adopts the same format as running the process on the command line. Therefore, the process field starts with the name of the process, it is followed by the parameter to be passed to the process during running. For example,/sbin/shutdown-t3-r now, the process is executed when Ctrl + Alt + Del is pressed. You can also enter it in the command line to restart the system.

Special purpose records

Take a closer look at the example file and learn how to apply the syntax format of inittab. Most of the content of this file can be ignored, because more than half of the content is annotated, and the remaining content is mainly used to implement some special functions:

The value of id indicates that the default runlevel is 3.

The ud value can wake up the/sbin/update process. To ensure the integrity of the disk, the whole I/O buffer is cleared before I/O operations are performed on the disk.

The pf, pr, and ca values are called only for specific interruptions.

If the system is a dedicated X terminal, only the input value of x is required.

The getty process provides services for virtual terminal devices. For example:

3: 2345: respawn:/sbin/mingetty tty3

The value of the tag field is 3, which is the digital Suffix of the device tty3. tty3 is associated with the corresponding process. The runlevel that the getty process can start is 2, 3, 4, and 5, when the process is terminated, init immediately restarts it. The name of the startup process is/sbin/mingetty, which is the smallest version of getty supported by the virtual terminal and provides the process for tty3 to start the virtual device.

Si: sysinit:/etc/rc. d/rc. sysinit

This value tells the init program to run/etc/rc. d/rc. the sysinit script file is used to initialize the system. The script file is similar to all started scripts. It is only an executable file containing Linux shell commands, note that the entered string must include the full path of the script. Different Versions of Linux store this script in different locations, but you don't have to remember these locations. You only need to view the/etc/inittab file, this file contains the exact location of the startup script file. */

# System initialization.

Si: sysinit:/etc/rc. d/rc. sysinit

L0: 0: wait:/etc/rc. d/rc 0

L1: 1: wait:/etc/rc. d/rc 1

L2: 2: wait:/etc/rc. d/rc 2

L3: 3: wait:/etc/rc. d/rc 3

L4: 4: wait:/etc/rc. d/rc 4

### When the running level is 5, run the/etc/rc. d/rc Script with 5 as the parameter, and init will wait for it to return (wait)

L5: 5: wait:/etc/rc. d/rc 5

L6: 6: wait:/etc/rc. d/rc 6

### Allow restarting the system by CTRL-ALT-DELETE during startup

# Trap CTRL-ALT-DELETE

Ca: 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 the/sbin/mingetty program with ttyX as the parameter at Level 2, 3, 4, and 5, and enable the ttyX terminal for user login,

### If the process exits, run the mingetty Program (respawn) again)

# Run gettys in standard runlevels

1: 2345: respawn:/sbin/mingetty tty1

2: 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 the xdm program at level 5, provide the xdm graphical login interface, and re-Execute (respawn) upon exit)

# Run xdm in runlevel 5

X: 5: respawn:/etc/X11/preofdm-nodaemon

The preceding inittab file is used as an example to describe the inittab format. The row starting with # Is a comment row. Each row has the following format except the comment row:

Id: runlevel: action: process

The detailed explanations of the above items are as follows:

1. id

Id refers to the entry identifier, which is a string. For other login program items such as getty or mingetty, the id must be the same as the tty number; otherwise, the getty program will not work properly.

2. runlevel

Runlevel is the identifier of the running level of init. It is generally 0-6 and S or s. The running levels 0, 1, and 6 are retained by the system. Among them, 0 is used as the shutdown action, 1 is used as the restart to the single-user mode, and 6 is used as the restart; S and s share the same meaning, indicating the single-user mode, the inittab file is not required, so it does not appear in inittab. In fact, when you enter single-user mode, init runs/sbin/sulogin directly on the console (/dev/console. In general system implementation, 2, 3, 4, and 5 are used. In the Redhat system, 2 indicates that the multi-user mode is not supported by NFS, 3 indicates full multi-user mode (also the most common level), 4 is reserved for user customization, and 5 indicates XDM graphical login mode. 7-9 levels are also available, which are not defined by traditional Unix systems. Runlevel can be multiple parallel values to match multiple running levels. For most actions, runlevel is executed only when it matches the current running level.

3. action

Action describes the running mode of the subsequent process. Optional values of action include initdefault, sysinit, boot, and bootwait:

Initdefault is a special action value used to identify the default startup level. When init is activated by the core, it reads the initdefault item in inittab and obtains the runlevel, as the current running level. If there is no inittab file or there is no initdefault item, init will request to enter runlevel on the console.

Actions such as sysinit, boot, and bootwait will run unconditionally when the system is started, ignoring runlevel.

Other actions (excluding initdefault) are related to a certain runlevel. The definitions of each action are described in detail in the man manual of inittab.

4. process

Process is the specific execution program. The program can be followed by parameters.

Part 3: system initialization

There is such a line in the init configuration file:

Si: sysinit:/etc/rc. d/rc. sysinit

It calls and executes/etc/rc. d/rc. sysinit, while rc. sysinit is a bash shell script, which mainly

There is such a line in the init configuration file:

Si: sysinit:/etc/rc. d/rc. sysinit

It calls/etc/rc. d/rc. sysinit, while rc. sysinit is a bash shell script mainly used to complete system initialization, rc. sysinit is an important script to run at every running level. It mainly includes activating swap partitions, checking disks, loading hardware modules, and other tasks that require priority.

Rc. sysinit has more than 850 lines, but each single function is relatively simple and has annotations. It is recommended that interested users read the file on their own machines, to learn more about system initialization. This file is long, so it is not listed in this article, and will not be described in detail.

After the rc. sysinit program is executed, the system returns init to continue the next step.

Part 4: Start the running daemon

After rc. sysinit is executed, init will be returned to continue other actions. Normally, the/etc/rc. d/rc program will be executed next. Taking running level 5 as an example, init will execute the following line in the configuration file inittab:

L5: 5: wait:/etc/rc. d/rc 5

This line indicates running/etc/rc with 5 as the parameter. d/rc,/etc/rc. d/rc is a Shell script that accepts 5 as the parameter and executes/etc/rc. d/rc5.d/All rc startup scripts in the directory,/etc/rc. in the d/rc5.d/directory, these startup scripts are actually some link files, rather than the real rc startup scripts. The real rc startup scripts are actually stored in/etc/rc. d/init. d/directory. These rc boot scripts have similar usage. They generally accept parameters such as start, stop, restart, and status.

The rc STARTUP script in/etc/rc. d/rc5.d/is usually a link file starting with K or S. For a STARTUP script starting with S, it will run with the start parameter. If the corresponding script is found to have a K-header link, and it is already in the running state (marked by a file under/var/lock/subsys ), stop the started daemon with the stop parameter and run the daemon again. This ensures that all related daemon will be restarted when init changes the running level.

You can use chkconfig or "System Services" in setup to set which daemon will run at each running level. Common daemon processes include:

Amd: automatically installs the NFS daemon.

Apmd: Advanced Power Management daemon

Arpwatch: records logs and constructs an ethernet address and IP address pair database that is visible on the LAN interface.

Autofs: automatically installs the management process automount, which is related to NFS and relies on NIS.

Crond: the daemon of scheduled tasks in Linux

Named: DNS Server

Netfs: Install NFS, Samba, and NetWare Network File Systems

Network: Activate the script program with configured network interfaces

Nfs: Enable the NFS service

Portmap: RPC portmap manager, which manages RPC-based connections

Sendmail: sendmail

Smb: Samba file sharing/printing service

Syslog: a script that enables syslog and klogd system logs to wait for processes during system boot.

Xfs: X Window server, which provides a font set for local and remote X Servers

Xinetd: supports core daemon processes of multiple network services and manages services such as wuftp, sshd, and telnet.

These daemon processes are also started, the rc program is executed, and the init is returned to continue the next step.

Part 5: Establish a terminal

After the rc is executed, init is returned. At this time, the basic system environment has been set and various daemon processes have been started. Init will then open six terminals so that users can log on to the system. You can switch between the six terminals by pressing Alt + Fn (n corresponds to 1-6. The following six lines in the inittab define six terminals:

1: 2345: respawn:/sbin/mingetty tty1

2: 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

From the above, we can see that the mingetty program will be run in the respawn mode in the 2, 3, 4, and 5 running levels. The mingetty program can open the terminal and set the mode. At the same time, it will display a text logon interface, which is a logon interface we often see. In this logon interface, a user is prompted to enter the user name, the user input will be passed as a parameter to the login program to verify the user's identity.

Part 6: log on to the system and start the system

For graphical users with a running level of 5, their logon is through a graphical logon interface. After successful logon, you can directly go to the KDE, Gnome, and other Window managers. This article focuses on text-based Logon:

When we see the mingetty logon interface, we can enter the user name and password to log on to the system.

In Linux, the Account Verification Program is login. login receives the username sent from mingetty as the username parameter. Login analyzes the user name. If the user name is not root and the/etc/nologin file exists, login outputs the content of the nologin file and then exits. This is usually used to prevent non-root User Logon during system maintenance. Only terminals registered in/etc/securetty allow the root user to log on. If this file does not exist, the root user can log on to any terminal. The/etc/usertty file is used to add access restrictions to users. If this file does not exist, there are no other restrictions.

 

After the username is analyzed, login searches for/etc/passwd and/etc/shadow to verify the password and set other information about the account, such as what is the main directory and what shell is used. If no main directory is specified, the root directory is used by default. If no shell is specified,/bin/bash is used by default.

After the login program is successful, the last logon information (recorded in/var/log/lastlog) is output to the corresponding terminal ), check whether the user has any new emails (in the directory of the corresponding user name of/usr/spool/mail ). Then set various environment variables: For bash, the system first looks for the/etc/profile script file and runs it. Then, if the user's main directory exists. execute the bash_profile file. Other configuration files may be called in these files. After all the configuration files are executed, various environment variables are also set, A familiar command line prompt will appear, and the entire startup process ends.

The inittab document describes the processes (such as/etc/init. d/boot,/etc/init. d/rc, and getty) started during system boot and normal operations ).

Init

(8) discuss the concept of runlevels. Each running level has its own set of processes. the valid running level is 0-6 plus A, B, and C. each entry in the inittab document is in the following format:

Id: runlevels: action: process

Rows starting with '#' are ignored.

Id

The unique identifier of entries in the inittab document, which must be 1-4 characters long (for example, the sysvinit program generated by library versions earlier than 5.2.18 or a. out is limited to 2 characters ).

Note: For getty or other registration processes, the id must be the tty Suffix of the response terminal line, for example, 1 responds to tty1. Otherwise, the registration process cannot work normally.

Runlevels

Lists the running levels of a specified action.

Action

Describes the action to take.

Process

The process to be executed. if the process field starts with a '+', init will not charge the process in the utmp and wtmp documents. this is because getty needs to host utmp/wtmp accounting by itself, and it is also a legacy vulnerability.

The runlevels field can contain multiple characters that indicate different running levels. For example, 123 indicates that the process must be started when the running level is 1, 2, and 3. the runlevels domain of an ondemand entry can contain A, B, or C. the runlevels fields used for sysinit, boot, and bootwait entries are ignored.

When the running level is changed, the processes that are not given in the new operation level are killed. Use the SIGTERM signal first, and then the SIGKILL.

Actions that can be used in the action field include:

Respawn

The process is restarted immediately after it is terminated (for example, getty ).

Wait

Start this process as long as you enter the specified running level, and init waits for the end of the process.

Once

This process is started once at the specified running level.

Boot

This process is executed during system boot. The runlevels domain is ignored.

Bootwait

Execute this process during system boot. and init waits for the process to end (such as/etc/rc). The runlevels domain is ignored.

Off

Do nothing.

Ondemand

Only processes marked as ondemand will be executed at the ondemand running level. in any case, the running level is not actually changed (ondemand running level is 'A', 'B', and 'C ').

Initdefault

The initdefault entry indicates the running level that the system enters after booting. If such an entry does not exist, init will query the running level on the console. The process domain to be accessed is ignored.

Sysinit

This process is executed during system boot. This process will be executed before the boot or bootwait entry. The runlevels domain is ignored.

Powerwait

This process is executed when the power supply is insufficient. The init process is usually notified when a process connects the UPS to the computer. Init will wait until the process ends before continuing other work.

Powerfail

Similar to powerwait, but init does not wait for the process to complete.

Powerokwait

Execute this process immediately after init receives the power recovery notification.

Powerfailnow

This process is executed when init is notified that the UPS power supply is quickly exhausted while the external power supply fails (invalid). (assuming that the UPS and monitoring process can detect such a situation ).

Ctrlaltdel

Execute this process when init receives the SIGINT signal. This means that someone has pressed the CTRL-ALT-DEL key combination on the console, typically, might want to execute something like shutdown and then enter single user mode or reboot the machine.

Kbrequest

This process is executed when init receives a special combination of key signals generated from the console keyboard.

This document has not been completed for this feature; more information can be found in the kbd-x.xx package (the latest kbd-0.94 when writing this document ). of course, you may want to map key combinations for some "KeyboardSignal" actions. For example, to map (Alt-up arrow), you can use the following methods in the keyboard ing document:

Alt key code 103 = KeyboardSignal

 

Example

This is an example document similar to the old Linux inittab document:

# Inittab for linux

Id: 1: initdefault:

Rc: bootwait:/etc/rc

1: 1: respawn:/etc/getty 9600 tty1

2: 1: respawn:/etc/getty 9600 tty2

3: 1: respawn:/etc/getty 9600 tty3

4: 1: respawn:/etc/getty 9600 tty4

This document executes/etc/rc at boot and starts the getty process on the ty1-tty4.

A more detailed inittab will have different running levels (refer to its own notes ):

# Enter the default running level

Id: 2: initdefault:

# Complete system initialization before performing other tasks.

Si: sysinit:/etc/rc. d/bcheckrc

# The running level 0 suspends the system, 6 restarts, and 1 single user mode.

L0: 0: wait:/etc/rc. d/rc. halt

L1: 1: wait:/etc/rc. d/rc. single

L2: 2345: wait:/etc/rc. d/rc. multi

L6: 6: wait:/etc/rc. d/rc. reboot

# What to do when "3 keys" are pressed.

Ca: ctrlaltdel:/sbin/shutdown-t5-rf now

# Running level 2 and 3: generate the getty process on the console. If the running level is 3, generate getty on the modem.

1: 23: respawn:/sbin/getty tty1 VC linux

2: 23: respawn:/sbin/getty tty2 VC linux

3: 23: respawn:/sbin/getty tty3 VC linux

4: 23: respawn:/sbin/getty tty4 VC linux

S2: 3: respawn:/sbin/uugetty ttyS2 M19200

 

Document

/Etc/inittab

 

On zylonite, yes

: Sysinit:/etc/init. d/rcS

TtyS0: respawn:-/bin/sh

TtyS1: respawn:-/bin/sh

TtyS2: respawn:-/bin/sh

Tty1: respawn:-/bin/sh

Tty2: respawn:-/bin/sh

: Ctrlaltdel:/bin/umount-a-r

 

On fedra 3, yes

#

# Inittab This file describes how the INIT process shocould set up

# The system in a certain run-level.

#

# Author: Miquel van Smoorenburg,

# 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. sysinit

L0: 0: wait:/etc/rc. d/rc 0

L1: 1: wait:/etc/rc. d/rc 1

L2: 2: wait:/etc/rc. d/rc 2

L3: 3: wait:/etc/rc. d/rc 3

L4: 4: wait:/etc/rc. d/rc 4

L5: 5: wait:/etc/rc. d/rc 5

L6: 6: wait:/etc/rc. d/rc 6

# Trap CTRL-ALT-DELETE

Ca: 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 runlevels

1: 2345: respawn:/sbin/mingetty tty1

2: 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 5

X: 5: respawn:/etc/X11/preofdm-nodaemon

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.