S20nfs-kernel-server S20samba S20xinetd S30gdm S98usplash S99rc.local 总结: 这样一来,upstart管理的ubuntu启动过程应该就清楚了。梳理一下: 1,内核启动init 2,init找到/etc/event.d/rc-default文件,确定默认的运行级别(X) 3,触发相应的runlevel事件,开始运行/etc/event.d/rcX 4,rcX运行/etc/init.d/rc,传入参数X 5,/etc/init.d/rc脚本进行一系列设置,最后运行相应的/etc/rcX.d/中的脚本 6,/etc/rcX.d/中的脚本按事先设定的优先级依次启动,直至最后给出登录画面(启动X服务器和GDM) 理解了这些,手动配置开机服务的启动与否就很简单了。Ubutnu默认的启动级别是2,不想启动的程序,只要把相应的符号链接从/etc/rc2.d/中删去即可 注意: 想redat ,federa 这些系统,他们用的是sysvinit ,有 /etc/inittab 文件,里面定义了 : id:5:initdefault: si::sysinit:/etc/init.d/rcS init 直接解析 id:5:initdefault 字段,然后执行 /etc/rc5.d/ 下面的脚本 ================ 参考文档: linux教程:upstart 和ubuntu启动过程原理介绍 http://www.zhiweinet.com/jiaocheng/2009-06/12500.htm 6.2 小型嵌入式系统启动流程 小型嵌入式的 init 通常使用busybox中自带的, 6.3 android 系统启动流程 参考文档: init 是内核进入文件系统后第一个运行的程序,我们可以在linux的命令行中进行指定,如果没指定,内核将会到/sbin/, /bin/ 等目录下 查找默认的init,如果没有找到那么就报告出错。 init 源代码分析 init的mian函数在文件:./system/core/init/init.c 中,init会一步步完成下面的任务: 1.初始化log系统 2.解析/init.rc和/init.%hardware%.rc文件 3. 执行 early-init action in the two files parsed in step 2. 4. 设备初始化,例如:在 /dev 下面创建所有设备节点,下载 firmwares. 5. 初始化属性服务器,Actually the property system is working as a share memory. Logically it looks like a registry under Windows system. 6. 执行 init action in the two files parsed in step 2. 7. 开启 属性服务。 8. 执行 early-boot and boot actions in the two files parsed in step 2. 9. 执行 Execute property action in the two files parsed in step 2. 10. 进入一个无限循环 to wait for device/property set/child process exit events.例如,如果SD卡被插入,init会收到一个设备插入事件, 它会为这个设备创建节点。系统中比较重要的进程都是由init来fork的,所以如果他们他谁崩溃了,那么init 将会收到一个 SIGCHLD 信号,把这个信号转化 为子进程退出事件, 所以在loop中,init 会操作进程退出事件并且执行 *.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系统 log_init(); //解析/init.rc和/init.%hardware%.rc文件 parse_config_file("/init.rc"); ... snprintf(tmp, sizeof(tmp), "/init.%s.rc", hardware); parse_config_file(tmp); ... //执行 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 */ /* 执行 init action in the two files parsed in step 2 */ action_for_each_trigger("init", action_add_queue_tail); drain_action_queue(); ... /* 执行 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