📄 00000001.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: Hanky@FruitTea1 (骗谁啊?), 信区: Linux <BR>标 题: SysV init 2.6 的开机过程 (一) <BR>发信站: 果茶小站 (Wed May 29 19:38:46 1996) <BR> <BR>首先我们先讲一下为什麽是 sysv init 2.6: <BR>因为很多 distributions 用了有问题的 2.5x 版...... <BR>所以我们以 Linux 为平台, 讲 2.6 的。 <BR> <BR>这样开场白好像怪怪的, 先不管它。 <BR> <BR>一般来说, 系统在跑完 kernel bootstrapping 後, 就去跑 init <BR>这个『万process之父』, 有了它, 才能开始生小孩...... <BR>另外 Linux 有两个 kernel 类的 process 也开始跑了起来, <BR>一个是 kflushd, 另一个是 kswapd: <BR> <BR> * process ID 1: init <BR> * process ID 2: kflushd <BR> * process ID 3: kswapd <BR> <BR>只有这个 init 是完全属於 user 类的 process, 後两者是 kernel <BR>假藉 process 之名挂在排程上。 <BR> <BR>init 一开始就去读 /etc/inittab, 这个 inittab 中对於各个 <BR>runlevel 要跑哪些 rc 或 spawn 出什麽有很清楚的设定。 <BR> <BR>--------[/etc/inittab □例档]--------------------------------- <BR> <BR># /etc/inittab: init(8) configuration. <BR># $Id: inittab,v 1.4 1996/03/10 11:47:55 miquels Exp $ <BR> <BR># The default runlevel, 我们设为 3; runlevel 的概念我们等会儿提。 <BR>id:3:initdefault: <BR> <BR># 开机的 system configuration/initialization script. <BR># This is run first except when booting in emergency (-b) mode. <BR>si::sysinit:/etc/init.d/boot <BR> <BR># What to do in single-user mode. sulogin 即为 Single User LOGIN. <BR>~~:S:wait:/sbin/sulogin <BR> <BR># /etc/init.d executes the S and K scripts upon change <BR># of runlevel. 其中 /etc/init.d/rc 是一个 shell script, <BR># 後面的 0~6 参数表示要跑该 runlevel 所应跑的设定 script. <BR># Runlevel 0 is halt. <BR># Runlevel 1 is single-user. <BR># Runlevels 2-5 are multi-user. <BR># Runlevel 6 is reboot. <BR> <BR>l0:0:wait:/etc/init.d/rc 0 <BR>l1:1:wait:/etc/init.d/rc 1 <BR>l2:2:wait:/etc/init.d/rc 2 <BR>l3:3:wait:/etc/init.d/rc 3 <BR>l4:4:wait:/etc/init.d/rc 4 <BR>l5:5:wait:/etc/init.d/rc 5 <BR>l6:6:wait:/etc/init.d/rc 6 <BR> <BR># 当 CTRL-ALT-DEL 按下去了, 该做什麽?一般都是 shutdown -r now <BR>ca:12345:ctrlaltdel:/sbin/shutdown -t1 -r now <BR># ^^^^^先等个一秒好了 <BR> <BR># Action on special keypress (ALT-UpArrow). 这个我暂时查不到, 抱歉。 <BR>kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work." <BR> <BR># What to do when the power fails/returns. 这个我晚一点讲 (有关 UPS 的部份) <BR>pf::powerwait:/etc/init.d/genpowerfail start <BR>#pn::powerfailnow:/etc/init.d/genpowerfail now <BR>po::powerokwait:/etc/init.d/genpowerfail stop <BR>#pg::powerokwait:/etc/init.d/genpowerfail stop <BR> <BR># /sbin/getty invocations for the runlevels. <BR># ^^^^^^^^^^^开 console 出来了。 <BR># The "id" field MUST be the same as the last <BR># characters of the device (after "tty"). <BR># 例如在 runlevel==3 时, 会有六个 virtual console (tty1~tty6) <BR># Format: <BR># <id>:<runlevels>:<action>:<process> <BR>1:2345:respawn:/sbin/agetty 19200 tty1 <BR>2:23:respawn:/sbin/agetty 19200 tty2 <BR>3:23:respawn:/sbin/agetty 19200 tty3 <BR>4:23:respawn:/sbin/agetty 19200 tty4 <BR>5:23:respawn:/sbin/agetty 19200 tty5 <BR>6:23:respawn:/sbin/agetty 19200 tty6 <BR> <BR>----------[End of /etc/inittab]--------------------------------- <BR> <BR>上面的设定, 令系统在一跑完 kernel bootstrapping 後, 就去执 <BR>行 /etc/init.d/boot 这个 shell script, 如果没什麽问题, 就 <BR>进入 default runlevel, runlevel 在 sysv 通常是有如下意义: <BR> <BR>0: halt (只有 shutdown, 不 reboot 了) <BR>1: Single-user <BR>2: Multi-user <BR>3: Multi-user & 把 network resource export 出来 <BR>4: 除了有 Multi-user & export network resource, 一般来讲是留给 xdm <BR>5: 不太用到了. <BR>6: reboot (shutdown 後会 reboot) <BR> <BR>其中 2-5 都是 multi-user 的 runlevel, 通常 runlevel(2~5) <BR>越高, 所提供的服务也就越多。当系统资源有所变动 (例如电力) <BR>时, 我们可以用 telinit 去告知 init 要变换 runlevel (例如 <BR>原来是 runlevel=3, 用 telinit 2 使 runlevel 降为 2), 这 <BR>样子可以关掉一些网路资源服务; 或例如 telinit S 与 telinit 1 <BR>都是到 Single-user mode (但前者不同的是, telinit S 根本 <BR>就直接在 /dev/console 上执行一个 /bin/sh 给你用; 後者会 <BR>去执行 /etc/init.d/rc 1 这个指令); telinit 6 就等於 reboot. <BR> <BR>OK, 有问题请先提出来。 <BR> <BR>下面我们要讲到的是 /etc/init.d/boot 这个 script 应该做些 <BR>什麽, 才是我们要的。 <BR> <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -