ubuntu mid启动过程浅析是基于《upstart 和ubuntu启动过程和原理介绍》一文的。
下面也是upstart机制在ubuntu上的具体实现。
系统启动过程中配置文件执行流程图:
_____________________
| /etc/event.d/rcS |
| | |
| | |
| | |
| V |
| /etc/init.d/rcS |
| | |
| | |
| | |
| V |
| /etc/init.d/rc S |
| | |
| | |
| | |
| V |
| /etc/rcS.d/S* |
`````````````````````
(图1)
____________________________
| /etc/event.d/rc-default |
| | |
| | |
| | |
| V |
| /etc/event.d/rc2 |
| | |
| | |
| | |
| V |
| /etc/init.d/rc 2 |
| | |
| | |
| | |
| V |
| /etc/rc2.d/S* |
````````````````````````````
(图2)
以图2为例对流程进行详细分析:
首先分析/etc/event.d/rc-default文件(它就是设置默认运行级别的):
--------------------------------------------------------------------------------------------------------
# rc - runlevel compatibility
#
# This task guesses what the "default runlevel" should be and starts the
# appropriate script.
start on stopped rcS
script
runlevel --reboot || true
if grep -q -w -- "-s\|single\|S" /proc/cmdline; then
telinit S
elif [ -r /etc/inittab ]; then
RL="$(sed -n -e "/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab || true)"
if [ -n "$RL" ]; then
telinit $RL
else
telinit 2
fi
else
telinit 2
fi
end script
--------------------------------------------------------------------------------------------------------
分析/etc/event.d/rc2(rc2文件是定义在发生运行级别2的时候所要执行的东西):
--------------------------------------------------------------------------------------------------------
# rc2 - runlevel 2 compatibility
#
# This task runs the old sysv-rc runlevel 2 ("multi-user") scripts. It
# is usually started by the telinit compatibility wrapper.
start on runlevel 2 //发生运行级别2的时候所要执行的东西
stop on runlevel [!2]
console output
script
set $(runlevel --set 2 || true)
if [ "$1" != "unknown" ]; then
PREVLEVEL=$1
RUNLEVEL=$2
export PREVLEVEL RUNLEVEL
fi
exec /etc/init.d/rc 2 //执行/etc/init.d/rc 2
end script
------------------------------------------------------------------------------------------------------------
分析/etc/init.d/rc文件(/etc/init.d/中存放的是服务(services)或者任务(tasks)的执行脚本)
------------------------------------------------------------------------------------------------------------
# Now run the START scripts for this runlevel.
# Run all scripts with the same level in parallel
CURLEVEL=""
for s in /etc/rc$runlevel.d/S*
这说明,当给rc脚本传递一个数字参数"X"的时候,它在经过一系列的设置后,将会开始执行/etc/rcX.d/下S开头的脚本。这就过渡到下一个目录/etc/rcX.d/了。
进入/etc/rcX.d/,ls -l /etc/rcX.d/看看有些什么内容?哈哈,没错,都是一些到/etc/init.d/中脚本的符号链接。不同的是它们的开头加上了S和一个数字。
熟悉原本init的人应该知道,S表示在启动时运行,数字则表示执行的先后顺序。
接下来我们就可以分析:
/etc/rcS.d/S* , /etc/rc2.d/S*
看看这些脚本到底都做了些什么?
阅读(831) | 评论(0) | 转发(0) |