S20nfs-kernel-server S20samba S20xinetd S30gdm S98usplash S99rc.local 總結: 這樣一來,upstart管理的ubuntu啟動過程應該就清楚了。梳理一下: 1,內核啟動init 2,init找到/etc/event.d/rc-default文件,確定默認的運行級別(X) 3,觸發(fā)相應的runlevel事件,開始運行/etc/event.d/rcX 4,rcX運行/etc/init.d/rc,傳入參數X 5,/etc/init.d/rc腳本進行一系列設置,最后運行相應的/etc/rcX.d/中的腳本 6,/etc/rcX.d/中的腳本按事先設定的優(yōu)先級依次啟動,直至最后給出登錄畫面(啟動X服務器和GDM) 理解了這些,手動配置開機服務的啟動與否就很簡單了。Ubutnu默認的啟動級別是2,不想啟動的程序,只要把相應的符號鏈接從/etc/rc2.d/中刪去即可 注意: 想redat ,federa 這些系統(tǒng),他們用的是sysvinit ,有 /etc/inittab 文件,里面定義了 : id:5:initdefault: si::sysinit:/etc/init.d/rcS init 直接解析 id:5:initdefault 字段,然后執(zhí)行 /etc/rc5.d/ 下面的腳本 ================ 參考文檔: linux教程:upstart 和ubuntu啟動過程原理介紹 http://www.zhiweinet.com/jiaocheng/2009-06/12500.htm 6.2 小型嵌入式系統(tǒng)啟動流程 小型嵌入式的 init 通常使用busybox中自帶的, 6.3 android 系統(tǒng)啟動流程 參考文檔: init 是內核進入文件系統(tǒng)后第一個運行的程序,我們可以在linux的命令行中進行指定,如果沒指定,內核將會到/sbin/, /bin/ 等目錄下 查找默認的init,如果沒有找到那么就報告出錯。 init 源代碼分析 init的mian函數在文件:./system/core/init/init.c 中,init會一步步完成下面的任務: 1.初始化log系統(tǒng) 2.解析/init.rc和/init.%hardware%.rc文件 3. 執(zhí)行 early-init action in the two files parsed in step 2. 4. 設備初始化,例如:在 /dev 下面創(chuàng)建所有設備節(jié)點,下載 firmwares. 5. 初始化屬性服務器,Actually the property system is working as a share memory. Logically it looks like a registry under Windows system. 6. 執(zhí)行 init action in the two files parsed in step 2. 7. 開啟 屬性服務。 8. 執(zhí)行 early-boot and boot actions in the two files parsed in step 2. 9. 執(zhí)行 Execute property action in the two files parsed in step 2. 10. 進入一個無限循環(huán) to wait for device/property set/child process exit events.例如,如果SD卡被插入,init會收到一個設備插入事件, 它會為這個設備創(chuàng)建節(jié)點。系統(tǒng)中比較重要的進程都是由init來fork的,所以如果他們他誰崩潰了,那么init 將會收到一個 SIGCHLD 信號,把這個信號轉化 為子進程退出事件, 所以在loop中,init 會操作進程退出事件并且執(zhí)行 *.rc 文件中定義的命令。 例如,在init.rc中,因為有: service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server socket zygote stream 666 onrestart write /sys/android_power/request_state wake onrestart write /sys/power/state on 所以,如果zygote因為啟動某些服務導致異常退出后,init將會重新去啟動它。 int main(int argc, char **argv) { ... //需要在后面的程序中看打印信息的話,需要屏蔽open_devnull_stdio()函數 open_devnull_stdio(); ... //初始化log系統(tǒng) log_init(); //解析/init.rc和/init.%hardware%.rc文件 parse_config_file("/init.rc"); ... snprintf(tmp, sizeof(tmp), "/init.%s.rc", hardware); parse_config_file(tmp); ... //執(zhí)行 early-init action in the two files parsed in step 2. action_for_each_trigger("early-init", action_add_queue_tail); drain_action_queue(); ... /* execute all the boot actions to get us started */ /* 執(zhí)行 init action in the two files parsed in step 2 */ action_for_each_trigger("init", action_add_queue_tail); drain_action_queue(); ... /* 執(zhí)行 early-boot and boot actions in the two files parsed in step 2 */ action_for_each_trigger("early-boot", action_add_queue_tail); action_for_each_trigger("boot", action_add_queue_tail); drain_action_queue(); /* run all property triggers based on current state of the properties */ queue_all_property_triggers(); drain_action_queue(); /* enable property triggers */ property_triggers_enabled = 1; ... for(;;) { int nr, timeout = -1; ... drain_action_queue(); restart_processes(); if (process_needs_restart) { timeout = (process_needs_restart - gettime()) * 1000; if (timeout