运维工程师面试必须掌握的服务器开机启动过程

网友投稿 711 2022-05-28

文章目录

Centos 6 系统启动过程

Centos 6系统开机过程总结

Centos 6 启动相关配置文件

Centos 7 系统启动过程

CentOS7引导顺序

总结:

Centos 6 系统启动过程

加载 BIOS 的硬件信息,跟据设定取得第一个可开机引导设置,如:光驱,硬盘,网络,USB; 如果是硬盘为第一引导。

读取硬盘中 MBR 的 boot Loader 就是 grub引导

依据 boot loader 的设定,到引导分区加载 Kernel ,Kernel 会开始侦测硬件并加载驱劢程序;

在硬件驱动成功后,Kernel 会主动执行 init 程序,而 init 会取得 run-level 信息;

init 执行 /etc/rc.d/rc.sysinit 文件来准备软件执行的作业环境 (如网络、时区等);

init 执行 run-level 下各个服务并启动 (script 方式);

init 执行开机后自动运行脚本 /etc/rc.d/rc.local 文件;

init 执行虚拟终端机控制程序 mingetty 来启动 login 程序,最后就等待用户登入啦;

图:

Centos 6系统开机过程总结

开机自检–BIOS

MBR引导

GRUB菜单

加载内核

运行INIT进程

读取/etc/inittab配置文件

执行脚本

启懂mingetty进程,进入登录界面

centos 5 、6开机过程差不多的

Centos 6 启动相关配置文件

[root@localhost ~]# vim /boot/grub/grub.conf default=0 # 设定默认启动菜单项,当系统中有多个内核时,0表示默认加载第1个,1表示第2个内核 timeout=5 # 菜单项等待选项时间为5s splashimage=(hd0,0)/grub/splash.xpm.gz # 指明菜单背景图片路径为 hiddenmenu # 隐藏菜单 title Red Hat Enterprise Linux (2.6.32-431.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-431.el6.x86_64.img # 内核匹配的ramfs文件

1

2

3

4

5

6

7

8

9

10

11

修改系统启动级别:

/etc/rc.d/rc.sysinit shell脚本 作用:系统初始化: 像:主机名 和/etc/fstab 都在这里指定了,完成了包括mount分区 激活swap 加载modules等重要的工作.

[root@localhost ~]# vim /etc/inittab # Individual runlevels are started by /etc/init/rc.conf # # # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # # Default runlevel. The runlevels used are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:3:initdefault: #这里决定系统启动的级别 ~

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

运维工程师面试必须掌握的服务器开机启动过程

启动对应级别下的服务如: init 3 级别

/etc/rc.d/rc3.d/(这里的程序/服务S开头的全部开机执行;K开头的表示开机不执行,表明了关机时顺序)

lrwxrwxrwx. 1 root root 11 Mar 12 20:03 /etc/init.d -> rc.d/init.d [root@localhost ~]#

1

2

3

[root@localhost ~]# ll /etc/rc.d/rc3.d/|grep network lrwxrwxrwx. 1 root root 17 Mar 12 20:04 S10network -> ../init.d/network [root@localhost ~]# #表示network是第10个启动的服务。 所以init是顺序启动系统,需要一个一个服务启动成功,再执行下一步操作,启动系统比较慢。而centos7中的systemd可以并行启动多个服务,启动比较快。

1

2

3

4

[root@localhost ~]# vim /etc/init.d/network # chkconfig: 2345 10 90 #b表示2345 转态是启动的,10 启动顺气,90关闭顺序 # start at boot time.

1

2

3

[root@localhost ~]# chkconfig --list |grep network #过滤开启启动的网络 network 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@localhost ~]# [root@localhost ~]# chkconfig network off #关闭开机自动启 [root@localhost ~]#

1

2

3

4

5

6

7

所有服务都运行成功后,设置开机自动执行某个命令: /etc/rc.local

[root@localhost ~]# cat /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local /bin/nginx start #开机自动运行某个命令 [root@localhost ~]#

1

2

3

4

5

6

7

8

9

10

11

Centos 7 系统启动过程

CentOS7引导顺序

UEFi或BIOS初始化,运行POST开机自检

选择启动设备

引导装载程序 centos7是grub2

加载装载程序的配置文件

/etc/grub.d/ /etc/default/grub /boot/grub2/grub.cfg

加载内核选项

加载initramfs初始化伪文件系统

内核初始化,centos7使用systemd代替init

执行initrd.target所有单元,包括挂载/etc/fstab

从initramfs根文件系统切换到磁盘根目录

systemd执行默认target配置,配置文件/etc/systemd/system/default.target

systemd执行sysinit.target初始化系统及basic.target准备操作系统

systemd启动multi-user.target下的本机与服务器服务

systemd执行multi-user.target下的/etc/rc.d/rc.local

Systemd执行multi-user.target下的getty.target及登录服务

systemd执行graphical需要的服务

图片

总结:

如果需要图中的思维导图,可以打开以下链接,下载:

https://download.csdn.net/download/weixin_42313749/12245342

https://download.csdn.net/download/zj15527620802/11435203

CentOS 运维

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:更改文字、图片和视频大小(缩放)
下一篇:华为云免备案服务器
相关文章