Linux系统中启动的流程:

1.加载bios的硬件信息以及进行自我检测  并根据设置取得第一个启动的设备

2.若以硬盘方式引导  读取并执行引导扇区 MBR

3.加载grub(引导程序)启动菜单(/\)

4.+加载内核(以只读方式进行挂载)

5.挂载根目录系统  启动init进程(所有进程的鼻祖)

6.读取/etc/inittab配置文件

7.执行/etc/rc.d/rc.sysint脚本

8.根据/etc/initab文件下的启动级别执行/etc/rc.d/rc下的脚本

9.执行/etc/rc.d/rc.local (开机脚本  期望开机自动执行的指令可以放在这个脚本里)

 

分析/etc/inittab文件

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 1 #

  2 # inittab       This file describes how the INIT process should set up

  3 #               the system in a certain run-level.

  4 #

  5 # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>

  6 #               Modified for RHS Linux by Marc Ewing and Donnie Barnes

  7 #

  8 

  9 # Default runlevel. The runlevels used by RHS are:

 10 #   0 - halt (Do NOT set initdefault to this)  #10-16行指的是启动级别)#关机

 11 #   1 - Single user mode#单用户模式  通常用于维护系统

 12 #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)

     #多用户模式 但是无网络

 13 #   3 - Full multiuser mode#多用户模式(字符界面)

 14 #   4 - unused#用户定义  ,未定义情况下与3级别相同

 15 #   5 - X11#图形界面

 16 #   6 - reboot (Do NOT set initdefault to this)#系统重启

 17 # 

 18 id:3:initdefault:

#第一列表示表示怎么表示无所谓    第二列表示启动级别  第三列表示动作  第四列     

表示参数   如果级别列无任何标示表示任何级别    该句话表示默认启动级别为三

 19 

 20 # System initialization.

 21 si::sysinit:/etc/rc.d/rc.sysinit

#参考十八行  第一列表示标示   第二列无表示 代表进入任何级别都要执行该指令    第三行表示动作  表示进行初始化   第四行表示执行/etc/rc.d/rc.sysinit 脚本  

 22 

 23 l0:0:wait:/etc/rc.d/rc 0

 24 l1:1:wait:/etc/rc.d/rc 1

24 l1:1:wait:/etc/rc.d/rc 1

 25 l2:2:wait:/etc/rc.d/rc 2

 26 l3:3:wait:/etc/rc.d/rc 3

 27 l4:4:wait:/etc/rc.d/rc 4

 28 l5:5:wait:/etc/rc.d/rc 5

 29 l6:6:wait:/etc/rc.d/rc 6

#参考十八行   最后一个数字表示将此数字传递给 /etc/rc.d/rc脚本

如传递3  那么就会执行/etc/rc.d/rc3.d  

 30 

 31 # Trap CTRL-ALT-DELETE

 32 ca::ctrlaltdel:/sbin/shutdown -t3 -r now

  #参考十八行 表示在任何级别下都可以使用ctrl+alt+del 执行/sbin/shutdown -r 表示关机并重新启动系统默认三秒后立即执行 

 33 

 34 # When our UPS tells us power has failed, assume we have a few minutes

 35 # of power left.  Schedule a shutdown for 2 minutes from now.

 36 # This does, of course, assume you have powerd installed and your

 37 # UPS connected and working correctly.  

 38 pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

#系统断电后 执行/sbin/shutdown -h表示关机之后不重新启动  -f表示重新启动不执行fsck 2分钟之后执行  并显示 提示信息

 39 

 40 # If power was restored before the shutdown kicked in, cancel it.

 41 pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

#电力恢复之后取消已经运行的shutdown指令  并提示信息

 42 

 43 

 44 # Run gettys in standard runlevels

 45 1:2345:respawn:/sbin/mingetty tty1

 46 2:2345:respawn:/sbin/mingetty tty2

 47 3:2345:respawn:/sbin/mingetty tty3

 48 4:2345:respawn:/sbin/mingetty tty4

 49 5:2345:respawn:/sbin/mingetty tty5

 50 6:2345:respawn:/sbin/mingetty tty6

#/sbin/mingetty  表示产生字符终端  共六个字符终端  respawn表示再生的意思  即当前的终端注销后  仍然在一个终端里

 51 

 52 # Run xdm in runlevel 5

 53 x:5:respawn:/etc/X11/prefdm -nodaemon

~                                                                                                                                     

~-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

~启动故障:

可分为两大阶段:

1.系统引导扇区MBR出现问题

2.Grub菜单出现问题

1.模拟MBR扇区出现故障

创建一个文件覆盖整个硬盘

[root@localhost ~]# dd  if=/dev/zero  of=/dev/sda   bs=446  count=1

161444268.png

MBR扇区被覆盖 引导程序抹掉了

161520107.png

解决方式:

重建MBR用可安装光盘引导

161602784.png

在此界面下进入急救模式 输入linux  resuce  

161705869.png

选择语言

161755141.png

鼠标键盘类型

161828888.png

                                               是否启动网络功能  没有必要

161906576.png

                                                   关于急救模式的提示硬盘将会挂载在/mnt/p_w_picpath

162013950.png

提示将./mnt/sysp_w_picpath当做系统根目录  使用chroot指令指定硬盘的根目录  #chroot   /mnt/sysp_w_picpath

162203841.png

             修复分区表  执行grup指令  #grub

162205323.png

 1.先指明引导系统  执行root指令

          #root hd0,0)  (第一块硬盘,第一块分区)

162207818.png

2.执行setup可以帮助重新建mbr  #setuo  hd0

162209437.png

执行一次quit两次exit系统进行重新启动

162211255.png

二.GRUB引导菜单出现故障

查看/boot/grub

[root@localhost ~]# ll /boot/grub

162610144.png

在所有文件中最为重要的是grub.conf文件

162612832.png

----------------------------------------------------------------------------------------------------------------------

 1 # grub.conf generated by anaconda

  2 #

  3 # Note that you do not have to rerun grub after making changes to this file

  4 # NOTICE:  You have a /boot partition.  This means that

  5 #          all kernel and initrd paths are relative to /boot/, eg.

  6 #          root (hd0,0)

  7 #          kernel /vmlinuz-version ro root=/dev/sda2

  8 #          initrd /initrd-version.img

  9 #boot=/dev/sda

 10 default=0  #默认操作系统

 11 timeout=5#超时时间5s

 12 splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz#grub菜单背景图片

 13 hiddenmenu

 14 title Red Hat Enterprise Linux Server (2.6.18-164.el5)#标签

 15         root (hd0,0)#引导分区MBR

 16         kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet

#内核文件位置  以只读方式进行 系统启动后根目录变成文件系统的根   quiet静默

 17         initrd /initrd-2.6.18-164.el5.img  #驱动

 

故障一.

故障1.删除grub.conf

[root@localhost ~]# rm  /boot/grub/grub.conf

rm: remove regular file `/boot/grub/grub.conf'? y

[root@localhost ~]# cd  /boot/grub  

162842718.png

重启

163032953.png

Grub直接启动表明第二阶段有问题

       指明引导分区 #root hd0,0)  (第一块硬盘,第一块分区)

163034681.png

grub>help  可以查看可以执行的指令

163036754.png

        查看根目录grup > find /

163038418.png

执行  kernel  /vmlinuz-2.6-164.e15  ro  root=/dev/sda2 quit

    Initrd /initrd-2.6.18-164.e15.img

163040352.png

执行完成后启动   grub>boot

163042715.png

启动完成

进入系统后使用grub-install产生二阶段的其他文件

--------------------------------------------------------------------------------

[root@localhost ~]# grub-install

install_device not specified.

Usage: grub-install [OPTION] install_device

Install GRUB on your drive.

 

  -h, --help              print this message and exit

  -v, --version           print the version information and exit

  --root-directory=DIR    install GRUB p_w_picpaths under the directory DIR

     #指明这些文件的目录

                          instead of the root directory

  --grub-shell=FILE       use FILE as the grub shell

  --no-floppy             do not probe any floppy drive

  --force-lba             force GRUB to use LBA mode even for a buggy

                          BIOS

  --recheck               probe a device map even if it already exists

                          This flag is unreliable and its use is

                          strongly discouraged.

 

INSTALL_DEVICE can be a GRUB device name or a system device filename.

 

grub-install copies GRUB p_w_picpaths into the DIR/boot directory specfied by

--root-directory, and uses the grub shell to install grub into the boot

sector.

 

Report bugs to <bug-grub@gnu.org>.

[root@localhost ~]# grub-install  --root-directory=/boot/grub  /dev/sda

Grub.conf 文件丢失需重新编写

163614451.png

重启:

163616745.png

故障二  /boot目录下的所有内容被删

a.删除/boot下的所有内容   rm   -rf  /boot/*

163936140.png

b.重启

163938344.png

c.进入bios设置  将光驱设置为首先启动

163940529.png

d.进入救援模式:linux  rescue

163942882.png

e.使用chroot指令切换到硬盘的目录  Chroot  /mnt/sysp_w_picpath

163945435.png

f.切换到boot目录并查看内容   cd  /boot && ls

163947850.png

g.挂载光驱  Mount     /dev/hdc  /mnt

163949515.png

h.安装内核  内核安装完成后会自动安装initrd

Rpm  -ivh  --force  /mnt/Server/kernel-2.6.18-164.e15.i686.rpm

163951560.png

i.内核安装完成之后我们安装grub    grub-install   /dev/sda

163953511.png

j.再次查看/boot目录下的内容

163955863.png

k.查看grub的内容发现缺少grub.conf  重新编写grub.conf

 #cd  /boot/grub/    #touch   grub.conf   #vim grub.conf 

 

164026910.png

164028858.png

164030829.png

l.两次exit退出重启  重启要设置bios为硬盘启动

164032132.png

故障三 删除了/grub下的内容

依据故障二重复第a.c.e.j.l即可

故障四:文件系统表改变   

                       vim  /etc/fstab

165420358.png

如果误操作其中一个例如

165422786.png

重新启动后会出现

165424102.png

输入管理员密码

165426244.png

编辑vim  /etc/fstab

165428599.png

  重新挂载 mount -o remount  /  然后再编辑

165430343.png

重启

165432823.png

165435967.png