#rc--run command的意思【rc解释
harvey@ubuntu:/etc$ cat ./init/rc-sysinit.conf
# rc-sysinit - System V initialisation compatibility
#
# This task runs the old System V-style system initialisation scripts,
# and enters the default runlevel when finished.
#选定系统的启动级别,还没有真正进入系统启动阶段
description "System V initialisation compatibility"
author "Scott James Remnant <scott@netsplit.com>" start on (filesystem and static-network-up) or failsafe-boot
stop on runlevel # Default runlevel, this may be overriden on the kernel command-line
# or by faking an old /etc/inittab entry
#设置默认的启动级别为2,但是当有inittab文件和内核命令行的时候默认值会被改变
env DEFAULT_RUNLEVEL= emits runlevel # There can be no previous runlevel here, but there might be old
# information in /var/run/utmp that we pick up, and we don't want
# that.
#
# These override that
#防止/var/run/utmp下面旧的启动信息干扰,把信息置空
env RUNLEVEL=
env PREVLEVEL= console output
env INIT_VERBOSE task
#如果存在inittab文件就按照inittab的要求计算默认DEFAULTLEVEL
script
# Check for default runlevel in /etc/inittab
if [ -r /etc/inittab ]
then
eval "$(sed -nre 's/^[^#][^:]*:([0-6sS]):initdefault:.*/DEFAULT_RUNLEVEL="\";/p' /etc/inittab || true)"
fi # Check kernel command-line for typical arguments
for ARG in $(cat /proc/cmdline)
do
case "${ARG}" in
-b|emergency)
# Emergency shell
[ -n "${FROM_SINGLE_USER_MODE}" ] || sulogin
;;
[0123456sS])
# Override runlevel
DEFAULT_RUNLEVEL="${ARG}"
;;
-s|single)
# Single user mode
[ -n "${FROM_SINGLE_USER_MODE}" ] || DEFAULT_RUNLEVEL=S
;;
esac
done # Run the system initialisation scripts
#执行系统内核脚本改变DEFAULTLEVEL的值
[ -n "${FROM_SINGLE_USER_MODE}" ] || /etc/init.d/rcS # Switch into the default runlevel
#开放根据选定的level启动系统
telinit "${DEFAULT_RUNLEVEL}" #执行telinit命令
end script

在ubuntu下init 和telinit都是二进制命令:

harvey@ubuntu:/etc$ ll /sbin/init /sbin/telinit
-rwxr-xr-x root root 1月 /sbin/init*
-rwxr-xr-x root root 1月 /sbin/telinit*

ubuntu启动流程:

Ubuntu的upstart init文件→→进入/etc/init文件夹下选择进入的level值→→进入/etc/rc{level}.d文件夹,根据文件夹内的软连接的名字判断执行方式→→实际进入/etc/init.d文件夹执行命令

 harvey@ubuntu:/etc/rc2.d$ ll #rc2.d 文件夹下都是链接到init.d文件夹中的软连接,软连接以S开头表示启动服务K开头的表示停止,rc{level}.d文件夹类似于windows的启动文件夹,windows中放入启动文件夹中的程序会被启动
总用量
drwxr-xr-x root root 3月 : ./
drwxr-xr-x root root 3月 ../
-rw-r--r-- root root 7月 README
lrwxrwxrwx root root 3月 : S20kerneloops -> ../init.d/kerneloops*
#exec="/usr/sbin/kerneloops"执行该程序,并把pid保存在/var/run/$prog.pid使用的conf是/etc/kerneloops.conf文件【证明usr放的是程序代码,var防止运行时信息】
lrwxrwxrwx root root 3月 : S20speech-dispatcher -> ../init.d/speech-dispatcher*
#服务程序位置daemon="/usr/bin/speech-dispatcher" 进程文件信息PIDFILE=/var/run/speech-dispatcher/speech-dispatcher.pid 进程所属用户user='speech-dispatcher'
lrwxrwxrwx root root 3月 : S21sendmail -> ../init.d/sendmail*
#服务程序位置/usr/sbin/sendmail 脚本文件位置 /etc/init.d/sendmail
lrwxrwxrwx root root 3月 : S35whereami -> ../init.d/whereami*
#strat whereami
lrwxrwxrwx root root 3月 : S50pulseaudio -> ../init.d/pulseaudio*
#服务程序位置/usr/bin/pulseaudio PID文件位置/var/run/pulse
lrwxrwxrwx root root 3月 : S50rsync -> ../init.d/rsync*
#服务位置/usr/bin/rsync
lrwxrwxrwx root root 3月 : S50saned -> ../init.d/saned*
#daemon服务的位置 /usr/sbin/saned
lrwxrwxrwx root root 3月 : S70dns-clean -> ../init.d/dns-clean*
lrwxrwxrwx root root 3月 : S70pppd-dns -> ../init.d/pppd-dns*
lrwxrwxrwx root root 3月 : S75sudo -> ../init.d/sudo*
lrwxrwxrwx root root 3月 : S99acpi-support -> ../init.d/acpi-support*
lrwxrwxrwx root root 3月 : S99grub-common -> ../init.d/grub-common*
lrwxrwxrwx root root 3月 : S99ondemand -> ../init.d/ondemand*
lrwxrwxrwx root root 3月 : S99rc.local -> ../init.d/rc.local* #

ubuntu用runlevel查看当前运行的级别,用sudo init {num}来切换工作的level。level0 表示关键 level6表示重启动 level2是默认级别

harvey@ubuntu:~$ runlevel  #查看当前工作level
N
harvey@ubuntu:~$ sudo init #shutdown和reboot就是切换的runleve

参考资料:ubuntu为什么没有/etc/inittab文件? 深究ubuntu的启动流程分析

ubuntu启动脚本一览分析的更多相关文章

  1. ubuntu启动脚本

    下午分析了一下mysql的启动脚本,找到这篇,记录一下,目前很多服务都是以这种方式封装,后面自己写来借鉴一下 http://blog.fens.me/linux-upstart/

  2. HBase配置&启动脚本分析

    本文档基于hbase-0.96.1.1-cdh5.0.2,对HBase配置&启动脚本进行分析 date:2016/8/4 author:wangxl HBase配置&启动脚本分析 剔除 ...

  3. Spark配置&启动脚本分析

    本文档基于Spark2.0,对spark启动脚本进行分析. date:2016/8/3 author:wangxl Spark配置&启动脚本分析 我们主要关注3类文件,配置文件,启动脚本文件以 ...

  4. linux系统 initrd.img中init启动脚本分析

    概述:这篇文章主体内容来源于网上转载.前面几篇文章倾向于制作initrd.img,这篇文章更倾向于initrd.img的运行过程:加载framebuff驱动 ide驱动和文件系统驱动,最后进入到真正的 ...

  5. busybox rootfs 启动脚本分析(二)

    上次分析了busybox的启动脚本,这次分析一下init.d中一些脚本的内容. 参考链接 http://www.cnblogs.com/helloworldtoyou/p/6169678.html h ...

  6. [Tomcat 源码分析系列] (二) : Tomcat 启动脚本-catalina.bat

    概述 Tomcat 的三个最重要的启动脚本: startup.bat catalina.bat setclasspath.bat 上一篇咱们分析了 startup.bat 脚本 这一篇咱们来分析 ca ...

  7. [Tomcat 源码分析系列] (一) : Tomcat 启动脚本-startup.bat

    概述 我们通常使用 Tomcat 中的 startup.bat 来启动 Tomcat. 但是这其中干了一些什么事呢? 大家都知道一个 Java 程序需要启动的话, 肯定需要 main 方法, 那么这个 ...

  8. 关于Ubuntu运行级别、开机启动脚本的说明

    关于Ubuntu运行级别.开机启动脚本的说明 目录简介 1.1介绍Ubuntu下面的自启动脚本目录 1.2 Linux操作系统运行级别的概念 1.3关于操作系统自启脚本的启动顺序 1.4    Lin ...

  9. 老李推荐:第5章3节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 启动脚本

    老李推荐:第5章3节<MonkeyRunner源码剖析>Monkey原理分析-启动运行: 启动脚本   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性 ...

随机推荐

  1. HDFS HA(High Availability)高可用性

    HDFS HA(High Availability)高可用性 参考文献: 官方文档 全文翻译 Hadoop组件之-HDFS(HA实现细节) 这张图片的个人理解 由于NameNode在Hadoop1只有 ...

  2. PHP.33-TP框架商城应用实例-后台9-商品相册-修改、删除(AJAX)

    商品相册图片删除 当商品删除时,把相册中的图片一并从硬盘和数据库中删除,根据商品id[因为每一张商品相片都会生成三张缩略图,所以删除时要将其缩略图一并删除] //钩子方法_before_delete: ...

  3. 十、mysql之索引原理与慢查询优化

    mysql之索引原理与慢查询优化 一.介绍 1.什么是索引? 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,在生产环境中,我们遇到最多的,也是最容易出问题的,还 ...

  4. 02,Python网络爬虫第二弹《http和https协议》

    一.HTTP协议 1.官方概念: HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文 ...

  5. PCB工艺要求

    项目 加工能力 工艺详解   层数 1~6层 层数,是指PCB中的电气层数(敷铜层数).目前嘉立创只接受1~6层板.   板材类型 FR-4板材 板材类型:纸板.半玻纤.全玻纤(FR-4).铝基板,目 ...

  6. Java语言基础---变量与数据类型

    变量的作用域 java用一对大括号“{}”作为语句块的范围,称为作用域.作用域中的变量不能重复定义:离开作用域,变量所分配的内存空间将被JVM所收回. 基本数据类型的包装类 java为基础数据类型提供 ...

  7. [网站公告]1月10日1:00-7:00阿里云RDS维护会造成30秒闪断

    大家好! 阿里云将于1月10号1:00-7:00(今天夜里)对杭州机房部分RDS实例所在的物理主机做维护操作,维护期间部分RDS实例会有1-2次闪断,每次闪断时间在30秒以内. 我们使用的RDS实例将 ...

  8. .gitignore 中文文件夹无效

    有个文件夹名如:测试 在.gitignore中添加  /测试/   但运行命令git status后发现还是被追踪到了 一番搜索后终于发现.gitignore文件编码是GBK的,重新将文件保存成utf ...

  9. Linux查看端口被占用情形

    查看某端口的占用情况: lsof -i:<端口号> 例如:lsof -i:8080 netstat -apn|grep <端口号> 例如: netstat -apn | gre ...

  10. HDU 4714 Tree2cycle 找规律

    假设最少删除的边的个数为cost,显然,最终答案即为cost+cost+1 (因为删除一条边,就会增加一个链,所以删除cost条边后,就会有cost+1条链,将这cost+1条链连接起来的代价为cos ...