admin@80vps.com
联系我们
QQ:1668121212
CN
Cn
En
邮件订阅
服务条款
优惠促销
会员中心
Toggle navigation
站群服务器
香港站群
美国站群
日本站群
韩国站群
新加坡站群
国内云主机
景安多线
四川双线云主机
上海电信
华为云
香港服务器
香港Cera高防
香港PowerLine
香港Pangnet
香港BGP大带宽
沙田大带宽
香港九龙
香港大浦
亚太服务器
越南服务器
韩国优化
韩国首尔
日本CIA
日本CN2
日本精品
新加坡
欧美及高防
洛杉矶MC
凤凰城IF
洛杉矶Cera高防
洛杉矶SK高防
VPS主机
亚太VPS列表
新加坡SG
日本CTG
香港CTG
韩国BGP
香港CI
欧美VPS列表
美国Cera
美国MC
帮助中心
账户管理
用户注册
登录验证
购买结算
充值汇款
新购续费
退款处理
VPS购买及使用
常用下载
VPS云服务器介绍
用户操作指南
Linux操作指南
Windows操作指南
产品介绍
常用下载
PHP源码
ASP源码
在线工具
推广
本月特价
CentOS 系统启动流程
浏览次数:2163 关键词 (
系统启动
流程
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) --> 设置默认运行级别 --> 运行系统初始脚本、完成系统初始化 --> 关闭对应下需要关闭的服务,启动需要启动服务 --> 设置登录终端