linux init 和系统初始化
(Linux Init and System Initialization)
一: init和runlevels
init进程读取/etc/inittab文件,使用它来决定如何创建进程。你可以man init来得到更多的信息。我们
应该注意到,init进程总是在运行中,并且可以根据各种各样的信号来动态的做一些事情和运行新的进程
。管理员可以通过修改/etc/inittab文件或者使用telinit命令来告知init进程改变系统进程和运行级别(runlevels)。首先,我们解释一下什么是运行级别(runlevels),运行级别是系统对软件的配置,它只允许被选择的一组进程得到运行。init进程可以使系统在8个不同的运行级别下运行。8个级别是0~6,S和s。当然系统一次只能在一个级别下运行,也就是说不能同时运行在不同的级别下。这些运行级别有各自的适用情况,对red hat linux version 6来说,它们是:
0 - halt(停机)
1 - Single user mode(单一用户模式)
2 - Multiuser, without NFS(多用户模式,没有nfs文件系统支持,同3,如果你没有网络的话)
3 - Full multiuser mode(多用户模式)
4 - unused(没有用到)
5 - X11(图形模式)
6 - Reboot(重启了)
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <[email protected]>
# 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)
#
1) id:3:initdefault:
# System initialization.
2) si::sysinit:/etc/rc.d/rc.sysinit
# Things to run in every runlevel.
10) ud:nce:/sbin/update
# Trap CTRL-ALT-DELETE
11) 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.
12) pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
# If power was restored before the shutdown kicked in, cancel it.
13) pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
# Run gettys in standard runlevels
14) 1:2345:respawn:/sbin/mingetty tty1
15) 2:2345:respawn:/sbin/mingetty tty2
16) 3:2345:respawn:/sbin/mingetty tty3
17) 4:2345:respawn:/sbin/mingetty tty4
1 5:2345:respawn:/sbin/mingetty tty5
19) 6:2345:respawn:/sbin/mingetty tty6
# Run xdm in runlevel 5
# xdm is now a separate service
20) x:5:respawn:/etc/X11/prefdm -nodaemon