-
# 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:5:initdefault:# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit#7个不同运行等级需要启动的服务的脚本放置路径
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/prefdm -nodaemon上面是/etc/inittab的内容,该文件的基本语法
[设置项目]:[run level]:[init的操作行为]:[命令项目]
1.设置项目:最多4个字符,init主要工作项目,简单的表示说明
2.运行等级:35表示运行等级为3和5都会执行
3.init的操作项目:man inittab查阅更多信息.
4.命令项目:可以执行的命令,通常是一些脚本
/etc/rc.d/rc.sysinit
/etc/inittab中这样一句
si::sysinit:/etc/rc.d/rc.sysinit,这个shell脚本是用来设置系统环境.大概有1000行,看了一会头就大了.索性不看了.
在经过/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运行等级5的启动目录放在/etc/rc.d/rc5.d目录中.
"ll /etc/rc.d/rc5.d"查看目录下的文件.发现全部是以 S 或 K 为开头的连接文件.这些连接文件都是/etc/init.d里的shell脚本.
lrwxrwxrwx 1 root root 19 2008-07-19 K90bluetooth -> ../init.d/bluetooth
lrwxrwxrwx 1 root root 14 2008-07-19 K91capi -> ../init.d/capi
lrwxrwxrwx 1 root root 17 2008-09-07 K92ipvsadm -> ../init.d/ipvsadm
lrwxrwxrwx 1 root root 15 03-17 11:50 K95kudzu -> ../init.d/kudzu
lrwxrwxrwx 1 root root 23 2008-07-19 S00microcode_ctl -> ../init.d/microcode_ctl
lrwxrwxrwx 1 root root 17 2008-09-04 S03sysstat -> ../init.d/sysstat
lrwxrwxrwx 1 root root 25 2008-07-19 S04readahead_early -> ../init.d/readahead_early
lrwxrwxrwx 1 root root 18 2008-07-19 S06cpuspeed -> ../init.d/cpuspeed
■以S为开头的文件,为启动时需要"start"的服务
■以K为开头的文件,为关机时需要"stop"的文件连接
■在S与K后面接的数字,表示该文件的执行顺序
■将/etc/init.d连接到/etc/rc.d/rc5.d的方法,除了手动建立外,其实都是以chkconfig程序来管理的
在完成了系统所有服务的启动后,接下来Linux就会启动终端或X windows来等待用户登录.
# 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在运行等级2,3,4,5时,都会执行/sbin/mingetty,而且执行6个(mingetty就是启动终端的命令)
■respawn The process will be restarted whenever it terminates (e.g. getty),所以我们在登录tty1终端界面,以exit离开后,系统还是会重新显示等待用户输入画面
■将上面清单中的某些项目注释掉,可以取消某些终端界面
# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon如果是等级5,则还会执行/etc/X11/prefdm -nodaemon命令来启动X Window.
/etc/rc.d/rc.local
可以把自己制作的shell脚本的完整文件名写入/etc/rc.d/rc.local,然后系统启动时就可以执行我的shell脚本.
如果只是暂时更改系统的运行等级,用命令init [0-6]来更改运行等级.现在运行等级是5,命令"init 3"就是切换到运行等级3.
当执行"init 3"时系统:
■ 先比较/etc/rc.d/rc3.d和/etc/rc.d/rc5.d内的K和S开头的文件
■ 关闭/etc/rc.d/rc5.d内的一些服务,且该服务并不存在于/etc/rc.d/rc3.d中
■ 启动/etc/rc.d/rc3.d内的服务
"runlevel" 查看当前运行等级