系统启动流程
大致过程如下
- 加电自检,检查硬件是否正常;MBR引导MBR前446个字节属于grub的属于第一阶段,后续需要加载grub的1.5阶段,1.5阶段存在硬盘的后续扇区中,加载1.5阶段识别boot分区的文件系统加载/boot分区文件系统驱动;挂载boot分区进入grub的第二阶段对应的/boot/grub目录下有grub.config此文件中定义内核的路径,与“/”所在的分区还定义了initrd-2.6.18-308.el5.img (5)initramfs-2.6.32-696.el6.x86_64.img(6)此文件的路径而且此文件存放部分驱动;通过此文件的驱动加载操作系统的“/”;进入/后运行系统第一个进程/sbin/init;找一些系统的配置文件,加载一些文件后用户可以登陆界面了
-启动进程首先读取/etc/inittab文件,5和6不一样;6用的inittab文件以不是inittab文件时upstart
centos5 /etc/inittab文件
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level. #描述了init进程如何在不同的模式下启动系统的
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#作者
# Default runlevel. The runlevels used by RHS 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:5:initdefault: 默认登陆的模式;这里表示5;生产环境建议把5改成3 id表示唯一标示
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit 进入模式前必须先运行此脚本的脚本
下面定义了什么模式下运行什么样的脚本
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
# Trap CTRL-ALT-DELETE
# ca::ctrlaltdel:/sbin/shutdown -t3 -r now 建议把此行注释掉因为此行带表 CTRL-ALT-DELETE 表示关机*****centos6防止此组合键关机可以应更改此文件
***********************************************************************************
[root@chenxi ~]# cat /etc/init/control-alt-delete.conf
# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed. Usually used to shut down the machine.
#
# Do not edit this file directly. If you want to change the behaviour,
# please create a file control-alt-delete.override and put your changes there.
start on control-alt-delete
exec /sbin/shutdown -r now "Control-Alt-Delete pressed" 注释此行
***********************************************************************************
# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down" 表示突然停电靠备用电池给系统上的一些服务发两分钟我要关机
# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
如果突然有恢复电源系统将会发送取消关机并发生消息
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1 #respawn 表示进程死掉冲新激活
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6 这里可以设置支持更多的终端
# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon 这里定义了为什么5模式经拉起就是图形界面
centos6 inittab配置文件
/etc/inittab文件
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.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:5:initdefault:
centos6