您的位置:首页 > 运维架构 > Linux

系统启动流程及常见故障排除

2013-08-05 12:58 543 查看
Linux系统中启动的流程:1.加载bios的硬件信息以及进行自我检测 并根据设置取得第一个启动的设备2.若以硬盘方式引导 读取并执行引导扇区 MBR3.加载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 124 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


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


无法引导 解决方式:重建MBR用可安装光盘引导


在此界面下进入急救模式输入linux resuce 或者按F5








是否启动网络功能不必要


关于急救模式的提示 系统将会被挂载在/mnt/sysimage 下


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


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


1.先指明引导系统 执行root指令 #root (hd0,0) (第一块硬盘,第一块分区)


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


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


已经启动2.GRUB引导菜单出现故障


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


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

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 splashimage=(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.confrm: remove regular file `/boot/grub/grub.conf'? y[root@localhost ~]# cd /boot/grub

重启

Grub直接启动表明第二阶段有问题 指明引导分区 #root (hd0,0) (第一块硬盘,第一块分区)

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

查看根目录grup > find /

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

执行完成后启动Boot

启动完成进入系统后使用grub-install产生二阶段的其他文件--------------------------------------------------------------------------------[root@localhost ~]# grub-installinstall_device not specified.Usage: grub-install [OPTION] install_deviceInstall GRUB on your drive. -h, --help print this message and exit -v, --version print the version information and exit --root-directory=DIR install GRUB images 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 images into the DIR/boot directory specfied by--root-directory, and uses the grub shell to install grub into the bootsector. Report bugs to <bug-grub@gnu.org>.[root@localhost ~]# grub-install --root-directory=/boot/grub /dev/sdaGrub.conf 文件丢失需重新编写

重启:

故障二:/boot 目录被删的解决办法删除/boot下的所有内容 rm -rf /boot/*

重启

解决办法 首先将光驱挂载上 进入救援模式进入bios设置 将光驱设置为首先启动

进入救援模式:

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

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

Boot下面主要是内核和grub引导菜单 所有我们就要安装内核和grub由于光驱上有内核和引导菜单 所以我们借助光驱进行安装首先挂载光驱Mount /dev/hdc /mnt

安装内核 内核安装完成后会自动安装initrdRpm -ivh --force /mnt/Server/kernel-2.6.18-164.e15.i686.rpm

内核安装完成之后我们安装grub

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

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

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



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

故障三:grub目录被删故障四;文件系统表改变 Vim /etc/fstab

如果误操作其中一个例如

重新启动后会出现

输入管理员密码





mount -o remount

重启



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息