RHEL5、RHEL6、RHEL7的init系统分别为sysvinit、upstart、systemd。
CentOS6.5是根据RHEL6.5源码编译的,两者差别非常小。它也用upstart。
证据:
[root@www ~]# rpm -qf /sbin/init
upstart-0.6.5-13.el6_5.3.x86_64
upstart把原本在/etc/inittab中的rc.sysinit, rc.d等配置拆分,放在/etc/init目录下。/etc/inittab中只能控制启动级别。
系统内核加载完成后,开始执行第一个进程init。init会执行一个脚本:
/etc/init/rcS.conf
内容是这样:
[root@www init]# cat -n rcS.conf
1 # rcS - runlevel compatibility
2 #
3 # This task runs the old sysv-rc startup scripts.
4 #
5 # Do not edit this file directly. If you want to change the behaviour,
6 # please create a file rcS.override and put your changes there.
7
8 start on startup
9
10 stop on runlevel
11
12 task
13
14 # Note: there can be no previous runlevel here, if we have one it's bad
15 # information (we enter rc1 not rcS for maintenance). Run /etc/rc.d/rc
16 # without information so that it defaults to previous=N runlevel=S.
17 console output
18 pre-start script
19 for t in $(cat /proc/cmdline); do
20 case $t in
21 emergency)
22 start rcS-emergency
23 break
24 ;;
25 esac
26 done
27 end script
28 exec /etc/rc.d/rc.sysinit
29 post-stop script
30 if [ "$UPSTART_EVENTS" = "startup" ]; then
31 [ -f /etc/inittab ] && runlevel=$(/bin/awk -F ':' '$3 == "initdefault" && $1 !~ "^#" { print $2 }' /etc/inittab)
32 [ -z "$runlevel" ] && runlevel="3"
33 for t in $(cat /proc/cmdline); do
34 case $t in
35 -s|single|S|s) runlevel="S" ;;
36 [1-9]) runlevel="$t" ;;
37 esac
38 done
39 exec telinit $runlevel
40 fi
41 end script
比较重要的是30-32行:
30 if [ "$UPSTART_EVENTS" = "startup" ]; then
31 [ -f /etc/inittab ] && runlevel=$(/bin/awk -F ':' '$3 == "initdefault" && $1 !~ "^#" { print $2 }' /etc/inittab)
32 [ -z "$runlevel" ] && runlevel="3"
30行:如果 EVENT是“startup”就执行后面的内容。
31行:/bin/awk -F ‘:’ ‘3 == “initdefault” && 1 !~ “^#” { print $2 }’ /etc/inittab的意思是:以“:作为字段分隔符,”找出/etc/inittab里面第三个字段是initdefault,并且不是以“#”开头的行(#开头一般为注释),然后提取出第二个字段。
连起来就是:如果存在/etc/inittab 这个文件,runlevel的值就取刚才提取的字符串。
32行:如果现在runlevel为空,就让runlevel取值“3”。
所以删掉inittab 最后运行级别就是3