参考网上许多的教程。

然后有一下相关的笔记:

kernel 在挂载完文件系统后,会执行第一个进程init

这个进程的PID为1

这个进程是所有进程的父进程

init 进程,首先要去读取inittab中的数据,根据这里面的数据去执行相关的初始化。

在inittab  可以指定默认的运行级别

  

id::initdefault:

还会规定第一个执行的程序

si::sysinit:/etc/init.d/rcS
//指定单用户模式
~~:S:wait:/sbin/sulogin

在TI的板子上还规定终端的显示的开关

::respawn:/sbin/getty  ttyO0

这里提到,他规定下一个执行的是/etc/init.d/rcS

在/etc/init.d/rcS 内又做了哪些工作呢?

PATH=/sbin:/bin:/usr/sbin:/usr/bin                                 //设置环境变量
runlevel=S //设置运行级别
prevlevel=N
umask //设置默认权限补码
export PATH runlevel prevlevel //对外发布这些变量
trap ":" INT QUIT TSTP
//这里话的含义是忽略ctrl + c中断信号
exec /etc/init.d/rc S    //运行/etc/init.d/rc    并加一个参数S

下面进入rc文件分析

 # rc        This file is responsible for starting/stopping
# services when the runlevel changes. //在文件一开始,就说明了这个文件是当运行级别改变就要更改相关的服务
//设置终端,将 CR 字符映射为 NL 字符,避免阶梯效应
stty onlcr >&
  # Get first argument. Set new runlevel to this argument.
[ "$1" != "" ] && runlevel=$
if [ "$runlevel" = "" ]
then
echo "Usage: $0 <runlevel>" >&
exit
fi
//如果没有获取到运行级别就退出
previous=$PREVLEVEL
[ "$previous" = "" ] && previous=N //传入参数是S的话,则$runleve=S $previous=N
export runlevel previous
//若$runlevel=“S”,即检查rcS.d是否为目录。
if [ -d /etc/rc$runlevel.d ]
then
//rcS.d是目录
PROGRESS_STATE= //Split the remaining portion of the progress bar into thirds
progress_size=$((( - $PROGRESS_STATE) / ))//progress_size = 100/3 =33 case "$runlevel" in//runlevel=S
|)
first_step=-
progress_size=
step_change=
;;
S)
//Begin where the initramfs left off and use 2/3of the remaining space
first_step=$PROGRESS_STATE ///progress_size = 100/3 =33
progress_size=$(($progress_size * ))//progress_size=66
step_change=
;;
*)
//Begin where rcS left off and use the final 1/3 ofthe space (by leaving progress_size unchanged)
first_step=$(($progress_size * + $PROGRESS_STATE))
step_change=
;;
esac
num_steps=
for s in /etc/rc$runlevel.d/[SK]*; //s取/etc/rcS.d目录下以S或K开头的文件名
do
//这句话的含义去掉变量s中所有的/etc/rcS.d/S??的部分
//例:s=/etc/rc$runlevel.d/S10checkroot,那么去掉/etc/rc$runlevel.d/K??部分后,s为checkroot
case "${s##/etc/rc$runlevel.d/S??}" in
gdm|xdm|kdm|reboot|halt)//若s剩下的文件名中为这五个则跳出for语句
break
;;
esac
num_steps=$(($num_steps + ))//num_steps递加,表示查找到此目录下/etc/rcS.d有多少个脚本
done//for语句结束
        step=
# First, run the KILL scripts. 首先运行KILL
if [ $previous != N ] //由于previous = N ,所以一下不执行
then
for i in /etc/rc$runlevel.d/K[-][-]*
do
# Check if the script is there.
[ ! -f $i ] && continue # Stop the service.
startup $i stop
done
fi
    # Now run the START scripts for this runlevel.
for i in /etc/rc$runlevel.d/S*
do
[ ! -f $i ] && continue if [ $previous != N ] && [ $previous != S ] //由于previous为N所以跳过
then
#
# Find start script in previous runlevel and
# stop script in this runlevel.
#
suffix=${i#/etc/rc$runlevel.d/S[-][-]}
stop=/etc/rc$runlevel.d/K[-][-]$suffix
previous_start=/etc/rc$previous.d/S[-][-]$suffix
#
# If there is a start script in the previous level
# and _no_ stop script in this level, we don't
# have to re-start the service.
#
[ -f $previous_start ] && [ ! -f $stop ] && continue
fi
case "$runlevel" in
|)
startup $i stop
;;
*)
startup $i start //然后启动了相关的服务 运行在文件前面定义的 startup 函数
;;
esac
done
fi

startup函数有如下定义:

#
# Start script or program.
#
startup() {
# Handle verbosity
[ "$VERBOSE" = very ] && echo "INIT: Running $@..." case "$1" in //判断第一个参数,如果是一个脚本,执行第一个
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
scriptname=$
shift //shift 命令每执行一次,变量的个数($#)减一,而变 量值提前一位
. $scriptname //在执行第一个参数
)
;;
*) //如果不是一个脚本,那么认为是一个服务
"$@"
;;
esac
startup_progress //再运行前一个函数
}

startup_progress 函数详解

startup_progress() {
step=$(($step + $step_change))
if [ "$num_steps" != "" ]; then
progress=$((($step * $progress_size / $num_steps) + $first_step))
else
progress=$progress_size
fi
#echo "PROGRESS is $progress $runlevel $first_step + ($step of $num_steps) $step_change $progress_size"
#if type psplash-write >/dev/null 2>&1; then
# TMPDIR=/mnt/.psplash psplash-write "PROGRESS $progress" || true
#fi
if [ -e /mnt/.psplash/psplash_fifo ]; then
echo "PROGRESS $progress" > /mnt/.psplash/psplash_fifo
fi
echo progress over...
}

最后,执行qt.sh

#Uncomment to cause psplash to exit manually, otherwise it exits when it sees a VC switch
if [ "x$runlevel" != "xS" ] && [ ! -x /etc/init.d/xserver-nodm ]; then
. /etc/init.d/qt.sh
# if type psplash-write >/dev/null >&; then
# TMPDIR=/mnt/.psplash psplash-write "QUIT" || true
# umount /mnt/.psplash
# fi
fi

参考:

http://www.cnblogs.com/cnland/archive/2013/03/26/2981967.html

https://wiki.archlinux.org/index.php/Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)#Init_.E6.B5.81.E7.A8.8B

http://blog.chinaunix.net/uid-17188120-id-4073497.html

linux 文件系统sysvinit 流程分析的更多相关文章

  1. Linux文件系统与日志分析

    Linux文件系统与日志分析一.inode与block概述① 文件数据包括元信息(类似文件属性)与实际数据② 文件存储在硬盘上,硬盘最小存储单位是"扇区"(sector),每个扇区 ...

  2. Linux文件系统与日志分析的了解

    Linux文件系统与日志分析 1.inode和block概述 2.模拟inode耗尽实验 3.ext类型文件恢复 4.xfs类型文件恢复 5.日志文件 6.日志分析 1.文件:文件是存储在硬盘上的,硬 ...

  3. linux文件系统和日志分析

    一.Linux文件系统 1.inode与block 1.概述: (1)文件数据包括元信息与实际信息 (2)文件存储在硬盘上,硬盘最小存储单位是"扇区",每个扇区存储512字节 (3 ...

  4. Linux学习-Linux 的开机流程分析

    开机流程一览 系统开机的经过可以汇整成底下的流程的: 加载 BIOS 的硬件信息与进行自我测试,并依据设定取得第一个可开机的装置; 读取并执行第一个开机装置内 MBR 的 boot Loader (亦 ...

  5. linux 内核启动流程分析,移植

    分析 linux-2.6.22.6 内核启动流程 移植 linux-3.4.2 到 JZ2440 开发板 Linux内核源码百度云链接: https://pan.baidu.com/s/1m1ymGl ...

  6. Linux NAPI处理流程分析

    2017-05-10 今天重点对linux网络数据包的处理做下分析,但是并不关系到上层协议,仅仅到链路层. 之前转载过一篇文章,对NAPI做了比较详尽的分析,本文结合Linux内核源代码,对当前网络数 ...

  7. 深入理解Linux文件系统与日志分析

    一.inode和bolck概述 二.链接文件 三.inode节点耗尽故障处理 四.EXT类型文件恢复 五.xfs文件备份和恢复 六.日志文件 一.inode和bolck概述 1.定义 文件数据 文件数 ...

  8. Linux内核启动流程分析(二)【转】

    转自:http://blog.chinaunix.net/uid-25909619-id-3380544.html S3C2410 Linux 2.6.35.7启动分析(第二阶段) 接着上面的分析,第 ...

  9. Linux内核启动流程分析(一)【转】

    转自:http://blog.chinaunix.net/uid-25909619-id-3380535.html 很久以前分析的,一直在电脑的一个角落,今天发现贴出来和大家分享下.由于是word直接 ...

随机推荐

  1. e_msg_c_as_register_req-注册存储过程

    TOP:BEGIN #Routine body goes here... IF EXISTS ( SELECT * FROM `global_account` WHERE `plantform_id` ...

  2. MySQL数据库常用函数

    一.数学函数 数学函数主要用于处理数字,包括整型.浮点数等. ABS(x) 返回x的绝对值 不区分大小写 SELECT ABS(-1) -- 返回1 CEIL(x),CEILING(x) 返回大于或等 ...

  3. JavaWeb学习笔记——jsp基础语法

    1.JSP注释 显式注释 <!-- 注释内容 --> 隐式注释,隐式注释在客户端无法看见 // /* */ <% 注释内容 %> 2.Scriptlet(小脚本程序) 所有嵌入 ...

  4. 仿照jquery封装一个自己的js库(一)

    所谓造轮子的好处就是复习知识点,加深对原版jquery的理解. 本文系笔者学习jquery的笔记,记述一个名为"dQuery"的初级版和缩水版jquery库的实现.主要涉及知识点包 ...

  5. Sublime Text 3065

    Package Control安装 安装方法:https://packagecontrol.io/installation 用Package Control安装插件 1.按下Ctrl+Shift+P调 ...

  6. eshop截取字符串长度 和去掉省略号

    <!-- {if $goods.goods_brief} --> {$goods.goods_brief|truncate:17}<!-- {/if} --> 去掉省略号: 找 ...

  7. php构造函数extends

    extends的继续关系 page继承Dapta:也就是page拥有data的所有功能. <?php class Data{ function f(){ "; } } class Pa ...

  8. vertical-align0 垂直对齐- 图片 兼容个浏览器

    效果:  代码: <html> <head> <style type="text/css"> img.top {vertical-align:t ...

  9. System.out.println与System.err.println的区别(输出顺序!!!)

    System.out.println与System.err.println的区别(输出顺序!!!) 分类:java (208)  (0) System.out.println与System.err.p ...

  10. Linux 脚本 sh 和 ./ 的区别

    如果.不在PATH里面,要执行当前目录下的可执行文件,使用全路径:./executable-file PATH是环境变量,如果将当前目录“./”添加到环境变量中,那么也可以不用“./”,直接输入当前目 ...