Inittab files in Linux

Source: Internet
Author: User
Tags sigint signal syslog terminates

The init process number is 1 (ps-aux | Less), it can be seen from this point that the INIT process is the starting point for all processes in the system, and Linux starts to run the INIT program after it completes the kernel boot.

The INIT program needs to read the configuration file/etc/inittab. Inittab is a non-executable text file that consists of several lines of instructions.

Understanding RunLevel:

RunLevel is used to represent the system state after the end of the Init process, there is no fixed information in the hardware of the system to represent RunLevel, it is purely a software structure. Init and Inittab are the only reasons runlevel affect the state of the system. In the above example, the Inittab file begins with the comment master

Used to describe RunLevel:

Runlevel 0 is to have init close all processes and terminate the system.

Runlevel 1 is used to transfer the system to single-user mode, single-user mode can only be accessed by the system administrator, in this mode to deal with those who can not make changes in the case of logged-in users, the Runlevel number 1 can also be replaced with S.

Runlevel 2 is a mode that allows the system to enter multiple users, but does not support file sharing, which is rarely applied.

Runlevel 3 is the most common mode of operation, mainly used to provide true multiuser mode and the default mode for most servers.

Runlevel 4 is generally not used by the system, users can design their own system state and apply it to Runlevel 4 phase, although rarely used, but the system can be used to implement some specific login requests.

Runlevel 5 is to initialize the system to a dedicated X Window terminal. This is not a good choice for a powerful Linux system, but it can be implemented by booting in RunLevel if the user wants to.

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

Inittab File Contents:

# # #表示当前缺省运行级别为5 (Initdefault);

Id:5:initdefault:/* Enter the graphical interface after startup, set to 3 to enter the character terminal interface */

# # #启动时自动执行/etc/rc.d/rc.sysinit script (sysinit)

/*

All lines that start with # in the Inittab file are comment lines. Comment Lines help users understand the Inittab file, and the values in the Inittab file are in the following format:

Label is a 1~4-character label that is used to indicate the value entered. Some systems only support a 2-character label. For this reason, most people limit the number of label characters to less than 2. The tag can be a string of any character, but in fact, some specific tags are common, and the tags used in red Hat Linux are:

Code:

ID is used to define the default level of Init run

Si is the process of system initialization

ln where n is from 1~6, indicating the level of runlevel that the process can use

UD is the upgrade process

CA indicates processes that run when Ctrl+alt+del is pressed

PF refers to a process that runs when a UPS indicates a power outage

PR is the process that the UPS needs to run before the system actually shuts down the signal when it sends a power recovery

X is the process that needs to run when the system is transferred to the X terminal

The RunLevel field specifies the level of runlevel. You can specify more than one RunLevel level, or you can specify a specific value for the RunLevel field.

The Action field defines the state in which the process should run:

Code:

Boot runs at system startup, ignoring RunLevel

The bootwait runs at system startup, and Init waits for the process to complete. Ignore RunLevel

Ctrlaltdel when the Ctrl+alt+del three keys are pressed at the same time, the SIGINT signal is sent to Init. Ignore RunLevel

Initdefault do not perform this process, it is used to set the default RunLevel

Kbrequest run when Init receives a signal from the keyboard. Here the keyboard combination is required to conform to keyboardsigral (see/usr/share/doc/kbd-* for a document on the keyboard combination)

Off is not allowed, so the process does not run

Once run once per RunLevel level

OnDemand run when the system specifies a specific run level A, B, C

Powerfail run when Init receives SIGPWR signal

Powerokwait run when a sigpwd signal is received and the power state in the/etc/file contains OK

Powerwait when the sigpwd signal is received, and Init waits for the process to run at the end

Respawn restarts a process whenever it terminates

Sysinit run before the boot or bootwait process runs

Wait run process waits for input run mode

The process field contains the processes that Init executes, and the process takes the same format as running the process at the command line, so the process field begins with the name of the session, followed by the runtime, followed by the arguments that are passed to the process at run time. For example/sbin/shutdown-t3-r now, the process executes when Ctrl+alt+del is pressed, and can be entered directly at the command line to reboot the system.

Records for special purposes

Learn the example file carefully and learn how to apply the syntax format for Inittab. Most of the content of the file can be ignored, because more than half of the content is commented, and some of the remaining file content is mainly used to implement some special functions:

The value of the ID indicates that the default RunLevel is 3.

The value of UD wakes up the/sbin/update process, which, in order to preserve the integrity of the disk, empties the entire I/O buffer before I/O to the disk.

The values of PF, PR, and CA are only called by specific interrupts.

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

Getty process to provide services for virtual end-devices, such as:

3:2345:respawn:/sbin/mingetty Tty3

The value of the Label field is 3,3 is the number 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, and when the process terminates, Init restarts it immediately. The path name of the startup process is/sbin/mingetty, which is the minimum version of Getty that implements the virtual terminal support, providing tty3 the process to start the virtual appliance.

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

This value tells the INIT program to run the/etc/rc.d/rc.sysinit script file to initialize the system, which, like all startup scripts, is just an executable file containing the Linux shell command, and note that the string entered must include the full path of the script. Different versions of Linux store this script location is not the same, but do not deliberately to remember these locations, just view the/etc/inittab file, the 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

# # #当运行级别为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

# # #在启动过程中允许按CTRL-alt-delete Restart System

# Trap Ctrl-alt-delete

Ca::ctrlaltdel:/sbin/shutdown-t3-r now

# when our UPS tells us Power had failed, assume we have a few minutes

# of Power left. Schedule a shutdown for 2 minutes.

# This does, the course, assume you have Powerd installed and your

# UPS connected and working correctly.

PF::p owerfail:/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 "

# # #在2, 3, 4, 5 level on the Ttyx as the parameters to execute the/sbin/mingetty program, open Ttyx terminal for user login,

# # #如果进程退出则再次运行mingetty程序 (respawn)

# 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

# # #在5级别上运行xdm程序, provide XDm graphical login interface, and re-execute on exit (respawn)

# Run XDm in RunLevel 5

X:5:respawn:/etc/x11/prefdm-nodaemon

Take the Inittab file above as an example to illustrate the format of Inittab. Lines where # begins with # are comment lines, and each row has the following format in addition to the comment line:

Id:runlevel:action:process

The detailed explanations of the above items are as follows:

1. Id

The ID refers to the entry identifier, which is a string, and for other login program items such as Getty or Mingetty, the ID is the same as the TTY number, otherwise the Getty program will not function properly.

2. RunLevel

RunLevel is the identity of the runlevel at which Init is located, typically using 0-6 and s or S. 0, 1, 6 operation level is reserved by the system: 0 as Shutdown action, 1 as restart to single-user mode, 6 restart; S and s have the same meaning, represent single-user mode, and do not have inittab files, and therefore do not appear in Inittab, in fact, when entering single-user mode, init runs/sbin/sulogin directly on the console (/dev/console). In the general system implementation, the use of 2, 3, 4, 5 levels, in the Redhat system, 2 represents a multi-user mode without NFS support, 3 represents a full multi-user mode (also the most commonly used level), 4 reserved for user-defined, 5 represents the XDm graphical login method. 7-9 levels are also available, and traditional UNIX systems do not define these levels. RunLevel can be multiple values in parallel to match multiple runlevel, and for most actions, only if RunLevel matches the current runlevel is successful.

3. Action

An action is a description of how the subsequent process works. Action-desirable values include: Initdefault, Sysinit, boot, bootwait, and so on:

Initdefault is a special action value that identifies the default boot level, and when Init is activated by the core, it reads the Initdefault item in the Inittab, obtains runlevel in it, and acts as the current runlevel. If there is no Inittab file, or there are no Initdefault entries in it, INIT will request input runlevel on the console.

Actions such as sysinit, boot, bootwait, and so on, will run unconditionally when the system starts, ignoring the runlevel.

The rest of the action (without initdefault) is related to a runlevel. The definitions of each action are described in detail in the Inittab Man Handbook.

4. Process

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

Part III: System initialization

There is a line in the init configuration file:

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

It calls the execution of/etc/rc.d/rc.sysinit, while Rc.sysinit is a bash shell script that mainly

There is a line in the init configuration file:

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

It calls the execution of/etc/rc.d/rc.sysinit, and Rc.sysinit is a bash shell script, which is mostly done with some system initialization, and Rc.sysinit is an important script to run every run level first. Its main tasks are: Activating the swap partition, checking the disk, loading the hardware modules, and some other priorities that need to be performed.

Rc.sysinit has about 850 rows, but each single feature is relatively simple, with comments, suggesting that interested users can read the file on their own machine in order to understand the details of the initialization of the system. Because this file is longer, it is not listed in this article, and does not make a specific introduction.

When the Rc.sysinit program finishes executing, it will return to Init to continue to the next step.

Part IV: Start the daemon for the corresponding runlevel

After Rc.sysinit executes, it will return to Init to continue with other actions, usually followed by the/ETC/RC.D/RC program. For example, run Level 5, Init executes the following line in the configuration file Inittab:

L5:5:WAIT:/ETC/RC.D/RC 5

This line indicates that running with the 5 parameter/ETC/RC.D/RC,/ETC/RC.D/RC is a shell script that accepts 5 as a parameter to execute all RC startup scripts under the/etc/rc.d/rc5.d/directory,/etc/rc.d/rc5.d/ These startup scripts in the directory are actually some linked files, not the actual RC startup scripts, and the actual RC startup scripts are actually placed in the/etc/rc.d/init.d/directory. These RC startup scripts have a similar usage, and they generally accept start, stop, restart, status, and so on.

The RC startup script in/etc/rc.d/rc5.d/is usually a link file starting with K or S, and will run with the start parameter for startup scripts starting with S. If it is found that the corresponding script also has a K-link, and is already in the running state (the file under/var/lock/subsys/as the flag), the stop is the first parameter to stop these started daemons, and then rerun. This is done to ensure that when Init changes the RunLevel, all associated daemons are restarted.

As to which Daemons will be run at each run level, the user can be set from the row by using "System Services" in Chkconfig or Setup. Common daemon processes are:

AMD: Automatically install the NFS daemon

APMD: Advanced Power Management Daemon

Arpwatch: Log and build an Ethernet address and IP address to the database that you see on the LAN interface

AutoFS: Automatic installation of the management process AutoMount, related to NFS, dependent on NIS

The daemon of the scheduled task under Crond:linux

Named:dns Server

NETFS: Installing NFS, Samba, and NetWare network file systems

Network: Activating a scripted program that has a configured networking interface

NFS: Open NFS Service

PORTMAP:RPC Portmap Manager, which manages RPC service-based connections

SendMail: Mail server SendMail

Smb:samba file sharing/Printing service

Syslog: A script that lets the system boot up syslog and klogd the system log waiting process

xfs:x window font server, providing font sets for local and remote X servers

XINETD: Support the core daemon of various network services, can manage Wuftp, sshd, Telnet and other services

These daemons also start to complete, the RC program is finished, and then return to Init to proceed to the next step.

Part V: Setting up the terminal

After the RC finishes executing, return to init. At this point the basic system environment has been set up, various daemons have been started. Init then opens 6 terminals so that the user can log on to the system. You can switch between the 6 terminals by pressing ALT+FN (n corresponds to 1-6). The following 6 lines in Inittab define 6 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 can be seen in the 2, 3, 4, 5 of the operating level will be respawn to run the Mingetty program, mingetty program can open terminal, set mode. At the same time it will display a text login interface, which is the login interface we often see, in this login screen will prompt the user to enter a user name, and the user input user will be passed as a parameter to the login program to verify the identity of the user.

Part VI: Login to the system, start to complete

For graphical users with a run level of 5, their login is via a graphical login interface. After successful login, you can go directly to KDE, GNOME and other window manager. And this article is mainly about the text mode of login situation:

When we see the login screen of Mingetty, we can enter the user name and password to log into the system.

Linux Account Verification Program is Login,login will receive mingetty from the user name parameters. Login then parses the username: If the user name is not root and there is a/etc/nologin file, login will output the contents of the Nologin file and then exit. This is typically used for system maintenance to prevent non-root users from logging on. Only the terminal registered in/etc/securetty allows the root user to log on, and if the file does not exist, root can log on at any terminal. The/etc/usertty file is used to make additional access restrictions to the user, and there are no additional restrictions if the file does not exist.

After analyzing the user name, login will search/etc/passwd and/etc/shadow to verify the password and set up additional information about the account, such as what the home directory is and what shell to use. If you do not specify a home directory, the default is the root directory, and if you do not specify a shell, the default is/bin/bash.

When the login program succeeds, it will output the most recent login information (recorded in/var/log/lastlog) to the corresponding terminal, and check whether the user has new mail (in/usr/spool/mail/'s corresponding user list). Then start setting up the various environment variables: for bash, the system first looks for the/etc/profile script file and executes it, and then executes it if there is a. bash_profile file in the user's home directory, in which case other configuration files may be called. After all the configuration files have been executed, the various environment variables are set up, and a familiar command prompt will appear, and the entire boot process is over.

The Inittab documentation describes which processes are initiated during system boot and normal operations (such as/etc/init.d/boot,/ETC/INIT.D/RC, Getty, and so on).

Init

(8) Discuss the concept of runlevels (run level), where each run level has a collection of his own startup processes. The valid run level is 0-6 plus a, B, and C for OnDemand entries. Each entry in the Inittab document resembles the following format:

Id:runlevels:action:p rocess

Lines that begin with ' # ' are ignored.

Id

The unique identifier of the entry in the Inittab document, limited to 1-4 characters (if the Sysvinit program is generated using a library compiled with a version number less than 5.2.18 or a.out), it is limited to 2 characters.

Note: For Getty or other registration processes, the ID must be a TTY suffix that responds to the terminal line, such as 1 response tty1, otherwise the registration process does not work properly.

Runlevels

Lists the run level at which the specified action occurred.

Action

Describes the action to take place.

Process

The process to be executed. If the process domain begins with a ' + ', Init does not account for this process in the utmp and wtmp documents. This is due to the need for Getty to host the Utmp/wtmp account, and this is a historical loophole.

The runlevels domain can contain multiple characters representing different run levels, such as 123 to indicate that the process starts at run Level 1, 2, and 3 o'clock. The Runlevels field used for the OnDemand entry can contain a, B, or C. The runlevels domain used for sysinit, boot, and bootwait entries is ignored.

When changing the run level, those running processes that are not given in the new run level are killed, first using the sigterm signal, and then Sigkill.

Actions that the action field can use are:

Respawn

The process restarts as soon as it terminates (such as Getty).

Wait

This process is started as soon as it enters the specified run level, and Init waits for the end of the process.

Once

This process is initiated once the specified run level is entered.

Boot

This process is performed during system boot. The Runlevels field is ignored.

Bootwait

This process is performed during system boot. And Init waits for the end of the process (such as/ETC/RC). The Runlevels field is ignored.

Off

Don't do anything.

OnDemand

Only those processes marked as OnDemand are executed when entering the OnDemand run level. In any case, the run level is not actually changed (the OnDemand run level is ' a ', ' B ', and ' C ').

Initdefault

The Initdefault entry gives the run level entered when the system is booted, and if no such entry exists, Init asks the console to enter the run level. The process field is ignored.

Sysinit

This process is performed during system boot. This process will be executed before the boot or bootwait entry. The Runlevels field is ignored.

Powerwait

This process is performed when the power supply is low. The init process is usually notified when a process connects the UPS to the computer, and Init waits for the process to finish before continuing with the other work.

Powerfail

Similar to powerwait, but Init does not wait for this process to complete.

Powerokwait

This process is executed immediately after Init receives a notification that power has been restored.

Powerfailnow

This process is executed when Init is told that the UPS power is running out while the external power supply fails (invalid). (assuming that the ups and monitoring processes can find such a situation).

Ctrlaltdel

This process is executed when Init receives the SIGINT signal. This means that someone has pressed the Ctrl-alt-del key combination in the console, typically to perform a similar shutdown and then go into single-user mode or reboot the machine.

Kbrequest

This process executes when Init receives a special combination of key signals generated from the console keyboard.

This document is not yet complete for this feature; More information can be found in the KBD-X.XX package (the latest is kbd-0.94 when writing this document). Of course you might want to map the key combinations for some "keyboardsignal" behavior, such as for mapping (alt-up arrow) to use the following in a keyboard mapping document:

Alt KeyCode 103 = keyboardsignal

Example

This is an example document similar to the old Linux Inittab documentation:

# 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 time and starts the Getty process on Ty1-tty4.

A more detailed inittab will have different run levels (refer to the comments themselves):

# Enter the default run level

Id:2:initdefault:

# Complete the initialization of the system before doing any other work.

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

# Run-level 0 suspend system, 6 reboot, 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

# "3 Keys" to do the work when pressed.

CA::CTRLALTDEL:/SBIN/SHUTDOWN-T5-RF now

# Run-Level 2 and 3: Generate the Getty process at the console, run at 3 o'clock and 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 the Zylonite is

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

Fedra 3 on the

#

# Inittab This file describes how the INIT process should 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 is:

# 0-halt (do not set Initdefault to this)

# 1-single User mode

# 2-multiuser, without NFS (the same as 3, if you don't 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 had failed, assume we have a few minutes

# of Power left. Schedule a shutdown for 2 minutes.

# This does, the course, assume you have Powerd installed and your

# UPS connected and working correctly.

PF::p owerfail:/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/prefdm-nodaemon

Inittab files in Linux

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.