Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What file is the linux run level defined in?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "linux run level definition in what file", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "linux run level definition in what file" article.

The linux run level is defined in the "/ etc/inittab" configuration file. "/ etc/inittab" is the configuration file used by the init initialization program when linux initializes the file system; this configuration file can only be used to set the default run level of the system, that is, the run level that the system will enter when it boots up.

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What is the run level?

In fact, Linux uses the run level to determine which services are started when the system is started.

Linux has seven runlevels by default, as shown in Table 1.

Table 1 run level includes 0 shutdown 1 single user mode, which can be imagined as Windows security mode, which is mainly used for system repair 2 incomplete command line mode, without NFS service 3 complete command line mode, that is, standard character interface 4 system retains 5 graphical mode 6 restart

Which file is the linux run level defined in?

The linux run level is defined in the "/ etc/inittab" configuration file.

The / etc/inittab configuration file can only be used to set the default runlevel of the system, that is, which runlevel the system will enter after booting up

The / etc/inittab file describes which processes start up and run normally. The configuration file used by the init initialization program when inittab initializes the file system for linux. This file is responsible for setting where the initialization script of the init initialization program is; the commands that run at each runlevel initialization; the commands for booting, shutting down, and restarting; and the commands that run when each runlevel logs in.

The format of entries in the inittab file is as follows:

Label:runlevels:action:process

Each field is described below.

1.label

Label is a unique sequence that identifies an entry of 1-4 characters, and some systems support only 2-character tags. For other login program items such as getty or mingetty, label and tty are required to have the same number, otherwise the getty program will not work properly.

Commonly used labels are:

Id is used to define the default level of init to run si is the process ln initialized by the system, where n from 1 to 6, indicates that the level of runlevel that can be used by the process ud is the upgrade process ca indicates that the process pf runs when Ctrl+Alt+Del is pressed, refers to the process that runs when UPS indicates that the process running when the power is off is before the UPS signals power recovery before the system is actually shut down, x is the process that needs to be run when the system is transferred to the X terminal.

2.runlevels

Runlevels lists the runlevels and specifies the actions that should be taken. You can specify multiple runlevel levels or not specify a specific value for the runlevel field.

Runlevel 0 tells init to shut down all processes and terminate the system. Runlevel 1 is used to transfer the system to single-user mode, which can only be entered by the system administrator. In this mode, files that cannot be changed in the presence of logged-in users are processed, and the number 1 of runlevel can also be replaced by S. Runlevel 2 allows the system to enter multi-user mode, but does not support file sharing, which is rarely used. Runlevel 3 is the most commonly used mode of operation, mainly used to provide true multi-user mode, which is also 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 the runlevel 4 phase, although rarely used, but the system can be used to achieve some specific login requests. Runlevel 5 is a dedicated X Window terminal that initializes the system. This is not a good choice for powerful Linux systems, but users can also implement this solution by starting it in runlevel if they need it. Runlevel 6 shuts down all running processes and restarts the system.

Debian6 does not run the / etc/inittab file by default. The default level is 2-5 and grouped into one class.

3.action

The action field defines the state in which the process should run and describes how the subsequent process will run. :

Respawn restarts the process wait running process waits for input run mode whenever it terminates the process will start a run level when the specified input and init will wait for each runlevel level of the once to run once this process will be executed once when the specified input runlevelboot runs at system startup, ignoring runlevelbootwait running at system startup, and init waiting for the process to complete. Ignore runlevelctrlaltdel to run when three Ctrl+Alt+Del keys are pressed at the same time, sending the SIGINT signal to init. Ignore runlevelinitdefault do not execute this process, it is used to set the default runlevelkbrequest to run when init receives a signal from the keyboard. The keyboard combination is required to comply with KeyBoardSigraoff forbidden entry, so the process does not run once once at each runlevel level when the system specifies specific operation levels A, B, C, run powerfail, run powerokwait when init receives the SIGPWR signal, when the SIGPWD signal is received and the power status in the / etc/ file contains OK, run powerwait when the SIGPWD signal is received, and init waits for the end of the process to run sysinit before running the boot or bootwait process.

4.process

The process field contains the process executed by init in the same format as running the process on the command line, so the process field starts with the process's name, followed by the parameters to be passed to the process at run time.

The code is as follows:

# / etc/inittab: init (8) configuration.# $Id: inittab,v 1.91 2002-01-25 13:35:21 miquels Exp $

The code is as follows:

# The default runlevel.id:2:initdefault: # indicates that the current default runlevel is 2

The code is as follows:

# Boot-time system configuration/initialization script.# This is run first except when booting in emergency (- b) mode.si::sysinit:/etc/init.d/rcS # process of system initialization

The code is as follows:

# What to do in single-user mode.~~:S:wait:/sbin/sulogin

The code is as follows:

# / etc/init.d executes the S and K scripts upon change# of runlevel.## Runlevel 0 is halt.# Runlevel 1 is single-user.# Runlevels 2-5 are multi-user.# Runlevel 6 is reboot.

The code is as follows:

L0:0:wait:/etc/init.d/rc 0l1:1:wait:/etc/init.d/rc 1l2:2:wait:/etc/init.d/rc 2l3:3:wait:/etc/init.d/rc 3l4:4:wait:/etc/init.d/rc 4l5:5:wait:/etc/init.d/rc 5l6:6:wait:/etc/init.d/rc 6# Normally not reached, but fallthrough in case of emergency.z6:6:respawn:/sbin/sulogin

The code is as follows:

# What to do when CTRL-ALT-DEL is pressed. # whether it is allowed to restart the system by CTRL-ALT-DELETE during startup # ca:12345:ctrlaltdel:/sbin/shutdown-T1-a-r now

The code is as follows:

# Action on special keypress (ALT-UpArrow). # kb::kbrequest:/bin/echo "Keyboard Request--edit / etc/inittab to let this work."

The code is as follows:

# What to do when the power fails/returns.pf::powerwait:/etc/init.d/powerfail startpn::powerfailnow:/etc/init.d/powerfail nowpo::powerokwait:/etc/init.d/powerfail stop

The code is as follows:

# / sbin/getty invocations for the runlevels.## The "id" field MUST be the same as the last# characters of the device (after "tty"). # # Format:#: # # Note that on most Debian systems tty7 is used by the X Window System,# so if you want to add more getty's go ahead but skip tty7 if you run X.# getty process to provide virtual terminal device service 1:2345:respawn:/sbin/getty 38400 tty1

The code is as follows:

The value of the # label field is 1getty 1 is the numeric suffix of the device tty1, and the tty1 is associated with the corresponding process. The runlevel that the getty process can start are 2Magi 3Jing 4 and 5. When the process terminates, init restarts it immediately. The path name of the startup process is / sbin/getty, which is the minimum version of getty that implements the virtual terminal support and provides tty1 with the process to start the virtual device. 2:23:respawn:/sbin/getty 38400 tty2#3:23:respawn:/sbin/getty 38400 tty3#4:23:respawn:/sbin/getty 38400 tty4#5:23:respawn:/sbin/getty 38400 tty5#6:23:respawn:/sbin/getty 38400 tty6# Example how to put a getty on a serial line (for a terminal) # # T0:23:respawn:/sbin/getty-L ttyS0 9600 vt100T1:23:respawn:/sbin/getty-L ttyS1 115200 vt100# Example how to put a getty on a Modem line.##T3:23:respawn:/sbin/mgetty-x0-s 57600 ttyS3

Example

# Begin / etc/inittabid:3:initdefault:si::sysinit:/etc/rc.d/init.d/rc sysinitl0:0:wait:/etc/rc.d/init.d/rc 0l1:S1:wait:/etc/rc.d/init.d/rc 1l2:2:wait:/etc/rc.d/init.d/rc 2l3:3:wait:/etc/rc.d/init.d/rc 3l4:4:wait:/etc/rc.d/init.d/rc 4l5: 5:wait:/etc/rc.d/init.d/rc 5l6:6:wait:/etc/rc.d/init.d/rc 6ca:12345:ctrlaltdel:/sbin/shutdown-T1-a-r nowsu:S016:once:/sbin/sulogin1:2345:respawn:/sbin/agetty tty1 96002:2345:respawn:/sbin/agetty tty2 96003:2345:respawn:/sbin/agetty tty3 96004:2345:respawn:/sbin/agetty tty4 96005:2345:respawn:/sbin/agetty tty5 96006:2345:respawn: / sbin/agetty tty6 960 End / etc/inittab above is the content of the article on "what file is the linux runlevel definition in?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report