一、Linux内核的组成














相关概念:
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp;Linux系统的组成部分:内核+根文件系统
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp;内核:进程管理、内存管理、网络协议栈、文件系统、驱动程序。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp;IPC(Inter-Process Communication进程间通信):就是指多个进程之间相互通信,交换信息的方法。Linux IPC基本上都是从Unix平台上继承而来的。主要包括最初的Unix IPC,System V IPC以及基于Socket的IPC。另外,Linux也支持POSIX IPC。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            运行中的系统环境可分为两层:内核空间、用户空间;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            内核空间:内核代码(系统调用)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            用户空间:应用程序(进程或线程)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            内核设计流派:
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            单内核设计:把所有的功能集成于同一个程序;(Linux)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            微内核设计:每种功能都使用一个单独的子系统实现;(Windows solarls)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;Linux内核特点:
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (1)支持模块化:.KO(kernel object)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (2)支持模块运动时动态装载或卸载
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            组成部分:
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            核心文件:/boot/Vmliuz-VERSION-release&nbsp; &nbsp; &nbsp;&nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;ramdirk:
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;CentOS5:/boot/initrd-VERSION-release.img
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;CentOS6,7:/boot/initramfs-VERSION-release.img
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>
    </section>
</section>












二、CentOS系统启动流程

















总体启动顺序:
                    <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
                        POST(加点自检)--&gt;Boot Sequence(BIOS:基本输入输出系统)--&gt;Boot Loader(MBR:主引导记录)--&gt;Kernel(ramdisk)--&gt;rootfs(根文件系统)--&gt;switchchroot--&gt;/sbin/init/(/etc/inittab /etc/init/*.conf)--&gt;设定运行级别--&gt;系统初始化脚本--&gt;关闭启动相应服务--&gt;启动终端&nbsp;
                    </section>
                </section>
            </section>
        </section>
    </section>
</section>





 
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            总流程图:
        </section>
    </section>
</section>






 
    <section style="margin: 0px; padding: 0px 0px 0px 5px; font-size: 19.2px; vertical-align: middle; display: inline-block; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            各流程细化说明:&nbsp;
        </section>
    </section>
</section>





1、POST加电自检  
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            主要是检测硬件设别是否能正常的运行,然而实现自检功能主要是由镶嵌在主板芯片(CMOS)上的BIOS(basic input output system)程序,检测没问题之后进行硬件设备的初始化。 &nbsp;&nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **2、Boot Sequence(启动管理程序):选择启动顺序加载MBR**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            Boot Sequence是一个程序,它依赖于某个硬盘硬件,准确的说是第一个硬盘扇区的MBR,从而按次序查找各引导设备。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **3、MBR引导,bootloader引导加载器,启动程序 &nbsp;&nbsp;**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            MBR(Master Boot Record):此记录在0磁道1扇区,总共为512字节,前446字节为bootloder,后64字节为分区表信息,主分区加上扩展分区不能大于四个,最后2个字节为校验信息,为55AA。提供一个菜单,允许用户选择要启动的系统或不同的内核版本;把用户选定的内核装载到RAM中的特定空间中,解压、展开,而后把系统控制权移交给内核。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **4、kernel内核实现 &nbsp;**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            kernel自身初始化,实现功能,借助ramdisk探测可识别的程序,以自读方式挂载根文件系统,运行应用程序:/sbin/init
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp;&nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **5、/sbin/init/管理用户空间服务进程 &nbsp; &nbsp;&nbsp;**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            设定运行级别,进行初始化脚本,关闭或启动相应的程序,启动终端。 &nbsp;
        </section>
    </section>
</section>


 




 
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            GRUB(GRand Unified Bootloader)加载内核,就是MBR中的前 446 个字节,是BooTLoader的一种,它的作用是要选择要启动的内核。 &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            GRUB相关说明:&nbsp;
        </section>
    </section>
</section>









主要是由device.map,menulst,stage1,stage2,以及一系列的stage1_5组成。
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            device.map:存放的是内核文件的根分区
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            menu.lis:为菜单列表,里面为可选择的菜单列表,存放于stage2中。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            stage:用于grub引导程序过大,所以分2段引导,第一段存放在MBR中,第二段存放于内核文件系统中,第一段引导完成后可以找到第二段。 但是,第二段是存放于内核文件系统中的,此时还没有格式化文件系统,如何可以访问到第二段的menu.lst,就需要借助于中间层 stage1_5,有它来协助 stage1 段来访问stage2阶段。stage1_5通常位于stage1 字段后的 63 个扇区。 由于stage2 在内存中存放可以使用的文件系统不确定,所以这就是有多个stage1_5 的原因。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            Grub Legacy:分三阶段
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            stage1:存放在MBR上
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            stage1_5:存放在MBR之后的扇区,让stage1中的bootloader能识别stage2所在的分区上的文件系统;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            stage2:磁盘分区(/boot/grub/)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp;引导加载程序先读取MBR上的gurb第一阶段,由于MBR很小只有512字节采用grub这种方式引导程序,随后读取扇区中的stage1.5阶段,读取1.5阶段以后从而就能驱动第二阶段stage2所在的磁盘分区,stage2是存放在磁盘分区上的还包括了内核文件及ramdisk等都在这个分区上存放的;这就是为什么通过Bootloader之grub就能够加载内核文件的原因。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; 注意:当前硬件平台,主板BIOS必须能识别硬盘,然后BIOS才能加载硬盘中的Bootloader,磁盘中的Bootloader自身加载完以后,就能够识别当前主机上的硬盘设备了。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            但硬盘设备能识别,并不代表硬盘上的文件系统能识别,因为文件系统是额外附加的一层软件组织的文件结构,所以要能够对接一种文件系统,必须要用到文件系统驱动;对应的应用程序必须能识别和理解这样的文件系统才可以,这种程序就称为文件系统驱动;grub的1.5阶段就是给gurb提供了文件系统驱动的,从而就能够访问对应的第二阶段和内核所在的分区了,这通常是一个基本磁盘分区;所以grub第二阶段以及内核和ramdisk文件通常都会放在一个基本磁盘分区上;因为grub驱动不了逻辑卷这种高级接口。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;stage2一般是挂载至/boot/grub/目录下;grub也有自己的配置文件:/boot/grub/grub.conf且通常有个符号链接文件:/etc/grub.conf;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;stage2的功用:
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;(1)提供菜单或交互式接口;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;(2)能加载用户选择的内核或操作系统;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;(3)为菜单通过了保护机制。
        </section>
    </section>
</section>



 





 
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            进入单用户模式:&nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            1)编辑grub菜单,选定要编辑的title,而后使用e命令 &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            2)在选定的kernel后附加1 ,s 或single &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            3)在kernel所在的行,键入b键&nbsp;&nbsp; &nbsp; &nbsp;
        </section>
    </section>
</section>


 




 
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **6、根切换**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; 在挂载根文件系统时为了避免内核中有bug或操作过程中有bug导致根文件系统被损坏,先只读挂载根文件系统,加载完成后才读写挂载,完成整个挂载根文件系统后,直接去找/sbin/init程序,即开始运行用户空间的第一个程序。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            用户空间启动流程
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **7、/sbin/init程序**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; init程序主要依赖于配置文件:/etc/inittab,大体分为:设定默认启动级别 --&gt; 设定系统初始化脚本 --&gt; 启动对应级别的服务 --&gt; 打印各终端登录界面(如果级别为3处理提供文本登录界面,如果级别为5还提供图形登录界面)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **8、设置默认运行级别**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; (1)运行级别:为了系统的运行或维护等目的而设定的机制;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; 0-6:共7个级别;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; &nbsp;0:关机,shutdown
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; &nbsp;1:单用户模式(single user),root用户,无须认证,维护模式;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; &nbsp;2:多用户模式(multi user),会启动网络功能,但不会启动NFS,维护模式;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; &nbsp;3:多用户模式(multi user),完全功能模式,文本界面;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; &nbsp;4:预留级别:目前无特别使用目的,但习惯以同3级别功能使用;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; &nbsp;5:多用户模式(multi user),完全功能模式,图形界面;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; &nbsp;6:重启,reboot
        </section>
    </section>
</section>



 





(2)配置文件:/etc/inittab定义了很多功能,每一行定义一种操作(action)以及与之对应的process(仅适用于CentOS 5),一行就定义了init要执行的任务,甚至是一堆任务,每一行的语法格式为:                                                             id:runlevels:action:process
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; id为一个任务的标识符;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; runlevels:在哪些运行级别下启动此任务;例:3,2345,也可为空表示所有级别;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; action:在什么条件下启动此任务;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; wait:等待切换至此任务所在的级别时执行一次(刚刚切换进来时);
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; respawn:一旦此任务终止时,就自动重启;(如:登录终端执行logout登出后会再次启动)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; initdefault:设定默认允许级别;此时process省略为空;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; sysinit:设定系统初始化方式,此处一般为指定/etc/rc.d/rc.sysinit脚本;(CentOS 5,6都用到此脚本,CentOS 7是靠systemd完成的),在CentOS 6中仅保留此配置文件中设定启动运行级别的功能。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; &nbsp; process:具体任务;通常为应用程序,或脚本,或二进制的程序,取决于自定义。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>
    </section>
</section>



 





9、系统初始化脚本
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            系统初始化脚本:/etc/rc.d/rc.sysinit
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (1)设置主机名;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (2)设置欢迎信息;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (3)激活udev和selinux;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (4)挂载/etc/fstab文件中定义的所有文件系统;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (5)检测根文件系统,并以读写方式重新挂载根文件系统;(重新挂载是指根文件检测完之后)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (6)设置系统时钟;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (7)根据/etc/sysctl.conf文件来设置内核参数;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (8)激活lvm即软raid设备;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (9)激活swap设备;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (10)加载额外设备的驱动程序;(内核加载驱动只加载根文件系统的)
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            (11)清理操作;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            注意:在init配置文件:/etc/inittab中,有一行内容是定义/etc/rc.d/rc.sysinit,此脚本文件是负责完成系统初始化的脚本文件。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **10、关闭/启动对应级别下的服务**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp; 脚本文件/etc/rc.d/rc作用为当级别切换时启动或停止服务;此脚本接受传递的参数给脚本中$runlevel变量,然后,读取/etc/rc$runlevel.d/K*和/etc/rc$runlevel.d/S*所有文件,这些文件就是为什么开机启动后,有些服务会自动启动,有些服务没有启动的原因。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            K*:要停止的服务,K##*,优先级,数字越小,越优先关闭,依赖的服务先关闭,然后再关闭被依赖的。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            S*:要启动的服务,S##*,优先级,数字越小,越是优先启动,被依赖的服务先启动,而依赖的服务后启动。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            /etc/rc.d/init.d目录还有个链接目录为/etc/init.d目录,这两目录下文件相同。
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            如上诉定义将会启动3级别下的以S打头的进程:
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            图示:
        </section>
    </section>
</section>


 




11、启动终端(图形终端)
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;操作系统启动完成
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>
    </section>
</section>












三、系统启动流程总结。














 
        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **内核级别:**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            1.POST做开机启动时候的硬件检测功能
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            2.BootSequence(BIOS)启动加载主引导分区MBR中的引导加载器程序BootLoader
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;&nbsp; 在LInux现行的BootLoader是三段划分(打破446字节限制)的GRUB程序,
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;&nbsp;&nbsp;&nbsp;第1段写在BootLoader中
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;&nbsp;&nbsp;&nbsp;第1.5段在其后扇区用于文件系统的引导
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;&nbsp;&nbsp;&nbsp;第2段在boot/grub中提供内部接口和调用系统内核kernel
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            3.Kernel识别硬件、加载驱动、只读挂载根文件系统、同时交付给用户空间第一个程序/sbin/init
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            此处特别要注意,系统发行商为了适应多种硬件接口驱动调用,会在第一次安装系统时候,自动识别硬件接口,并调用唯一驱动程序来生成ramdisk文件,以内存当磁盘做虚根,驱动接口后会切换到真实的根文件系统上
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            CentOS 5系列是initrd,当磁盘映像文件会造成二次缓存缓冲
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            CentOS 6/7系列改进为initramfs,以文件系统形式可以不二次占用缓存和缓冲
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            &nbsp;
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            **用户空间级别**
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            4./sbin/init接管后更具其配置文件来初始化
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            5.根据/sbin/init中的配置会设置默认运行级别,以及一些在/etc/init.d/设置的开机服务
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            6./etc/rc.d/rc.sysinit运行系统初始化脚本,完成系统初始化
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            7.关闭对应级别下需要停止的服务,启动对应级别下需要开启的服务
        </section>

        <section style="margin: 0px; padding: 0px; -ms-word-wrap: break-word !important; max-width: 100%; box-sizing: border-box;">
            8.设置登录终端
        </section>
    </section>
</section>