本篇全文出自:Ben 的 IT 學習之不歸路網誌
玩過redhat、fedora 系列的都知道/etc/inittab這個檔案,也是就使用SysvInit,不過fedora 9 後已改成Upstart了,沒事改它幹啥,不過純屬個人意見,發發牢騷。
UpStart 取代了 SysvInit 後也表示系統的 /sbin/init 檔案也一併被換掉了,當然init這個指令還是存在,只是已不是以前那個了;所以 /etc/inittab 檔案再也沒有實質性的功能,那原本 /etc/inittab 以前的那些設定去哪了呢?唉!相關配置都轉移放置於 /etc/event.d/ 目錄內。
來看看/etc/inittab裡有何變化
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/event.d/rcS (以前的si::sysinit:/etc/rc.d/rc.sysinit已被這個檔案所替代了)
#
# Individual runlevels are started by /etc/event.d/rc[0-6](以前的l0:0:wait:/etc/rc.d/rc 0、l1:1:wait:/etc/rc.d/rc 1等已被這六個檔案替代)
#
# Ctrl-Alt-Delete is handled by /etc/event.d/control-alt-delete(以前的ca::ctrlaltdel:/sbin/shutdown -t3 -r now已被這個檔案所替代了)
#
# Terminal gettys (tty[1-6]) are handled by /etc/event.d/tty[1-6] and (以前的1:2345:respawn:/sbin/mingetty tty1、2:2345:respawn:/sbin/mingetty tty2等已被這六個檔案替代)
# /etc/event.d/serial
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(8), initctl(8), and events(5).
#
# Default runlevel. The runlevels used 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: (只剩一行啦,看到initdefault就知道要改預設開機的runlevel還是要來這裡改)
接著我們在來看/etc/event.d/rcS:
# rcS - runlevel compatibility
#
# This task runs the old sysv-rc startup scripts.
start on startup (開機要執行)
stop on runlevel (關機不執行)
# Note: there can be no previous runlevel here, if we have one it's bad
# information (we enter rc1 not rcS for maintenance). Run /etc/rc.d/rc
# without information so that it defaults to previous=N runlevel=S.
console output (輸出訊息到標準輸出)
script (程式開始,注意裡頭有一個認識的老朋友/etc/rc.d/rc.sysinit,開機還是要靠它)
runlevel --set S >/dev/null || true
/etc/rc.d/rc.sysinit
runlevel --reboot || true
end script(程式結束)
post-stop script (在上一個程式結束後開始)
if [ "$UPSTART_EVENT" == "startup" ]; then (如果start on <event> 的值是startup就跑此段程式)
runlevel=$(/bin/awk -F ':' '$3 == "initdefault" { print $2 }' /etc/inittab) (讀出預設開機的 runlevel)
我們接續再看 /etc/event.d/control-alt-delete
[ -z "$runlevel" ] && runlevel="3" (如果$runlevel值字串長度是0,那就跑runlevel 3)
for t in $(cat /proc/cmdline); do (讀出開機時帶進核心的參數,檢查是否是單人操作模式)
case $t in
-s|single|S|s) runlevel="S" ;;
[1-9]) runlevel="$t" ;;
esac
done
exec telinit $runlevel (開機成指定的runlevel啦)
fi
end script
# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed. Usually used to shut down the machine.
start on control-alt-delete (開機要執行control-alt-delete)
exec /sbin/shutdown -r now "Control-Alt-Delete pressed" (立即重新開機並秀出Control-Alt-Delete pressed)
留言列表