标签:系统引导
系统引导过程:POST(Power On Self Test) 硬件检测没有问题后,如果是硬盘引导会找到MBR(bootloader:446字节),通过MBR来找到/boot所在的分区并加载M,需要加载boot目录所在的分区,boot目录所在的分区是放在文件系统中的,要加载boot分区就需要驱动,initramfs中保存的是/文件系统的驱动
需要有模板文件,才可以使用以下修复
grub> root (hd0,0)
grub> setup (hd0)
系统引导过程:
1.POST(Power On Self Test) 硬件自检
2.读取MBR(bootloader:446字节 磁盘分区:64字节 分区标志位:2字节(55AA))
通过读取MBR中的将bootloader加载至内存,而该bootloader的程序通常就是Grub,
Grub主要的功能加载系统内核(进入操作系统提示的菜单选项),而内核在boot分区上,可以通过分区表查找到boot分区(因为安装操作系统前需要创建/boot分区),并将/boot/vmlinuz-2.6.32-696.el6.x86_64内核文件解压缩并加载内核,内核加载内存后需要引导操作系统(内核并没有包含所有的驱动包,所以/boot/initramfs-2.6.32-696.el6.x86_64.img就是提供操作系统驱动的另一个文件,内部包含文件系统的驱动),而操作系统的/文件系统的驱动程序在initramfs中,而访问initramfs又需要先存在操作系统,于是便有了通过虚拟的文件系统来引导,即initramfs中存在一个虚拟文件系统可以加载/分区,进而找到/sbin/init程序来加载文件系统
补充: 查看initramfs-2.6.32-696.el6.x86_64.img文件内容的办法:
首先 # file initramfs-2.6.32-696.el6.x86_64.img 查看文件类型是gzip压缩文件,压缩文件在解压缩时需要查看文件的后缀名,所以先要修改文件的后缀名为.gz。
1.mv initramfs-2.6.32-696.el6.x86_64.img initramfs-2.6.32-696.el6.x86_64.gz
2.gunzip initramfs-2.6.32-696.el6.x86_64.img 解压缩
3.file initramfs-2.6.32-696.el6.x86_64 发现文件的类型为cpio压缩类型
4.cpio -tv < initramfs-2.6.32-696.el6.x86_64 查看压缩文件内部内容
5.cpio -idv < initramfs-2.6.32-696.el6.x86_64 解压缩文件至当前文件夹
通过查看iinitramfs-2.6.32-696.el6.x86_64内容会发现里面的目录结构类似与操作系统的目录结构,并且存在大量的ko后缀的库文件,包括用于加载/文件系统的驱动
REHL5的/etc/initab配置文件
********************************************************************************************
[root@station1 grub]# cat /etc/inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# 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:
# 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
# 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" #UPS电源在失败前发送的警告信息,提示用户2分钟后关机
# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled" #如果UPS电源在关机前修复发送消息提示用户“电源恢复,关机取消”
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
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
********************************************************************************************************
3.加载文件系统以后尝试驱动所有的硬件设备并执行/sbin/init程序,获取默认的运行信息(id:5:initdefault:)
4.init程序执行/etc/rc.d/rc.sysinit
si::sysinit:/etc/rc.d/rc.sysinit
5.启动核心的服务模块,如运行界别为3,则找到/etc/rc.d/rc3.d下面启动服务模块
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
([root@station1 rc3.d]# pwd
/etc/rc.d/rc3.d
[root@station1 rc3.d]# ls
K01dnsmasq K24irda K74ntpd K89rdisc S08iptables S13portmap S25netfs S55sshd S95anacron
K02avahi-dnsconfd K35vncserver K80kdump K91capi S08mcstrans S14nfslock S25pcscd S56cups S95atd
K02NetworkManager K35winbind K85mdmpd K99readahead_later S09isdn S15mdmonitor S26acpid S56rawdevices S97rhnsd
K05conman K50netconsole K87multipathd S02lvm2-monitor S10network S18rpcidmapd S26apmd S56xinetd S97yum-updatesd
K05saslauthd K69rpcsvcgssd K88wpa_supplicant S04readahead_early S11auditd S19rpcgssd S26haldaemon S80sendmail S98avahi-daemon
K05wdaemon K73ypbind K89dund S05kudzu S12restorecond S22messagebus S26hidd S85gpm S99firstboot
K10psacct K74ipmi K89netplugd S06cpuspeed S12syslog S23setroubleshoot S28autofs S90crond S99local
K20nfs K74nscd K89pand S08ip6tables S13irqbalance S25bluetooth S50hplip S90xfs S99smartd
)
K(Kill)开头的文件,表示服务是默认不启动的,S(Start)开头文件,表示该服务默认是启动的,标志位后面的数字是启动服务或是关闭服务的顺序
6.启动至最后服务会发现S99local 执行的是另外的一个可执行脚本,与其他服务不同
[root@station1 ~]# ll /etc/rc.d/rc3.d/
lrwxrwxrwx 1 root root 11 Nov 2 2010 S99local -> ../rc.local #指向父目录的rc.local文件
lrwxrwxrwx 1 root root 16 Nov 2 2010 S99smartd -> ../init.d/smartd #指向父目录的init.d下面的smatd服务脚本
[root@station1 ~]# 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
Centos7中需要手动为该文件添加执行权限,Centos6默认有执行权限,可以编辑该脚本来让脚本在开机前执行
7.执行/bin/login程序,等待用户登录
1:2345:respawn:/sbin/mingetty tty1
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
respawn(再生), /sbin/mingetty登录终端不能被kill
标签:系统引导
原文地址:http://blog.51cto.com/9980200/2114813