了了大实话 發表於 2020-8-25 08:11:00

centos(linux)启动流程

<h3><strong>CentOS<span style="font-family: 宋体">系统启动流程——基础知识</span></strong></h3>
<p class="16"><strong>Linux<span style="font-family: 宋体">系统的组成部分:</span></strong></p>
<p><span style="font-family: 宋体">除去硬件部分</span>linux<span style="font-family: 宋体">系统由,内核</span><span style="font-family: Calibri">+</span><span style="font-family: 宋体">根文件系统组成。内核启动后不是在执行内核代码,就</span>是在执行根文件系统下某个路径中的应用程序的代码(用户代码)。</p>
<p class="16"><strong>内核主要功能:</strong></p>
<p class="15"><strong>简述</strong></p>
<p>进程管理、内存管理、网络管理、文件系统、驱动程序、安全功能,这些功能就是通过系统调用输出的。</p>
<p class="15"><strong>进程管理:</strong></p>
<p><span style="font-family: 宋体">如一个父进程可以</span>fork<span style="font-family: 宋体">一个子进程,在必要时还可以将自己的数据复制给子进程一份。在子进程完成任务后还可以将其收回。</span></p>
<p class="15"><strong>内存管理:</strong></p>
<p><span style="font-family: 宋体">如</span>c<span style="font-family: 宋体">语言编程是可以使用命令</span><span style="font-family: Calibri">malloc</span><span style="font-family: 宋体">函数申请一段内存,使用完成后通过</span><span style="font-family: Calibri">free</span><span style="font-family: 宋体">来释放内存</span></p>
<p class="15"><strong>文件系统:</strong></p>
<p>如打开,读取,编辑一个文件都是通过系统调用实现的。</p>
<p class="16"><strong>Glibc<span style="font-family: 宋体">:</span></strong></p>
<p><span style="font-family: 宋体">现在程序员在写程序的时候虽然需要发起系统调用,但是有些时候在编程时不是通过发起系统调用完成的,而是,调用把系统调用二次封装的离用户更近的库文件实现的。在</span>linux<span style="font-family: 宋体">叫做</span><span style="font-family: Calibri">glibc</span><span style="font-family: 宋体">。</span><span style="font-family: Calibri">Glibc</span><span style="font-family: 宋体">是用户空间的内容了,如</span><span style="font-family: Calibri">/usr/lib</span><span style="font-family: 宋体">下的文件。</span></p>
<p><span style="font-family: 宋体">整个操作系统最核心的是内核、用户空间的应用程序以及必要库文件,其他的都是非必要。如</span>man<span style="font-family: 宋体">命令提供的帮助文档。</span></p>
<p class="16"><strong>Lib(<span style="font-family: 宋体">库):</span></strong></p>
<p><span style="font-family: 宋体">库是函数的集合,一个功能模块,</span>lib<span style="font-family: 宋体">有其调用接口。通过函数名调用</span><span style="font-family: Calibri">lib</span><span style="font-family: 宋体">文件。库文件也是一个二进制文件,但是他不能独立运行,只能被调用。</span></p>
<p class="16"><strong>过程调用:</strong></p>
<p>procedure<span style="font-family: 宋体">,没有返回值的函数</span></p>
<p class="16"><strong>函数调用:</strong></p>
<p>function<span style="font-family: 宋体">,有返回值的函数</span></p>
<p>头文件:不同函数可接受的参数数量和类型不同,所以说每一个库中有多少个函数,每个函数可接受多少参数,以及每个参数类型都应该有一个文件对其加以描述,这个文件就是头文件。</p>
<p class="15"><strong>内核设计流派:</strong></p>
<p class="16"><strong><span style="font-family: 黑体">单内核设计:如,</span>Linux</strong></p>
<p><span style="font-family: 宋体">把所有功能集成于同一个程序;每个功能都是在此程序中通过线程实现。这就是</span>linux<span style="font-family: 宋体">内核线程。一般来讲效率高,但是可能任何一个程序出现问题会影响整个系统</span></p>
<p class="16"><strong><span style="font-family: 黑体">微内核设计:如,</span>Windows, Solaris</strong>&nbsp;</p>
<p>每种功能使用一个单独子系统实现;一般来讲效率比单内核设计低,但是一个子系统出现问题不会影响整个系统。</p>
<p class="16"><strong>Linux<span style="font-family: 黑体">内核特点:</span></strong></p>
<p><span style="font-family: 宋体">微内核设计思想比单内核更前卫,但是</span>linux<span style="font-family: 宋体">也借鉴了微内核有点,在内核内部支持模块化。</span></p>
<p class="16"><strong>支持模块化:</strong></p>
<p>linux<span style="font-family: 宋体">内核支持将每个功能设计为一个独立的功能模块。格式为</span><span style="font-family: Calibri">*.ko</span><span style="font-family: 宋体">。</span></p>
<p class="16"><strong>支持模块的动态装载和卸载。</strong></p>
<p class="16"><strong><span style="font-family: 黑体">动态装卸载的优点:</span><span style="font-family: 黑体">(小、维护)</span></strong></p>
<p>由于动态装卸载的存在,我们可以仅保留内核最基本和核心的功能,当需要某模块提供的功能时,只需要临时将其装载进内核。这样内核体系就变得非常小了。</p>
<p><span style="font-family: 宋体">我们知道硬件的驱动程序一般都是由内核提供的,如果内核模块不支持模块化的,得来的结果是:任何一个硬件驱动程序想要被使用,必须提前将其编写整合进内核。如果作为一个内核维护者,在没有充分检验情况下将别人开发的驱动整合进内核,万一有,此驱动带有恶意代码可能造成很大危害(例如对方植入病毒等)。造成内核崩溃,操作系统关闭等。而有了模块化后,任何一个厂商都可自行开发模块,作为用户,我们可以自行选择使用那些模块。维护工作也由厂商自己负责,以保证自己模块的安全性。这也是的</span>linux<span style="font-family: 宋体">能随时使用更多的硬件设备了</span></p>
<p class="15"><strong>内核组成部分:</strong>&nbsp;</p>
<p class="16"><strong>核心文件:</strong></p>
<p>/boot/vmlinuz-VERSION-release <span style="font-family: 宋体">。可以看到内核文件很小,是因为它将很多功能做成了模块</span></p>
<p><span style="font-family: 宋体"><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825081155795-1963586820.png"></span></p>
<p class="15"><strong>模块文件:</strong></p>
<p>/lib/modules/VERSION-release <span style="font-family: 宋体">。模块文件需要和内核版本严格匹配的。模块文件名就是核心文件的后缀名。</span><span style="font-family: Calibri">*.ko</span><span style="font-family: 宋体">文件就是内核模块</span></p>
<p><span style="font-family: 宋体"><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825081214150-817855838.png"></span></p>
<p class="16"><strong>Ramdisk<span style="font-family: 宋体">:</span></strong></p>
<p class="15"><strong>Init<span style="font-family: 黑体">文件在</span><span style="font-family: Arial">centos5</span><span style="font-family: 黑体">和</span><span style="font-family: Arial">6</span><span style="font-family: 黑体">上不同:</span></strong></p>
<p>Centos5<span style="font-family: 宋体">使用的是</span><span style="font-family: Calibri">initrd</span><span style="font-family: 宋体">,即</span><span style="font-family: Calibri">init ram disk</span></p>
<p>CentOS 5: /boot/initrd-VERSION-release.img <span style="font-family: 宋体">,基于内存的磁盘。</span></p>
<p>Centos6<span style="font-family: 宋体">使用的是</span><span style="font-family: Calibri">init ram file-system</span></p>
<p>CentOS 6: /boot/initramfs-VERSION-release.img <span style="font-family: 宋体">,基于内存的文件系统。</span></p>
<p class="15"><strong>Ramdisk<span style="font-family: 黑体">生成工具</span></strong></p>
<p>Ramdisk<span style="font-family: 宋体">是在安装系统时由工具自动生成的</span></p>
<p>Centos5<span style="font-family: 宋体">使用的是</span><span style="font-family: Calibri">initrd</span><span style="font-family: 宋体">,由</span><span style="font-family: Calibri">mkinitrd</span></p>
<p>Centos6<span style="font-family: 宋体">使用的是</span><span style="font-family: Calibri">initramfs,</span><span style="font-family: 宋体">由</span><span style="font-family: Calibri">dracut</span></p>
<p class="15"><strong><span style="font-family: 黑体">问题二:为什么</span>centos5<span style="font-family: 黑体">到</span><span style="font-family: Arial">6</span><span style="font-family: 黑体">从</span><span style="font-family: Arial">ramdisk </span><span style="font-family: 黑体">变成</span><span style="font-family: Arial">ramfs</span></strong></p>
<p><span style="font-family: 宋体">  这要从,</span>“内核中的特性之一:使用缓冲(写)和缓存(读)来加速对磁盘上的文件访问;”说起<span style="font-family: Calibri">centos5</span><span style="font-family: 宋体">中使用的是</span><span style="font-family: Calibri">ramdisk</span><span style="font-family: 宋体">是将内存当做磁盘使用,在</span><span style="font-family: Calibri">linux</span><span style="font-family: 宋体">中</span><span style="font-family: Calibri">cpu </span><span style="font-family: 宋体">认为磁盘的访问速度太慢,为了加速磁盘访问,会将磁盘内容加载至内存,这样会造成这个“磁盘”会再次被加载到内存一次当做缓冲和缓存。两次缓存,使得资源访问变慢。而</span><span style="font-family: Calibri">ramfs</span><span style="font-family: 宋体">是将内存当做了文件系统。文件系统自己就可以管理自己的缓存和缓冲,避免了两次加载。</span></p>
<p><span style="font-family: 宋体"><strong>问题三:内核如何挂载根</strong></span></p>
<p><span style="font-family: 宋体">  除去核心文件和模块文件还有第三个文件它是非必要的,但是在很多场景中被用到了他就是</span>ramdisk<span style="font-family: 宋体">。例如</span><span style="font-family: Calibri">linux</span><span style="font-family: 宋体">开机后加载内核,由内核去加载根文件系统,但是内核中没有根文件系统驱动(都放在</span><span style="font-family: Calibri">/lib/modules</span><span style="font-family: 宋体">下)。</span><span style="font-family: Calibri">/lib</span><span style="font-family: 宋体">在根文件系统上。这就没法去加载硬件驱动。解</span>决此问题有两种方法:&nbsp;</p>
<p>1、直接将驱动编译进内核,但是驱动有千万种,都将他们编译进内核,会使内核变得太大。这样显然不合适</p>
<p><span style="font-family: 宋体">2、借助于外在的辅助机制。</span> <span style="font-family: 宋体">将所有驱动硬盘的必要工具全部做成一个文件系统,这个文件系统称为虚拟文件系统。这个根文件系统仅仅包含了驱动硬盘的驱动和文件系统。在开机时此文件系统跟随内核一起加载至内存。内核先去加载虚拟文件系统,从虚拟文件系统加载到驱动磁盘的驱动</span>&nbsp;</p>
<p><strong>问题四:这个虚拟根文件系统中存放的是哪一种驱动呢?是全部的驱动?还是只针对于本机硬盘设备的驱动?</strong></p>
<p>  存放的是只适用于本机磁盘类型的驱动。所以虚拟根文件系统不是提前制作好的,而是在安装操作系统时,在安装最后一步自动生成的适用于自己的电脑的磁盘的驱动。</p>
<p>  这个虚拟文件系统是一个本地回环设备文件,并且该文件在系统启动时会自动加载到内存。在内存中把这个文件当做磁盘使用,从而使得内核能加载到临时根文件系统,并装载临时根文件系统中的驱动。随后进行根切换。将临时根切换为真正根。</p>
<h1><strong>CentOS <span style="font-family: 宋体">系统启动流程:</span></strong></h1>
<p><span style="font-family: 宋体">概述:加电自检</span>,<span style="font-family: 宋体">通过</span><span style="font-family: Calibri">BIOS</span><span style="font-family: 宋体">设定的启动顺序,将第一个含有</span><span style="font-family: Calibri">bootloader</span><span style="font-family: 宋体">的设备中的内核加载至内存。随后内核在内存中完成初始化(加载硬件驱动程序(有可能借助</span><span style="font-family: Calibri">ramdisk</span><span style="font-family: 宋体">),只读格式挂载跟文件系统,并运行第一个用户空间程序</span><span style="font-family: Calibri">/sbin/init</span><span style="font-family: 宋体">)。</span></p>
<p class="15"><strong>POST<span style="font-family: 宋体">:</span><span style="font-family: Calibri">powered self-test &nbsp;</span><span style="font-family: 宋体">加电自检;</span></strong></p>
<p><span style="font-family: 宋体">在按下开机电源后,给</span>CMOS<span style="font-family: 宋体">通电,先去通过</span><span style="font-family: Calibri">BIOS</span><span style="font-family: 宋体">读取</span><span style="font-family: Calibri">CMOS</span><span style="font-family: 宋体">中存储的当前系统的硬件配置和用户的参数设定,根据</span><span style="font-family: Calibri">BIOS</span><span style="font-family: 宋体">的设定去检测硬件设备(</span><span style="font-family: Calibri">cpu</span><span style="font-family: 宋体">、</span><span style="font-family: Calibri">memory</span><span style="font-family: 宋体">、</span><span style="font-family: Calibri">disk</span><span style="font-family: 宋体">)是否存在,状态是否正常,之后进行硬件设备的初始化。</span></p>
<p><span style="font-family: 宋体">补充:在上述操作后,会有一个提示:例如</span>Windows<span style="font-family: 宋体">中按下</span><span style="font-family: Calibri">enter</span><span style="font-family: 宋体">进入</span><span style="font-family: Calibri">bios</span><span style="font-family: 宋体">设定界面。</span><span style="font-family: Calibri">Linux</span><span style="font-family: 宋体">如下图按“</span><span style="font-family: Calibri">F2</span><span style="font-family: 宋体">”进入</span><span style="font-family: Calibri">bios</span><span style="font-family: 宋体">。随后看到</span><span style="font-family: Calibri">bios</span><span style="font-family: 宋体">界面</span></p>
<p><span style="font-family: 宋体"><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825082631657-1834815147.png"></span></p>
<p><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825082642248-799492647.png"></p>
<p class="15"><strong>BOOT Sequence<span style="font-family: 宋体">:系统的引导加载次序</span></strong></p>
<p><span style="font-family: 宋体">在</span>bios<span style="font-family: 宋体">中有个</span><span style="font-family: Calibri">BOOT Sequence</span><span style="font-family: 宋体">(见上图的</span><span style="font-family: Calibri">boot</span><span style="font-family: 宋体">菜单),根据</span><span style="font-family: Calibri">BIOS</span><span style="font-family: 宋体">设定的次序去逐一查找含有</span><span style="font-family: Calibri">boot loader</span><span style="font-family: 宋体">(引导加载器,是一个程序)的设备,直到找到第一个可启动设备。第一个有引导程序的设备即为本次启动用到设备;如果我们不按“</span><span style="font-family: Calibri">F2</span><span style="font-family: 宋体">”进入</span><span style="font-family: Calibri">bios</span><span style="font-family: 宋体">更改启动选项的话,会使用</span><span style="font-family: Calibri">boot</span><span style="font-family: 宋体">中之前已经设置好的。</span></p>
<p class="15"><strong>MBR: master boot record</strong>&nbsp;</p>
<p><span style="font-family: 宋体">位于硬盘上的</span>0<span style="font-family: 宋体">磁道的</span><span style="font-family: Calibri">0</span><span style="font-family: 宋体">分区共512字节,由以下三部分组成</span></p>
<p>  前446字节: bootloader<span style="font-family: 宋体">,一般是在安装</span><span style="font-family: Calibri">OS</span><span style="font-family: 宋体">时,默认安装。也可以手动安装</span></p>
<p>  64: fat<span style="font-family: 宋体">(磁盘分区表)</span></p>
<p>  最后2字节: 55AA<span style="font-family: 宋体">,用来标记</span><span style="font-family: Calibri">boot loader</span><span style="font-family: 宋体">是否有效</span>&nbsp;</p>
<p class="16"><strong>bootloader:</strong></p>
<p><span style="font-family: 宋体">每一种操作系统都应该有自己的加载器,</span>bootloader<span style="font-family: 宋体">主要功能是:找到操作系统所在的磁盘分区,将内核加载至内存中,并且将控制权转交给内核。</span></p>
<p><span style="font-family: 宋体">功能:提供一个菜单,允许用户选择要启动系统或不同的内核版本;把用户选定的内核装载到内存中的特定空间中,解压、展开,并把系统控制权移交给内核;</span></p>
<p class="15"><strong>Windows<span style="font-family: 黑体">中的</span><span style="font-family: Arial">bootloader</span><span style="font-family: 黑体">是 </span><span style="font-family: Arial">ntloader</span></strong></p>
<p class="15"><strong>Linux<span style="font-family: 黑体">中的</span><span style="font-family: Arial">bootloader</span><span style="font-family: 黑体">有两种</span></strong></p>
<p>LILO<span style="font-family: 宋体">:</span><span style="font-family: Calibri">LInux LOader</span><span style="font-family: 宋体">,古老,常见于手机中</span></p>
<p>GRUB: GRand Uniform Bootloader&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>  GRUB 0.X: GRUB Legacy &nbsp;<span style="font-family: 宋体">在</span><span style="font-family: Calibri">centos6</span><span style="font-family: 宋体">中使用的是</span><span style="font-family: Calibri">0.9</span><span style="font-family: 宋体">版本的</span><span style="font-family: Calibri">grub</span><span style="font-family: 宋体">。</span></p>
<p>  &nbsp;<img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825082926439-896666857.png"></p>
<p>  GRUB 1.x: GRUB2<span style="font-family: 宋体">,</span><span style="font-family: Calibri">grub </span><span style="font-family: 宋体">二代和一代完全不同是完全重写的centos7使用的是grub2&nbsp;</span></p>
<p><span style="font-family: 宋体">  <img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825083023285-2118416068.png"></span></p>
<p class="15"><strong>GRUB: grup<span style="font-family: 黑体">有三个阶段</span></strong></p>
<p class="15"><strong><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825083409025-137919815.png"></strong></p>
<p>Stage1<span style="font-family: 宋体">:运行</span><span style="font-family: Calibri">boot loader</span><span style="font-family: 宋体">主程序,这个程序只能被安装在</span><span style="font-family: Calibri">MBR</span><span style="font-family: 宋体">中。因为</span><span style="font-family: Calibri">MBR</span><span style="font-family: 宋体">空间太小,因此仅安装</span><span style="font-family: Calibri">boot loader</span><span style="font-family: 宋体">的最小主程序,并没有安装配置文件。只是查找位于磁盘上的第</span><span style="font-family: Calibri">1.5</span><span style="font-family: 宋体">阶段</span></p>
<p>Stage1_5<span style="font-family: 宋体">:在</span><span style="font-family: Calibri">MBR</span><span style="font-family: 宋体">随后的扇区存放,重要用于与</span><span style="font-family: Calibri">stage2</span><span style="font-family: 宋体">所在分区的文件进行交互。系统所使用的文件系统类型,在安装完操作系统后就已经确认为某一种了。</span><span style="font-family: Calibri">Grup</span><span style="font-family: 宋体">的</span><span style="font-family: Calibri">1.5</span><span style="font-family: 宋体">阶段就是将上图的某一个</span><span style="font-family: Calibri">1_5</span><span style="font-family: 宋体">与当前文件系统匹配,安装在了</span><span style="font-family: Calibri">MBR</span><span style="font-family: 宋体">随后的扇区上。通过</span><span style="font-family: Calibri">1.5</span><span style="font-family: 宋体">阶段去访问第</span><span style="font-family: Calibri">2</span><span style="font-family: 宋体">阶段分区的驱动,加载并访问第</span><span style="font-family: Calibri">2</span><span style="font-family: 宋体">阶段</span></p>
<p>Stage2<span style="font-family: 宋体">:通过</span><span style="font-family: Calibri">boot loader</span><span style="font-family: 宋体">加载所有的配置文件和相关环境参数,这些文件和参数放在磁盘的</span><span style="font-family: Calibri">/boot</span><span style="font-family: 宋体">目录下。</span></p>
<p class="15"><strong>Kernel<span style="font-family: 宋体">:</span></strong>&nbsp;</p>
<p><span style="font-family: 宋体">通过</span>bootloader <span style="font-family: 宋体">加载内核后,内核在内存中解压,加载。探测可识别到的所有硬件设备,加载硬件驱动程序(有驱动的适用驱动去访问硬件,没有的适用基本驱动去访问,如果基本驱动无法访问,则该设备无法被加载),只读方式挂载根文件系统,并启动</span><span style="font-family: Calibri">init</span><span style="font-family: 宋体">。</span></p>
<p class="15"><strong>自身初始化:</strong></p>
<p>1. <span style="font-family: 宋体">探测可识别到的所有硬件设备;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</p>
<p>2. <span style="font-family: 宋体">加载硬件驱动程序;(有可能会借助于</span>ramdisk<span style="font-family: 宋体">加载驱动)</span></p>
<p>3. 以只读方式挂载根文件系统;</p>
<p><span style="font-family: 宋体">任何一个程序中都有不确定因素,内核第一次加载根文件系统后,并不确定自己的行为是否妥当的,只读方式,是为了防止内核有</span>BUG<span style="font-family: 宋体">的情况下删除根文件系统等破坏性操作</span></p>
<p><span style="font-family: 宋体">4. 运行用户空间的第一个应用程序:</span>/sbin/init&nbsp;&nbsp;</p>
<p class="15"><strong>init<span style="font-family: 黑体">程序的类型:</span></strong></p>
<p>SysV: init, CentOS 5 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p><span style="font-family: 宋体">  配置文件:</span>/etc/inittab&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>Upstart: centos6</p>
<p><span style="font-family: 宋体">  在</span>centos6<span style="font-family: 宋体">上又被重命名为</span><span style="font-family: Calibri">init,</span><span style="font-family: 宋体">所有 </span><span style="font-family: Calibri">CentOS 6</span><span style="font-family: 宋体">还可以使用</span><span style="font-family: Calibri">service</span><span style="font-family: 宋体">启动管理服务。</span></p>
<p><span style="font-family: 宋体">  配置文件:</span>/etc/inittab<span style="font-family: 宋体">(该文件在</span><span style="font-family: Calibri">centos6</span><span style="font-family: 宋体">上几乎被废弃)</span><span style="font-family: Calibri">,</span><span style="font-family: 宋体">主要使用 </span><span style="font-family: Calibri">/etc/init/*.conf</span></p>
<h6><span style="font-size: 16px"><strong>Centos</strong><strong>6</strong><strong><span style="font-family: 黑体">使用</span>UPstart<span style="font-family: 黑体">的原因</span></strong></span></h6>
<p><span style="font-size: 16px">  Sysv<span style="font-family: 宋体">的</span><span style="font-family: Calibri">init</span><span style="font-family: 宋体">在完成系统初始化时</span><span style="font-family: Calibri">,</span><span style="font-family: 宋体">都是借助于脚本实现,是串行运行的。脚本是一组命令的集合,整个初始化过程由上往下执行,一直在创建进程和销毁进程,而各个服务之间有的还有以来关系(如</span><span style="font-family: Calibri">A</span><span style="font-family: 宋体">依赖于</span><span style="font-family: Calibri">B</span><span style="font-family: 宋体">只有在</span><span style="font-family: Calibri">B</span><span style="font-family: 宋体">完全启动后</span><span style="font-family: Calibri">A</span><span style="font-family: 宋体">才能启动),处理速度慢。这就是为什么</span><span style="font-family: Calibri">centos5</span><span style="font-family: 宋体">启动慢的原因。</span><span style="font-family: Calibri">Upstart </span><span style="font-family: 宋体">是由</span><span style="font-family: Calibri">ubantu</span><span style="font-family: 宋体">研发的,他是接近于并行运行的。当出现依赖关系是</span><span style="font-family: Calibri">A</span><span style="font-family: 宋体">无需等待</span><span style="font-family: Calibri">B</span><span style="font-family: 宋体">完全启动(提供一种基于总线的进程间互相通信,</span><span style="font-family: Calibri">B</span><span style="font-family: 宋体">一初始化就可以通知</span><span style="font-family: Calibri">A</span><span style="font-family: 宋体">,</span><span style="font-family: Calibri">A</span><span style="font-family: 宋体">可以启动了)</span><span style="font-family: Calibri">centos6</span><span style="font-family: 宋体">启动速度比</span><span style="font-family: Calibri">centos</span><span style="font-family: 宋体">大大加快。</span></span></p>
<p>Systemd<span style="font-family: 宋体">:</span><span style="font-family: Calibri">systemd, CentOS 7</span></p>
<p><span style="font-family: 宋体">仿照</span>mac<span style="font-family: 宋体">的初始化启动流程,不通过脚本的方式启动服务,而是由</span><span style="font-family: Calibri">systemd</span><span style="font-family: 宋体">自己本身启动服务,只有在服务第一次被使用的时候,该服务才被启动。这使得开机可以在秒级别启动</span></p>
<p><span style="font-family: 宋体">配置文件:</span></p>
<p>  /usr/lib/systemd/system/<span style="font-family: 宋体">和</span><span style="font-family: Calibri">/etc/systemd/system/</span><span style="font-family: 宋体">目录下&nbsp;&nbsp;</span></p>
<p><span style="font-family: 宋体">系统初始化流程总结(前半段):</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p><span style="color: rgba(153, 51, 0, 1)">POST --&gt; BootSequence (BIOS) --&gt; Bootloader(<span style="font-family: 宋体">位于</span><span style="font-family: Calibri">MBR</span><span style="font-family: 宋体">,三阶段</span><span style="font-family: Calibri">) --&gt; kernel--&gt;(</span><span style="font-family: 宋体">内核借助</span><span style="font-family: Calibri">ramdisk</span><span style="font-family: 宋体">挂载临时根,通过临时根去加载硬件驱动,然后切换临时根为真正根) </span><span style="font-family: Calibri">--&gt; rootfs(</span><span style="font-family: 宋体">只读方式挂载真正根</span><span style="font-family: Calibri">) --&gt; init&nbsp;&nbsp;</span></span></p>
<h2 class="17"><strong>/sbin/init</strong></h2>
<h2 class="17"><strong>CentOS 5:</strong></h2>
<p class="15"><strong>运行级别:</strong></p>
<p><span style="font-family: 宋体">为了系统的运行或维护等应用目的而设定;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>0-6<span style="font-family: 宋体">:</span><span style="font-family: Calibri">7</span><span style="font-family: 宋体">个级别&nbsp;</span></p>
<p>0<span style="font-family: 宋体">:关机&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p>
<p>1<span style="font-family: 宋体">:单用户模式</span><span style="font-family: Calibri">(</span><span style="font-family: 宋体">默认</span><span style="font-family: Calibri">root</span><span style="font-family: 宋体">用户</span><span style="font-family: Calibri">, </span><span style="font-family: 宋体">无须输入密码,即可登录</span><span style="font-family: Calibri">), single, </span><span style="font-family: 宋体">维护模式;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>2: <span style="font-family: 宋体">多用户模式,会启动网络功能,但不会启动</span><span style="font-family: Calibri">NFS</span><span style="font-family: 宋体">(网络文件系统);维护模式;&nbsp; &nbsp; &nbsp;</span></p>
<p>3<span style="font-family: 宋体">:多用户模式,正常模式;文本界面;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>4<span style="font-family: 宋体">:预留级别;可同</span><span style="font-family: Calibri">3</span><span style="font-family: 宋体">级别;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p>
<p>5<span style="font-family: 宋体">:多用户模式,正常模式;图形界面;&nbsp;</span></p>
<p>6<span style="font-family: 宋体">:重启&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p>
<p class="15"><strong>默认运行级别:</strong></p>
<p>Linux<span style="font-family: 宋体">默认运行级别应该为</span><span style="font-family: Calibri">3</span><span style="font-family: 宋体">或</span><span style="font-family: Calibri">5</span><span style="font-family: 宋体">。</span></p>
<p class="15"><strong>切换级别:</strong></p>
<p>init #&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</p>
<p class="15"><strong>查看级别:</strong></p>
<p>runlevel <span style="font-family: 宋体">:查看系统当前和上一次运行级别 </span>&nbsp;</p>
<p><span style="font-family: 宋体">输出两个字段:第一个代表上一次运行的级别,第二个为本次运行级别。下图情况</span>N<span style="font-family: 宋体">是</span><span style="font-family: Calibri">null</span><span style="font-family: 宋体">的意思代表系统启动后没有切换过级别,所以就和本次运行的级别一样其实也</span><span style="font-family: 宋体">是</span>3<span style="font-family: 宋体">。</span><span style="font-family: Calibri">3</span><span style="font-family: 宋体">代表系统运行级别为</span><span style="font-family: Calibri">3</span><span style="font-family: 宋体">级别。</span>who -r &nbsp;<span style="font-family: 宋体">:</span><span style="font-family: Calibri">last=3</span><span style="font-family: 宋体">代表上次运行级别为</span><span style="font-family: Calibri">3</span></p>
<p><span style="font-family: Calibri"><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825205929792-1278618111.png"></span></p>
<p class="16"><strong><span style="font-family: 宋体">配置文件:</span>/etc/inittab</strong></p>
<p class="15"><strong><span style="font-family: 黑体">配置文件</span>/etc/inittab<span style="font-family: 黑体">的格式</span></strong></p>
<p class="15"><strong>设定系统默认运行级别</strong></p>
<p><span style="font-family: 宋体">每一行定义一种</span>action<span style="font-family: 宋体">以及与之对应的</span><span style="font-family: Calibri">process</span><span style="font-family: 宋体">(操作)</span></p>
<p>id:runlevels:action:process</p>
<p>id<span style="font-family: 宋体">:一个任务的标识符;</span></p>
<p>runlevels<span style="font-family: 宋体">:在哪些级别启动此任务;</span><span style="font-family: Calibri">#</span><span style="font-family: 宋体">,</span><span style="font-family: Calibri">###</span><span style="font-family: 宋体">,也可以为空,表示所有级别;</span></p>
<p>action<span style="font-family: 宋体">:在什么条件下启动此任务;</span></p>
<p>process<span style="font-family: 宋体">:任务;</span>&nbsp;</p>
<p>action<span style="font-family: 宋体">:</span></p>
<p>  wait<span style="font-family: 宋体">:等待切换至此任务所在的级别时执行一次;</span></p>
<p>  respawn<span style="font-family: 宋体">:一旦此任务终止,就自动重新启动之;例如系统登录界面,每次登出系统都会跳转的此界面</span></p>
<p>  initdefault<span style="font-family: 宋体">:设定默认运行级别;此时,</span><span style="font-family: Calibri">process</span><span style="font-family: 宋体">省略;</span></p>
<p>  sysinit<span style="font-family: 宋体">:设定系统初始化方式,此处一般为指定</span><span style="font-family: Calibri">/etc/rc.d/rc.sysinit</span><span style="font-family: 宋体">脚本;</span></p>
<p>/etc/rc.d/rc.sysinit<span style="font-family: 宋体">:系统软件运行环境的配置比脚本。在设置好默认运行级别后,装载此脚本完成系统配置。</span></p>
<p>例如:</p>
<p>  根据配置文件中的设定来设定主机</p>
<p><span style="font-family: 宋体">  激活</span>selinux<span style="font-family: 宋体">和</span><span style="font-family: Calibri">udev</span></p>
<p><span style="font-family: 宋体">  激活</span>swap<span style="font-family: 宋体">设备</span></p>
<p>  设置时钟</p>
<p><span style="font-family: 宋体">  激活</span>LVM<span style="font-family: 宋体">、</span><span style="font-family: Calibri">raid</span><span style="font-family: 宋体">设备</span></p>
<p><span style="font-family: 宋体">  检测根文件系统,实现以读写方式重新挂载等</span></p>
<p>例如:</p>
<p>id:3:initdefault: <span style="font-family: 宋体">设定默认运行级别为</span><span style="font-family: Calibri">3</span></p>
<p class="15"><strong>系统环境初始化</strong>&nbsp;</p>
<p>si::sysinit:/etc/rc.d/rc.sysinit<span style="font-family: 宋体">:设定系统初始化方式,此处一般为指</span><span style="font-family: Calibri">/etc/rc.d/rc.sysinit</span><span style="font-family: 宋体">(系统初始化脚本);</span></p>
<p class="15"><strong>运行指定级别下的脚本</strong></p>
<p>10:0:wait:/etc/rc.d/rc &nbsp;0</p>
<p>11:1:wait:/etc/rc.d/rc &nbsp;1</p>
<p>…………</p>
<p>16:6:wait:/etc/rc.d/rc &nbsp;6</p>
<p><span style="font-family: 宋体">每一行后都有一个参数</span>0~6<span style="font-family: 宋体">,由于一开始设定“</span><span style="font-family: Calibri">id:3:initdefault:</span><span style="font-family: 宋体">”意味着去启动或关闭</span><span style="font-family: Calibri">/etc/rc.d/rc3.d/</span><span style="font-family: 宋体">目录下的服务脚本所控制服务;</span>etc/rc.d/rc3.d/<span style="font-family: 宋体">目录下的服务脚本,都是以</span><span style="font-family: Calibri">S</span><span style="font-family: 宋体">或者</span><span style="font-family: Calibri">K</span><span style="font-family: 宋体">开头的。</span><span style="font-family: Calibri">K</span><span style="font-family: 宋体">代表关闭服务。</span><span style="font-family: Calibri">S</span><span style="font-family: 宋体">代表开启服务</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>K##*<span style="font-family: 宋体">:</span><span style="font-family: Calibri">##</span><span style="font-family: 宋体">运行次序;数字越小,越先运行;数字越小的服务,通常为依赖到别的服务;</span></p>
<p><span style="font-family: Calibri">S##*</span><span style="font-family: 宋体">:</span><span style="font-family: Calibri">##</span><span style="font-family: 宋体">运行次序;数字越小,越先运行;数字越小的服务,通常为被依赖到的服务;</span></p>
<p><span style="font-family: 宋体">这些</span>/etc/rc.d/rc#.d/<span style="font-family: 宋体">下的</span><span style="font-family: Calibri">S</span><span style="font-family: 宋体">或者</span><span style="font-family: Calibri">K</span><span style="font-family: 宋体">开头的文件其实是</span><span style="font-family: Calibri">/etc/rc.d/init.d/</span><span style="font-family: 宋体">下文件的链接文件,链接文件保持</span><span style="font-family: Calibri">/etc/rc.d/init.d</span><span style="font-family: 宋体">下文件名不变只是在其前边添加</span><span style="font-family: Calibri">K##</span><span style="font-family: 宋体">或者</span><span style="font-family: Calibri">S##</span></p>
<p><span style="font-family: Calibri"><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825210641949-1976247531.png"></span></p>
<p class="16"><strong>chkconfig<span style="font-family: 宋体">命令</span></strong></p>
<p>/etc/rc.d/rc#.d/<span style="font-family: 宋体">下文件被启动还是关闭由其开头的</span><span style="font-family: Calibri">S</span><span style="font-family: 宋体">或者</span><span style="font-family: Calibri">K</span><span style="font-family: 宋体">决定。配置其实在哪个级别上开启或者关闭的是由</span><span style="font-family: Calibri">chkconfig</span><span style="font-family: 宋体">命令决定的</span></p>
<p class="15"><strong>查看服务在所有级别的启动或关闭设定情形:</strong></p>
<p>chkconfig [--list] &nbsp; &nbsp;&nbsp;</p>
<p><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825210937127-470219787.png"></p>
<p class="15"><strong>更改指定服务在某级别下的启停状态</strong></p>
<p><span style="font-family: 宋体">例如更改</span>NetworManager<span style="font-family: 宋体">在</span><span style="font-family: Calibri">3</span><span style="font-family: 宋体">级别下由</span><span style="font-family: Calibri">on</span><span style="font-family: 宋体">改为</span><span style="font-family: Calibri">off</span><span style="font-family: 宋体">状态</span></p>
<p>Chkconfig --level 3 NetworManager off</p>
<p><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825211033855-1823578525.png"></p>
<p><span style="font-family: 宋体">可以看到</span>/etc/rc.d/rc3.d<span style="font-family: 宋体">下</span><span style="font-family: Calibri">NetworkManager</span><span style="font-family: 宋体">被改成了以</span><span style="font-family: Calibri">K</span><span style="font-family: 宋体">开头的了</span></p>
<p><span style="font-family: 宋体"><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825211043345-1098903973.png"></span></p>
<p class="15"><strong><span style="font-family: 黑体">补充:</span>K84NetworkManager<span style="font-family: 黑体">中优先级</span><span style="font-family: Arial">84</span><span style="font-family: 黑体">是怎么来的呢?</span></strong></p>
<p><span style="font-family: 宋体">这个信息是在每个服务的脚本中定义的。查看</span>/etc/rc.d/rc3.d/NetworkManager<span style="font-family: 宋体">脚本。</span></p>
<p>Centos5 sysv<span style="font-family: 宋体">格式:</span></p>
<p><span style="font-family: 宋体">第一个地段:代表刚添加完服务脚本在此目录,并受到</span>chkconfig<span style="font-family: 宋体">控制时默认在那些级别下将此服务设置为</span><span style="font-family: Calibri">S</span><span style="font-family: 宋体">,“</span><span style="font-family: Calibri">-</span><span style="font-family: 宋体">”代表所有级别都不为</span><span style="font-family: Calibri">S</span><span style="font-family: 宋体">,即刚刚把服务脚本添加到目录,使用</span><span style="font-family: Calibri">chkconfig</span><span style="font-family: 宋体">处理时,默认在</span><span style="font-family: Calibri">0~6</span><span style="font-family: 宋体">级别都添加一个</span><span style="font-family: Calibri">K</span><span style="font-family: 宋体">开头的链接文件;</span></p>
<p><span style="font-family: 宋体">第二个字段:</span>23<span style="font-family: 宋体">代表启动时的优先级。</span></p>
<p><span style="font-family: 宋体">第三个地段:</span>84<span style="font-family: 宋体">位关闭时的优先级。</span></p>
<p>Centos5<span style="font-family: 宋体">一刀切的设置启动方式,</span><span style="font-family: Calibri">centos6</span><span style="font-family: 宋体">有更高级方式如下图</span></p>
<p><span style="font-family: 宋体"><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825211118035-671350522.png"></span></p>
<p><strong>如何让手动安装的软件要像系统服务那样自启动</strong></p>
<p><span style="font-family: 宋体">添加:手动安装的软件要想像系统服务那样自启动需要手动编写</span>Sysv<span style="font-family: 宋体">脚本放在</span><span style="font-family: Calibri">/etc/rc.d/init.d</span><span style="font-family: 宋体">下&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>SysV<span style="font-family: 宋体">的服务脚本放置于</span><span style="font-family: Calibri">/etc/rc.d/init.d (/etc/init.d)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p>
<p><span style="font-family: 宋体">使用</span>chkconfig<span style="font-family: 宋体">创建</span><span style="font-family: Calibri">rc</span><span style="font-family: 宋体">脚本</span></p>
<p>  chkconfig --add name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nb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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>chkconfig [--level levels] name &lt;on|off|reset&gt;</p>
<p>--level LLLL: <span style="font-family: 宋体">指定要设置的级别;省略时表示</span><span style="font-family: Calibri">2345</span><span style="font-family: 宋体">;&nbsp;</span></p>
<p><span style="font-family: 宋体">注意:正常级别下,最后启动一个服务</span>S99local<span style="font-family: 宋体">没有链接至</span><span style="font-family: Calibri">/etc/rc.d/init.d</span><span style="font-family: 宋体">一个服务脚本,而是指向了</span><span style="font-family: Calibri">/etc/rc.d/rc.local</span><span style="font-family: 宋体">脚本;因此,不便或不需写为服务脚本放置于</span><span style="font-family: Calibri">/etc/rc.d/init.d/</span><span style="font-family: 宋体">目录,且又想开机时自动运行的命令,可直接放置于</span><span style="font-family: Calibri">/etc/rc.d/rc.local</span><span style="font-family: 宋体">文件中;</span></p>
<p><span style="font-family: 宋体"><img src="https://img2020.cnblogs.com/blog/1394693/202008/1394693-20200825211321509-1524222880.png"></span></p>
<p>启动六个虚拟终端</p>
<p>tty1:2345:respawn: /sbin/mingetty tty1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p><span style="font-family: 宋体">只在</span>2345<span style="font-family: 宋体">级别启动原因:因为</span><span style="font-family: Calibri">1</span><span style="font-family: 宋体">级别不需要用户登录是单用户模式,</span><span style="font-family: Calibri">6</span><span style="font-family: 宋体">级别为重启</span></p>
<p>respawn<span style="font-family: 宋体">:当用户登出后,立即重启</span><span style="font-family: Calibri">/usr/sbin/mingetty</span><span style="font-family: 宋体">中的某一虚拟终端</span></p>
<p><span style="font-family: 宋体">注意:</span>mingetty<span style="font-family: 宋体">会调用</span><span style="font-family: Calibri">login</span><span style="font-family: 宋体">程序,</span><span style="font-family: Calibri">login</span><span style="font-family: 宋体">程序给用户提供一个登录界面,并验证账号密码信息&nbsp;</span></p>
<p>补充:</p>
<p>/etc/rc.d/rc.sysinit: <span style="font-family: 宋体">系统初始化脚本&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>(1) <span style="font-family: 宋体">设置主机名;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>(2) <span style="font-family: 宋体">设置欢迎信息;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>(3) <span style="font-family: 宋体">激活</span><span style="font-family: Calibri">udev</span><span style="font-family: 宋体">和</span><span style="font-family: Calibri">selinux; &nbsp;&nb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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
<p>(4) <span style="font-family: 宋体">挂载</span><span style="font-family: Calibri">/etc/fstab</span><span style="font-family: 宋体">文件中定义的文件系统;这就是以为什么该文件中定义设备会被开机自动挂载&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>(5) <span style="font-family: 宋体">检测根文件系统,并以读写方式重新挂载根文件系统;&nbsp;</span></p>
<p>(6) <span style="font-family: 宋体">设置系统时钟;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p>
<p>(7) <span style="font-family: 宋体">激活</span><span style="font-family: Calibri">swap</span><span style="font-family: 宋体">设备;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>(8) <span style="font-family: 宋体">根据</span><span style="font-family: Calibri">/etc/sysctl.conf</span><span style="font-family: 宋体">文件设置内核参数;&nbsp;</span></p>
<p>(9) <span style="font-family: 宋体">激活</span><span style="font-family: Calibri">lvm</span><span style="font-family: 宋体">及</span><span style="font-family: Calibri">software raid</span><span style="font-family: 宋体">设备;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p>
<p>(10) <span style="font-family: 宋体">加载额外设备的驱动程序;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>(11) <span style="font-family: 宋体">清理操作;&nbsp;</span><span style="font-family: 宋体">总结:</span>/sbin/init --&gt; (/etc/inittab) --&gt; <span style="font-family: 宋体">设置默认运行级别 </span><span style="font-family: Calibri">--&gt; </span><span style="font-family: 宋体">运行系统初始脚本、完成系统初始化 </span><span style="font-family: Calibri">--&gt; </span><span style="font-family: 宋体">关闭对应下需要关闭的服务,启动需要启动服务 </span><span style="font-family: Calibri">--&gt; </span><span style="font-family: 宋体">设置登录终端</span></p>
<h2><span style="font-family: 宋体">全部总结</span>--CentOS 6<span style="font-family: 宋体">启动流程:</span></h2>
<p>POST --&gt; Boot Sequence(BIOS) --&gt; Boot Loader (MBR) --&gt; Kernel(ramdisk) --&gt; rootfs --&gt; switchroot --&gt; /sbin/init --&gt;(/etc/inittab, /etc/init/*.conf) --&gt; <span style="font-family: 宋体">设定默认运行级别 </span><span style="font-family: Calibri">--&gt; </span><span style="font-family: 宋体">系统初始化脚本 </span><span style="font-family: Calibri">--&gt; </span><span style="font-family: 宋体">关闭或启动对应级别下的服务 </span><span style="font-family: Calibri">--&gt; </span><span style="font-family: 宋体">启动终端&nbsp;</span></p>
<p><span style="font-family: 宋体">&nbsp;</span></p>
<p><span style="font-family: 宋体">&nbsp;</span></p>
<p>&nbsp;</p>
<p><span style="font-family: 宋体">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/wxxjianchi/p/9879502.html
頁: [1]
查看完整版本: centos(linux)启动流程