歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習Linux

CentOS 系統啟動流程

CentOS 系統啟動流程


CentOS 系統啟動流程


CentOS 系統啟動流程
POST:加電自檢;
ROM:CMOS
BIOS:Basic Input and Output System

ROM+RAM

BOOT Sequence:
按次序查找各引導設備,第一個有引導程序的設備即為本次啟動用到設備;

bootloader: 引導加載器,程序
windows: ntloader
Linux:
LILO:LInux LOader
GRUB: GRand Uniform Bootloader
GRUB 0.X: GRUB Legacy
GRUB 1.x: GRUB2

功能:提供一個菜單,允許用戶選擇要啟動系統或不同的內核版本;把用戶選定的內核裝載到內存中的特定空間中,解壓、展開,並把系統控制權移交給內核;

MBR:
446: bootloader
64: fat
2: 55AA

GRUB:
bootloader: 1st stage
disk: 2nd stage

kernel:
自身初始化:
探測可識別到的所有硬件設備;
加載硬件驅動程序;(有可能會借助於ramdisk加載驅動)
以只讀方式掛載根文件系統;
運行用戶空間的第一個應用程序:/sbin/init

init程序的類型:
SysV: init, CentOS 5
配置文件:/etc/inittab

Upstart: init, CentOS 6
配置文件:/etc/inittab, /etc/init/*.conf

Systemd:systemd, CentOS 7
配置文件:/usr/lib/systemd/system, /etc/systemd/system

ramdisk:

內核中的特性之一:使用緩沖和緩存來回事對磁盤上的文件訪問;

ramdisk --> ramfs

CentOS 5: initrd, 工具程序:mkinitrd
CentOS 6: initramfs, 工具程序:mkinitrd, dracut

系統初始化:
POST --> BootSequence (BIOS) --> Bootloader(MBR) --> kernel(ramdisk) --> rootfs(只讀) --> init


/sbin/init

CentOS 5:

運行級別:為了系統的運行或維護等應用目的而設定;

0-6:7個級別
0:關機
1:單用戶模式(root, 無須登錄), single, 維護模式;
2: 多用戶模式,會啟動網絡功能,但不會啟動NFS;維護模式;
3:多用戶模式,正常模式;文本界面;
4:預留級別;可同3級別;
5:多用戶模式,正常模式;圖形界面;
6:重啟

默認級別:
3, 5

切換級別:
init #

查看級別:
runlevel
who -r

配置文件:/etc/inittab

每一行定義一種action以及與之對應的process
id:runlevel:action:process
action:
wait: 切換至此級別運行一次;
respawn:此process終止,就重新啟動之;
initdefault:設定默認運行級別;process省略;
sysinit:設定系統初始化方式,此處一般為指定/etc/rc.d/rc.sysinit;
...
[root@slave ~]# ll /etc/rc.d/
total 60
drwxr-xr-x. 2 root root 4096 Jan 29 2015 init.d
-rwxr-xr-x. 1 root root 2617 Oct 16 2014 rc
drwxr-xr-x. 2 root root 4096 Jan 31 2015 rc0.d
drwxr-xr-x. 2 root root 4096 Jan 31 2015 rc1.d
drwxr-xr-x. 2 root root 4096 Jan 31 2015 rc2.d
drwxr-xr-x. 2 root root 4096 Jan 31 2015 rc3.d
drwxr-xr-x. 2 root root 4096 Jan 31 2015 rc4.d
drwxr-xr-x. 2 root root 4096 Jan 31 2015 rc5.d
drwxr-xr-x. 2 root root 4096 Jan 31 2015 rc6.d
-rwxr-xr-x. 1 root root 259 Jul 31 00:53 rc.local
-rwxr-xr-x. 1 root root 19914 Oct 16 2014 rc.sysinit

id:3:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
...
l6:6:wait:/etc/rc.d/rc 6

說明:rc 0 --> 意味著讀取/etc/rc.d/rc0.d/
K*: K##*:##運行次序;數字越小,越先運行;數字越小的服務,通常為依賴到別的服務;
S*: S##*:##運行次序;數字越小,越先運行;數字越小的服務,通常為被依賴到的服務;

for srv in /etc/rc.d/rc0.d/K*; do
$srv stop
done

for srv in /etc/rc.d/rc0.d/S*; do
$srv start
done
[root@slave ~]# ll /etc/rc.d/init.d/
total 356
-rwxr-xr-x. 1 root root 1288 Oct 16 2014 abrt-ccpp
-rwxr-xr-x. 1 root root 1628 Oct 16 2014 abrtd
-rwxr-xr-x. 1 root root 1642 Oct 16 2014 abrt-oops
-rwxr-xr-x. 1 root root 1725 Aug 18 2010 acpid
-rwxr-xr-x. 1 root root 2062 Jan 30 2012 atd
-rwxr-xr-x. 1 root root 3580 Oct 15 2014 auditd
-r-xr-xr-x. 1 root root 1340 Oct 15 2014 blk-availability
-rwxr-xr-x. 1 root root 710 Nov 10 2010 bluetooth
-rwxr-xr-x. 1 root root 11355 Aug 13 2013 cpuspeed
-rwxr-xr-x. 1 root root 2826 Nov 23 2013 crond
-rwxr-xr-x. 1 root root 3034 Oct 15 2014 cups
-rwxr-xr-x. 1 root root 1734 Jun 16 2014 dnsmasq
-rwxr-xr-x. 1 root root 3245 Jul 9 2013 firstboot
-rw-r--r--. 1 root root 19295 Jul 22 2014 functions
-rwxr-xr-x. 1 root root 1801 Oct 15 2014 haldaemon
-rwxr-xr-x. 1 root root 5866 Jul 22 2014 halt
-rwxr-xr-x. 1 root root 2001 Oct 16 2014 htcacheclean
-rwxr-xr-x. 1 root root 3371 Oct 16 2014 httpd
-rwxr-xr-x. 1 root root 10804 Oct 15 2014 ip6tables
-rwxr-xr-x. 1 root root 10688 Oct 15 2014 iptables
-rwxr-xr-x. 1 root root 1938 Jun 2 2014 irqbalance
-rwxr-xr-x 1 root root 9980 Dec 18 2014 jexec
-rwxr-xr-x. 1 root root 19476 Oct 15 2014 kdump
-rwxr-xr-x. 1 root root 652 Jul 22 2014 killall
-r-xr-xr-x. 1 root root 2134 Oct 15 2014 lvm2-lvmetad
-r-xr-xr-x. 1 root root 2757 Oct 15 2014 lvm2-monitor
-rwxr-xr-x. 1 root root 2571 Sep 4 2014 mdmonitor
-rwxr-xr-x. 1 root root 2200 Sep 13 2012 messagebus
-rwxr-xr-x. 1 root root 2989 Jul 22 2014 netconsole
-rwxr-xr-x. 1 root root 6064 Jul 22 2014 netfs
-rwxr-xr-x. 1 root root 6334 Jul 22 2014 network
-rwxr-xr-x. 1 root root 2205 Oct 15 2014 NetworkManager
-rwxr-xr-x. 1 root root 1923 Jul 15 2013 ntpd
-rwxr-xr-x. 1 root root 2043 Jul 15 2013 ntpdate
-rwxr-xr-x. 1 root root 2023 Apr 3 2012 portreserve
-rwxr-xr-x. 1 root root 3912 Feb 20 2014 postfix
-rwxr-xr-x. 1 root root 1556 Jul 17 2012 psacct
-rwxr-xr-x. 1 root root 2034 Mar 5 2014 quota_nld
-rwxr-xr-x. 1 root root 1513 Sep 17 2013 rdisc
-rwxr-xr-x. 1 root root 1822 Oct 15 2014 restorecond
-rwxr-xr-x. 1 root root 1808 Dec 17 2011 rngd
-rwxr-xr-x. 1 root root 2011 Aug 15 2013 rsyslog
-rwxr-xr-x. 1 root root 1698 Oct 15 2014 sandbox
-rwxr-xr-x. 1 root root 2056 Jun 23 2014 saslauthd
-rwxr-xr-x. 1 root root 647 Jul 22 2014 single
-rwxr-xr-x. 1 root root 3002 Feb 21 2013 smartd
-rwxr-xr-x. 1 root root 2162 Sep 14 2014 snmpd
-rwxr-xr-x. 1 root root 1738 Sep 14 2014 snmptrapd
-rwxr-xr-x. 1 root root 2472 Oct 15 2014 spice-vdagentd
-rwxr-xr-x. 1 root root 4621 Oct 15 2014 sshd
-rwxr-xr-x. 1 root root 1144 Oct 16 2014 sysstat
-rwxr-xr-x. 1 root root 2294 Oct 15 2014 udev-post
-rwxr-xr-x. 1 root root 39800 Jan 27 2015 vmware-tools
-rwxr-xr-x. 1 root root 15208 Jan 27 2015 vmware-tools-thinprint
-rwxr-xr-x. 1 root root 1674 Feb 21 2013 wdaemon
-rwxr-xr-x. 1 root root 1608 Oct 15 2014 winbind
-rwxr-xr-x. 1 root root 1866 Feb 4 2013 wpa_supplicant
chkconfig命令
查看服務在所有級別的啟動或關閉設定情形:
chkconfig [--list] [name]
[root@slave ~]# chkconfig --level 3 NetworkManager on
[root@slave ~]# chkconfig --list
[root@slave ~]# chkconfig --level 3 NetworkManager off
添加:
SysV的服務腳本放置於/etc/rc.d/init.d (/etc/init.d)

chkconfig --add name

#!/bin/bash
#
# chkconfig: LLLL nn nn
chkconfig: 2345 10 90
刪除:
chkconfig --del name

修改指定的鏈接類型
chkconfig [--level levels] name <on|off|reset>
--level LLLL: 指定要設置的級別;省略時表示2345;

注意:正常級別下,最後啟動一個服務S99local沒有鏈接至/etc/rc.d/init.d一個服務腳本,而是指向了/etc/rc.d/rc.local腳本;因此,不便或不需寫為服務腳本放置於/etc/rc.d/init.d/目錄,且又想開機時自動運行的命令,可直接放置於/etc/rc.d/rc.local文件中;
[root@slave ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Jan 27 2015 /etc/rc.local -> rc.d/rc.local

tty1:2345:respawn:/usr/sbin/mingetty tty1
tty2:2345:respawn:/usr/sbin/mingetty tty2
...
tty6:2345:respawn:/usr/sbin/mingetty tty6

mingetty會調用login程序

/etc/rc.d/rc.sysinit: 系統初始化腳本
(1) 設置主機名;
(2) 設置歡迎信息;
(3) 激活udev和selinux;
(4) 掛載/etc/fstab文件中定義的文件系統;
(5) 檢測根文件系統,並以讀寫方式重新掛載根文件系統;
(6) 設置系統時鐘;
(7) 激活swap設備;
(8) 根據/etc/sysctl.conf文件設置內核參數;
(9) 激活lvm及software raid設備;
(10) 加載額外設備的驅動程序;
(11) 清理操作;

總結:/sbin/init --> (/etc/inittab) --> 設置默認運行級別 --> 運行系統初始腳本、完成系統初始化 --> 關閉對應下需要關閉的服務,啟動需要啟動服務 --> 設置登錄終端

http://xxxxxx/Linuxjc/1156022.html TechArticle

Copyright © Linux教程網 All Rights Reserved