zhousir1991

让开源路人皆知~!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

RHEL红帽企业版Linux系统排错

Posted on 2011-06-03 15:50  zhousir1991  阅读(1912)  评论(0编辑  收藏  举报
 本文系转载,写的比较全,所以放到这里分享给大家:

一、系统故障分析方法和目标

  • 判断问题的性质

重演出错过程 
查找进一步信息 
从简单的的方法入手 
在修改的时候备份配置文件

  • 修复Linux系统不同阶段的故障

将系统引导到不同的运行级别 
使用救援模式 
二、系统故障排错示例 
如下通过4个常见的示例说明系统故障排错的过程,分别是:

  • 系统密码不正确
  • mbr故障
  • /etc/fstab文件错误
  • /etc/inittab文件错误


三、系统密码不正确(忘记了或者说想窃取修改)

  • 忘记登陆系统的root密码,忘记grub引导管理器的密码

这里首先说明一个grup引导管理器密码,通过设置该密码可以防止人编辑启动菜单画面 
的选项,若要编辑必须输入密码才可以编辑。设置grub密码的步骤如下: 
[root@51cto ~]# vim /boot/grub/grub.conf 
//编辑这个文件 
[root@51cto ~]# cat /boot/grub/grub.conf 
# grub.conf generated by anaconda 
# 
# Note that you do not have to rerun grub after making changes to this file 
# NOTICE: 
You have a /boot partition. 
This means that 
# 
all kernel and initrd paths are relative to /boot/, eg. 
# 
root (hd0,0) 
# 
kernel /vmlinuz-version ro root=/dev/sda2 
# 
initrd /initrd-version.img 
#boot=/dev/sda 
default=0 
timeout=5 
splashimage=(hd0,0)/grub/splash.xpm.gz 
#hiddenmenu 
password=123 
//在Linux系统标题上面添加这行 
title Red Hat Enterprise Linux Server (2.6.18-128.el5) 
root (hd0,0) 
kernel /vmlinuz-2.6.18-128.el5 ro root=LABEL=/ rhgb quiet 
initrd /initrd-2.6.18-128.el5.img 
保存文件退出…... 
然后重启系统,可以发现提示信息说:直接回车可以启动系统,如果要设置菜单选项请 
输入“P”。要知道,如果系统没设置grub密码的话是可以直接编辑菜单选项的: 
 

 

输入“P”,然后输入先前设置的密码123 
 

 

可以发现密码验证过后,提示信息为输入“e”可以编辑菜单选项了 
 

 

 

输入“e”: 
 

 

这样就可以设置Linux系统启动级别了,所以说,没有设置grub密码的话,就算不知道root 
帐号密码,通过编辑菜单选项就可以通过level 1 启动系统设置密码了。 
当然,在设置grub密码的时候一般是使用MD5加密的,通过如下方法设置: 
[root@51cto ~]# grub-md5-crypt 
Password: 
//输入123 
Retype password: 
//输入123 
$1$q5Ppn/$MZr67rBdz6kIhk0lYDvFh0 
//这一行就是123的MD5加密密码 
然后编辑/boot/grub/grub.conf文件: 
[root@51cto ~]# vim /boot/grub/grub.conf 
[root@51cto ~]# cat /boot/grub/grub.conf 
# grub.conf generated by anaconda 
# 
# Note that you do not have to rerun grub after making changes to this file 
# NOTICE: 
You have a /boot partition. 
This means that 
# 
all kernel and initrd paths are relative to /boot/, eg. 
# 
root (hd0,0) 
# 
kernel /vmlinuz-version ro root=/dev/sda2 
# 
initrd /initrd-version.img 
#boot=/dev/sda 
default=0 
timeout=5 
splashimage=(hd0,0)/grub/splash.xpm.gz 
#hiddenmenu 
password --md5 $1$q5Ppn/$MZr67rBdz6kIhk0lYDvFh0 
//修改成MD5加密的 
title Red Hat Enterprise Linux Server (2.6.18-128.el5) 
root (hd0,0) 
kernel /vmlinuz-2.6.18-128.el5 ro root=LABEL=/ rhgb quiet 
initrd /initrd-2.6.18-128.el5.img 
当重启系统后想编辑菜单选项就输入加密密码123 
回到正题:忘记登陆系统的root密码,忘记grub引导管理器的密码 
开机--->第一张光盘启动(使用虚拟机测试就按ESC键)--->linux rescue(进入救援模式) 
--->一路回车--->chroot /mnt/sysimage--->vi /boot/grub/grub.conf编辑文件, 
删除password行(去除或重设密码)--->reboot--->进入单用户模式 
(开机-进入菜单界面-按e-选择第二项-e-在末尾输入空格1或空格single-回车) 
--->passwd(设置系统用户root的密码)--->reboot 
具体的步骤很简单就不显示了,去除或重设了grub密码,使用root密码就可以登陆系统了 
四、mbr故障 
[root@51cto ~]# dd if=/dev/zero of=/dev/sda bs=46 count=1 
//模拟mbr故障 
1+0 records in 
1+0 records out 
46 bytes (46 B) copied, 0.000197012 seconds, 233 kB/s 
[root@51cto ~]# reboot 
//重启系统查看 
Broadcast message from root (pts/0) (Sun Oct 10 08:05:01 2010): 
The system is going down for reboot NOW! 
结果发现启动不了系统,于是进入救援模式: 
通过如下两个命令就可以解决mbr故障了: 
chroot /mnt/sysimage 
grub-install /dev/sda 
然后重启系统 
 

 

登陆正常了,显示如下: 
 

 

五、/etc/fstab文件错误 
[root@51cto ~]# cat /etc/fstab      //查看该文件 
LABEL=/                 /                       ext3    defaults        1 1 
LABEL=/home             /home                   ext3    defaults        1 2 
LABEL=/boot             /boot                   ext3    defaults        1 2 
tmpfs                   /dev/shm                tmpfs   defaults        0 0 
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0 
sysfs                   /sys                    sysfs   defaults        0 0 
proc                    /proc                   proc    defaults        0 0 
LABEL=SWAP-sda5         swap                    swap    defaults        0 0 
/dev/sdb1               /51cto                  ext3    ro,noexec       0 0 
如果把该文件删掉重启系统: 
[root@51cto ~]# rm /etc/fstab 
rm:是否删除 一般文件 “/etc/fstab”? y 
[root@51cto ~]# ll /etc/fstab 
ls: /etc/fstab: 没有那个文件或目录 
[root@51cto ~]# reboot 
Broadcast message from root (pts/0) (Sun Oct 10 08:42:43 2010): 
The system is going down for reboot NOW! 
 

 

2010-10-11 00:43

由于该文件的丢失,所以系统硬盘无法使用了,只有重新把/etc/fstab恢复,必须手写进去 
 

 

然后重启系统查看: 
 

 

 

六、/etc/inittab文件错误 
[root@51cto ~]# 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:3: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" 
# 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 
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 
然后把文件删除,重启系统: 
[root@51cto ~]# rm /etc/inittab 
rm:是否删除 一般文件 “/etc/inittab”? y 
[root@51cto ~]# reboot 
 

 

 

结果显示不存在系统运行的进程,就是因为/etc/inittab的丢失造成的,当然修复的话不可能 
手写进去了,那么多内容啊! 
这时候进入救援模式,安装initscripts软件包,自动创建/etc/inittab文件 
当然要通过mount /dev/dhc 
/media/cdrom/挂载光驱,然后安装rpm包 
 

 

 

 

 

登陆了系统,可以查看到该文件了!