運維工程師面試必須掌握的服務器開機啟動過程
文章目錄

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小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。