输入“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 然后重启系统