您的位置:首页 > 运维架构 > Linux

Linux的run-level

2010-09-02 11:47 597 查看
Linux的run-level:

0:halt 关机

1:single user mode 单用户模式

2:multi-user without Network 不支持网络的多用户模式

3:full multi-user mode 完整的多用户模式

4:unused 保留

5:X x window模式

6:reboot 重新启动

/etc/inittab之中定义了开机之后的run-level以及其他有关启动的设定,在inittab之中有一个基本的语法:

[id]:[run-levels]:[action]:[process]

[id]是一个代号,最好不要超过4个字符,超过了大部分版本的解释器不支持。

[run-levles]是运行的级别,可以指定多个级别,比如2345表示在2,3,4,5级别都执行。

[action]init的行动,有以下几种:

respawn:

表示process如果terminate结束后会被重新启动,好比mingetty,用户logout之后会重新启动一个mingetty等待用户login。

wait:

这种process只会启动一次,并且init会等待process结束。

once:

这种process只会启动一次,init不会等待process结束。

boot:

启动时运行,run-levels会被忽略

bootwait:

同boot,而且init会等待process的结束,好像/etc/rc

off:

什么也不做

ondemand:

特定的run-level执行,可能是a,b,c之类。(没有试过,不知道怎么用。)

initdefault:

启动后要进入的run-level

sysinit:

启动时运行,会在boot和bootwait的process之前运行,忽略run-levels

powerwait

电源错误时候,init会等待这个process结束

powerfail

电源错误时候运行

powerokwait

电源恢复时候运行,init会等待这个process结束

powerfailnow

电源(UPS)即将没电时执行

ctrlaltdel:

顾名思义,CTRL+ALT+DEL的处理

kbrequest:

指定的键盘热键的处理,可以在自己的keymaps之中指定热键,指定后要loadkeys一下。

[process]

要执行的程序包括脚本,如果以+开始,表示init不会为process做utmp和wtmp的工作。

以下是我电脑之中的/etc/inittab:

#

# 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)

#

# 这里使用initdefault指定系统启动后进入的run-level

id:5:initdefault:

# 这里使用sysinit来指定系统初始化的脚本,可以指定为其他脚本

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit

# 每个run-level自己的初始化脚本

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

# 处理 CTRL-ALT-DELETE

# Trap CTRL-ALT-DELETE

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

# 处理powerfail事件

# 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"

# 处理powerokwait事件

# If power was restored before the shutdown kicked in, cancel it.

pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

# 定义虚拟控制台tty,2-5都有6个text的控制台,用的是respawn,每次logout后init又会

# 产生一个新的mingetty进程

# 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-level = 5,定义x window控制器

# Run xdm in runlevel 5

x:5:respawn:/etc/X11/prefdm -nodaemon
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: