Linux 版 (精华区)

发信人: don (驿路梨花), 信区: Linux
标  题: 关机与启动!
发信站: 哈工大紫丁香 (2000年06月09日11:40:06 星期五), 站内信件




关机与启动!
作者: 何斌武 (hbwork@dlut.edu.cn,大连理工大学网络中心,April 1999.)
三. 启动和关机
系统启动流程:
系统启动完成如下工作:
.机器本身所进行的必要的有限的自检
.查找一个可引导设备
.从引导设备上读取内核
.找到内核并初始化外设
.启动基本系统任务
.运行那些能提供服务的shell script
.其他应用程序开始
在系统启动过程中,绝大多数启动信息将同时写到主控台设备和系统日志文件,
系统日志文件可以参考系统文档syslogd和配置文件/etc/syslog.conf,
syslog.conf文件的最后一行为系统日志文件的位置.
1.初始化过程
内核: /vmunix, /unix或/boot/zImage, 位于/文件系统,kernel执行后运行
init, init将会创建一些正常操作所需要的子进程.这些操作包括设备主机名,
检查相应的磁盘并加载文件系统,启动系统日志,配置网络接口,启动网络和邮
件服务,清除临时分区,存储core dump, 要理解这些功能是如何实现的,需要更
深入的了解父进程是如何操作的,SYSV/BSD对这一父进程称之为init, 但其各自
的调用方式却差别很大.
.配置文件
linux使用一个非常灵活的init进程,init会直接建立在/etc/inittab中所列出
的任务, init通用运行级别如下:
0 shutdown
1 系统管理方式,所有的文件可以继续访问,但只有超级用户可以从主控台
访问系统
2 系统进入正常多用户操作方式
3 多用户操作方式,但同时开启远程文件共享,启动一些额外的进程以允许
远程文件共享,加载远程资源,同时向网上公布其远程资源(如nfs)
4 用户自定义多用户环境
5 自定义多用户环境,不同unix之间有所差别,如有些unix这试图关机并关闭电源
6 关闭机器后重新启动到运行级别2或3, 不同unix不完全相同
S/s 单用户方式,通常在inittab丢失或不对时使用此方式
Q/q 不改变运行状态,重新检查inittab, 不重启机器而开始新的改动.
示列文件/etc/inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg,
# 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:3:initdefault:
# System initialization.
si::sysinit:/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
# Things to run in every runlevel.
ud::once:/sbin/update
# 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:12345: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:/usr/bin/X11/xdm -nodaemon
x:3:respawn:/usr/bin/env KDEDIR=/opt/kde /opt/kde/bin/kdm -nodaemon
文件每一行格式如下:
identifier:runlevel:action-keyword:process
identifier: 最长4个字符,唯一标识一项
run-level: 为空表示所有级别,默认运行级别通常为2或3
action-keyword: init所采取的动作。具体参数含义如下:
Keyword Action Wait Restart
-------- -------------------------------------------- ---- -----
boot Executed only during a system boot. NO NO
multiuser after the system is started.
initdefault Start with this upon boot. The process field N/A N/A
is ignored. If level
off Kill processes when in a given level. Ignore N/A N/A
if the process doesn't exist.
once Run the process once. No No
powerfail Run processes when a powerdown is requested. No No
powerwait Run processes when a powerdown is requested. Yes No
respawn If the process doesn't exist, start it. If No Yes
the process does exist, do nothing.
sysinit Run processes before the login prompt is sent Yes No
to the system console.
wait Start processes once. Yes No
ctrlaltdel (Linux only.) The sequence was pressed on No No
the keyboard. Shutdown.
kbrequest (Linux only.) Keyboard spawned
request. This is ill-defined.
powerokwait (Linux only.) Power has come back on. Yes No
process:指作一daemon,shell script或program.这个进程可以执行其他二进制文件
或shell script.
在上面的示例中,系统加电后默认的运行状态为3,不同的运行级别所要执行的命令
由shell script /etc/rc.d/rc控制,/etc/rc.d/rc根据参数(运行级别数)的不同决
定执行/etc/rc.d/rc$runlevel.d/S*, 而运行级别1-6时如果没有到主控台的mingetty
则启动mingetty tty?,而对于用户的热启动请求则会生新启动机器(ctrlaltdel).
BSD类型的系统则使用另外一种灵活性稍差的init进程,init运行一个基本的重启
序列,根据所调用的方式不同,启动一个多用户或单用户系统。init通过信号改变
状态,使用kill命令来发送相应的信号,比如当从多用户切换到单用户时,超级用
户发送一个kill -TERM 1.
rc script(系统启动脚本程序).
BSD: /etc/rc /etc/rc.conf /etc/rc.conf.local ...
SYSV:
/etc/init.d/*
/etc/rc$runlevel.d/S* 系统启动rc shell script, 执行顺序按文件名
数字从小到大,如先执行S10*, 再执行S12*.
/etc/rc$runlevel.d/K* 系统关机rc shell script,执行顺序与启动文件
相反,先执行数字大的。
通常情况下/etc/rc$runlevel.d/*是到/etc/init.d/目录下相应文件
的连接。可执行ls -aF /etc/rc2.d/或file /etc/rc2.d/S*看一下。
多个不同运行级别的目录下的启动文件可能会连接到/etc/init.d/
下的同一个文件。
Linux Redhat: /etc/rc.d/init.d/*
/etc/rc.d/rc$runlevel.d/S*
/etc/rc.d/rc$runlevel.d/K*
/etc/rc.d/rc启动控制文件
网络配置文件: /etc/sysconfig/network
/etc/sysconfig/network-script/*
模块配置文件: /etc/conf.modules
Linux Slackware: /etc/rc.d/*
.启动守户进程及程序
使用ps aux |more应可以看到如下进程:
init 进程号永远为1,用户任务及大多数系统任务的父进程
inetd Internet Super Server, 此进程监听来自网络上的socket连接,
并调用相应的服务来处理所收到的信息,这种服务包括ftp,telnet,
finger,talk,rsh等。
getty 设置终端类型、速度、线路及其他方式
syslogd 记录系统信息的守护进程
crond 定时守户进程,可在指定时间及日期执行在crontab中所指定的任务。
named DNS服务
routed 路由表维护进程,使用RIP协议,用于网络信息传输
gated 路由表维护进程,所使用的路由协议比routed更多,功能更强
只有在使用动态路由协议的路由器上才有必运行routed或gated,普通
主机不用运行这两个守护进程。
nfsd/biod NFS相关进程
telnetd TELNET守护进程,当有远程telnet请求时由inetd启动telnetd
ftpd FTP守护进程,当有远程ftp请求时由inetd启动ftpd
注:如果有文件/etc/nologin存在,则只有超级用户可以从主控台进入系统,此时如
果有其他用户试图连接系统则会看到/etc/nologin的文本内容。
2.关机
关机会依次杀掉所有的进程,同步buffer与disk中的内容,然后umuont所有的文件
系统,关机时最好看一下当前是否有用户在使用系统。可以使用shutdown, reboot,
init,sync及halt关闭电源。最好不要使用halt关机,因为这样有可能损坏文件系统。
推荐使用:
shutdown [-h|-r] [-y] [ grace ]
grace用户退出的时间,单位为秒,默认值为60秒。
文件/etc/shutdown.allow列出可以执行shutdown的用户名。
TIPS:启动、关机时取好看一下主控台信息。

made by pageshop of CERNET network centre of DaLian region.copyright 1999


--
一条驿路,一种氛围。
一朵梨花,一种思考。
希望能在Linux这条驿路上与你同行!

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.239.63]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.455毫秒