grub shell 错误_CentOS Grub、BASH 故障、解决方法

简介:

Grub 常见的两种故障:Grub.conf 文件丢失、MBR 损坏 ( 不管恢复怎么样,还是先备份好吧 )

一、Grub.conf 文件丢失

shell > rm -rf /boot/grub/grub.conf ## 删除文件、模拟故障

shell> reboot

## 故障现象如下:

GNU GRUB verstion 0.97 (634k lower /1046400k upper memory )

[ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename. ]

grub>

## 就这个样子,无法登陆系统,下面是解决方法

grub> root (hd0,) # 输入 root (hd0,) 这时按 TAB 键会打印出系统上所有的分区 ( 注意在急救模式下不支持 TAB , 很伤~)

Possible partitions are:

Partition num:0, Filesystem type is ext2fs, partition type 0x83Partition num:1, Filesystem type unknown, partition type 0x82Partition num:2, Filesystem type is ext2fs, partition type 0x83

## 0, 1, 2 代表分区编号,上面显示有文件系统,分区类型,像 83 就是 Linux 普通分区,82 是虚拟分区 SWAP ( 硬盘分区时的知识 )

## 这里不分 IDE / SATA 什么的,都用 hd 代表,hd0 代表第一块硬盘,hd0,0 代表第一块硬盘的第一个分区,系统中是用 sda1 代表第一块硬盘的第一个分区

grub> root (hd0,0)/ # 输入 root (hd0,0)/ 这里按 TAB 键搜索内核在不在此分区上 ( boot 分区 ),如果有会输出下面信息 ( 试 83 的分区,82是交换分区就没必要试了 )

Possible files are: lost+found grub efi .VMlinuz-2.6.32-504.e16.x86_64.hmac System.map-2.6.32-504.e16.x86_64 config-2.6.32-504.x86_64 symvers-2.6.32-504.x86_64.gz VMlinuz-2.6.32-504.e16.x86_64 initramfs-2.6.32-504.e16.x86_64.img

## 如果可以看到 vmlinuz- 跟 initramfs- 字样,说明这就是我们想要的东西

grub> root (hd0,2)/ # 下面是搜不到的显示, 仔细看看 ( 发现这是根分区哎~~ hd0,2 是根分区,我们用的是 SATA , 所以根分区是 /dev/sda3 很有用 !)

Possible files are: lost+found boot dev proc sys var tmp etc root selinux lib64 usr bin home lib media mnt opt sbin srv .autorelabel

grub> root (hd0,0) # 绑定启动分区

Filesystem type is ext2fs, partition type0x83grub> kernel /VMlinuz-2.6.32-504.e16.x86_64 ro root=/dev/sda3 # 指定启动内核,ro 只读模式,root=指定根分区, 一定要指对 ( 可能如果 boot 没有单独分区不指定也是可以的 )

grub> initrd /initramfs-2.6.32-504.e16.x86_64.img # 这是内核映像吧 ( kernel 、initrd 都是上面搜出来的,输入一点点按 TAB 可以补全 )

grub>boot # 启动系统,手动编写 grub.conf 或恢复备份

shell> vim /boot/grub/grub.conf

default=0# 启动哪个系统

timeout=5# 等待时间

title CentOS6.6# 描述信息

kernel/VMlinuz-2.6.32-504.e16.x86_64 ro root=/dev/sda3 # 内核

initrd/initramfs-2.6.32-504.e16.x86_64.img # 启动映像

## 这里有个 vim 的用法,直接主机上 vim 是不可以用鼠标复制命令行内容的,那 kernel 跟 initrd 又那么长,不好记

## 方法:末行模式下输入 .! ls /boot/vmlinuz- 按 TAB 就可以补全了,这时按 Enter 键就可以将此条信息放到当前文件中

shell > reboot

## 这样就恢复成功了!还是记得备份吧

## 如果 kernel 没有指对根分区就会这样~ 还要重启系统,重新来过

dracut Warning: Signal caught!

?dracut Warning: Boot has faild. To debug this issue add "rdshell"to the kernel command line.?Kernel panic - not syncing: Attempted to kill init!

?Pid: 1, comm: init Not tainted 2.6.32-504.e16.x86_64 #1

?Call Trace:

[

? [

? [

? [

?

二、MBR 损坏

shell > dd if=/dev/zero of=/dev/sda count=1 bs=200 # 覆盖 MBR , 模拟故障 ( /dev/sda 前 512个字节是 MBR )

shell> reboot

## 故障现象如下:

Operating System not found # 基本就这样,会出现本地硬盘找不到系统、从 PXE 获取,DHCP xxxxxxxxxxxxx

## 解决方法:使用紧急救援模式修复

> 插入系统光盘,进入急救模式 ( 这个都会进吧,CentOS 直接选择,RedHat boot:linux rescue )

shell >grub # 进入 grub 模式

grub> root (hd0,0) # 直接指定内核所在分区吧,没法 TAB ( 一定要想办法找到它, 例如:先 chroot /mnt/sysimage , 然后 df -HT 可以看到所有分区,假如 sda1 是启动分区,那么这里对应就是 hd0,0了 )

grub> setup (hd0) # 重新安装 MBR 到该磁盘,实际上就是 /dev/sda

grub>quit

shell> reboot

## 现在就可以成功进入系统了,MBR 已经修复

附加:BASH 故障的解决方法

shell > rm -rf /bin/bash # 删除 bash ,模拟故障

shell> reboot

## 故障现象如为:系统无法初始化,init 命令不存在,其实什么指令都不能执行

## 进入急救模式重新安装 bash

shell > mkdir /media # 直接在光盘系统中操作,因为这时无法 chroot 到 /mnt/sysimage

shell> mount /dev/sr0 /media # 挂载光盘镜像,/dev/sr0 代表光驱,如果是 IDE 接口应该是 /dev/hdc

shell> cd /media/Packages

shell> rpm -ivh --replacepkgs --root /mnt/sysimage bash-4.1.2-29.e16.x86_64.rpm # 将 bash 安装到 --root 指定根目录中 --replacepkgs 是替换原有包

shell> reboot

## OK ,故障已经修复!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值