linux系统命令_Chapter_启动流程

——————–Chapter 系统登录————-

以Ubutun为例

参考网址: http://www.cnblogs.com/cassvin/archive/2011/12/25/ubuntu_init_analysis.html

1.以终端模式登录

进入中断命令模式:Ctrl+Alt+FX(0~6)

进入图形界面: Ctrl+Alt+f7进入图形界面

note:可以修改/etc/issue文件 添加打印信息

/etc/issue.sh
Ubuntu 14.04.5 LTS \n \l
-----------------------------------
-          Hello Leo              -
-       Have  a  Nice  Day       -
-                                -
-      :)                      (:-
-                                -
-----------------------------------

2.简单命令

date

study@ubuntu:~$ date
Tue May 23 09:19:27 CST 2017

ls
-a显示隐藏目录

-l显示全部信息

-h以方便阅读的方式查看文件信息

study@ubuntu:/$ ls
bin    hfs-workstation  lib32       mnt      run       tmp
boot   home             lib64       nfsroot  sbin      usr
cdrom  initrd.img       libx32      opt      srv       var
dev    initrd.img.old   lost+found  proc     sys       vmlinuz
etc    lib              media       root     tftpboot  vmlinuz.old

cat 查看文件内容

study@ubuntu:/home/Leo$ cat /etc/issue
Ubuntu 14.04.5 LTS \n \l
-----------------------------------
-         Hello Leo               -
-      Have  a  Nice  Day         -
-                                 -
-  :)                       (:    -   
-                                 -
-----------------------------------

3.启动流程

Ubuntu————init分析

Linux前面的启动流程总有inittab的身影,但是现在的Ubunt找不到了,因为现在的采用的是UpStart方式启动下面分别介绍两张启动方式

3.1 Sysytem v initialization,来源于Unix采用广泛,采用的是串行的方式

3.2现在采用的是 Upstart(Ubuntun),保留了前面的init特性,比如进程名仍然为init,但是核心编程了Event事件,可以使多个系统任务在保持依赖关系的前提下并发启动。

在前面的System v initialization中,init进程启动后第一时间要找到inittab设置runlevel及各种runlevel要执行的命令;但是在Upsatrt中系统服务如何知道自己什么时候应该启动和终止那?Ubuntun在/etc/init/.conf中(有的在/etc/event.d),Ubuntun中通过/etc/init/.conf一系列配置文件来指定各种系统服务的依赖关系,在Upstart的主进程/sbin/init会解析这些文件,按照彼此间的依赖关系并发的执行,每个服务的conf配置文件通常指明了执行依赖的事件(信号)、执行的环境、执行的任务属性、执行的任务内容等

//Upstart init处理System V-style服务的关键
rc.conf  rc在系统runlevel变化时被启动
rc-sysinit.conf  rc-sysinit在startup事件发生时被启动
rcS.conf rcS在系统runlevel为S时启动

eval:  命令将会首先扫描命令行进行所有的替换,然后再执行命令。该命令使用于那些一次扫描无法实现其功能的变量。该命令对变量进行两次扫描。这些需要进行两次扫描的变量有时候被称为复杂变量。


//      /etc/init/rc-sysinit.conf
env RUNLEVEL=
env PREVLEVEL=

console output
env INIT_VERBOSE

task

    script
# Check for default runlevel in /etc/inittab 查看inittab是否存在
if [ -r /etc/inittab ]
then
    eval "$(sed -nre 's/^[^#][^:]*:([0-6sS]):initdefault:.*/DEFAULT_RUNLEVEL="\1";/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 系统初始化脚本 /etc/init.d/rcS
[ -n "${FROM_SINGLE_USER_MODE}" ] || /etc/init.d/rcS

# Switch into the default runlevel
telinit "${DEFAULT_RUNLEVEL}"  //切换运行级别,猜测是不是发起了一个事件
end script

/etc/init/rc.conf  在上面那个脚本中telinit切换了级别,这里就会执行  
description "System V runlevel compatibility"
author  "Scott James Remnant <scott@netsplit.com>"

emits deconfiguring-networking
emits unmounted-remote-filesystems

start on runlevel [0123456] #不管那个级别都运行吗?
stop on runlevel [!$RUNLEVEL]

export RUNLEVEL
export PREVLEVEL

console output
env INIT_VERBOSE

task

script #[016关机 , 单用户 ,重启]
if [ "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" -o "$RUNLEVEL" = "6" ]; then
 status plymouth-shutdown 2>/dev/null >/dev/null && start wait-for-state WAITER=rc WAIT_FOR=plymouth-shutdown || :
fi
/etc/init.d/rc $RUNLEVEL    #这个脚本根据传入的级别参数调用/etc/rc${runlevel}.d/下的脚本(以S开头)以启动服务,终止前面那一次需要终止的服务
#System V initialization中,etc/init.d/rc $RUNLEVEL     /etc/inittab中的各runlevel对应的命令行就是通过这种形式设置的。
end script

/etc/init.d/rc $RUNLEVEL 才开始进行一系列的初始化

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值