【就业班作业】【第九周】3、简述linux操作系统启动流程---CentOS7的启动流程

CentOS7的启动流程:
第一步,POST(Power On Self Test),加电自检
CPU、内存、硬盘、显卡、IO等硬件初始化检查;

BIOS中设置要查看到自检过程,如下:

 效果图,如下:

 第二步,BIOS启动顺序

  设置启动顺序,检测驱动器,光驱、硬盘、网络、U盘等驱动器;

BIOS中设置驱动器启动顺序,如下:

第三步,如果是硬盘启动

读取硬盘的MBR(加载第1个扇区512字节到内存):512=BootLoader(446)+分区表(16)+MBR标识位0xAA55(2);
  Bootloader程序主要有:windows的ntloader或Bootmgr;linux的grub或grub2程序;
  加载完bootloader(已安装/boot/grub/stage1)后,控制权并转给grub这个引导程序;

第四步,grub2引导

stage1,放在MBR中,准备内存空间,再读取载入stage1.5多个文件;
stage1.5,放在MBR区域后紧跟的基本磁盘分区/boot里,本阶段可识别启动分区的文件系统,于是并载入/boot/grub/stage2;
stage2,载入时读取/grub2/grub.cfg;显示操作系统类别菜单,可为下一步指定只读方式内核(/boot/vmlinuz)、虚拟磁盘文件(/boot/initramfs)、真正根的分区位置等多个配置参数,回车后加载内核、内核参数、开机选项、多模块等,并将控制权转给内核;
grub.cfg文件内容:
[root@localhost boot]# ll /boot/grub2/grub.cfg 
-rw-r--r--. 1 root root 4257 Sep  8 17:48 /boot/grub2/grub.cfg
[root@localhost boot]# cat grub2/grub.cfg 
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub

grub.cfg配置文件开头注释部分说明了由/etc/grub.d/目录下文件和/etc/default/grub文件组成。
[root@localhost boot]# ll /etc/grub.d/
total 72
-rwxr-xr-x. 1 root root  8702 Aug  8  2019 00_header
-rwxr-xr-x. 1 root root  1043 Mar 22  2019 00_tuned
-rwxr-xr-x. 1 root root   232 Aug  8  2019 01_users
-rwxr-xr-x. 1 root root 10781 Aug  8  2019 10_linux
-rwxr-xr-x. 1 root root 10275 Aug  8  2019 20_linux_xen
-rwxr-xr-x. 1 root root  2559 Aug  8  2019 20_ppc_terminfo
-rwxr-xr-x. 1 root root 11169 Aug  8  2019 30_os-prober
-rwxr-xr-x. 1 root root   214 Aug  8  2019 40_custom
-rwxr-xr-x. 1 root root   216 Aug  8  2019 41_custom
-rw-r--r--. 1 root root   483 Aug  8  2019 README
[root@localhost boot]# 
[root@localhost boot]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[root@localhost boot]# 

修改完/etc/default/grub后,执行
grub2-mkconfig -o /boot/grub2/grub.cfg,将配置文件重新生成。

第五步,kernal引导

1、只读方式加载内核里的根,启动伪根里的systemd初始进程,探测硬件,加载驱动模块(内核才能识别真正的根);(/boot/kernal加载)
2、切换到真正的根(switchroot);然后启动真实根里的初始化程序(/usr/lib/systemd/systemd);此时控制权转给真正的初始化进程/usr/lib/systemd/systemd;(/boot/initramfs加载))

第六步,系统(systemd)初始化

读取默认target(运行级别)配置文件:
default.target 软链接指向/lib/systemd/system/里面某个target或runlevel#.targetls -l /etc/systemd/system/default.target
  lrwxrwxrwx. 1 root root 37 Sep 8 17:47 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target /etc/systemd/system/multi-user.target.wants //对应multi-user
/usr/lib/systemd/system/basic.target /usr/lib/systemd/system/sysinit.target (local-fs.target、swap.target /etc/fstab) getty.target //终端启动

第七步,终端启动

纯文本终端(/sbin/mingetty启动6个tty),验证登录、加载用户脚本、环境变量等
    验证登录:*/etc/nologin、/etc/usertty、/etc/securetty、/etc/passwd、/etc/shadow
    console登录时提示:/etc/issue
    登录成功提示:/var/log/lastlog、/var/spool/mail/、/etc/motd
    环境变量:/etc/profile、~/.bash_profile、~/.bash_login、~/.profile
  x-window等
    graphical.target,开启图形界面。

 (结束)

posted @ 2020-09-28 16:46  sankeya  阅读(211)  评论(0编辑  收藏  举报