星空网 > 软件开发 > 操作系统

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 .autorelabelgrub> root (hd0,0) # 绑定启动分区Filesystem type is ext2fs, partition type 0x83grub> 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.confdefault=0 # 启动哪个系统timeout=5 # 等待时间title CentOS 6.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:[<ffffffff815292bc] ? panic+0xa7/0x16f? [<ffffffff815292bc] ? do_exit+0xa7/0x16f? [<ffffffff815292bc] ? fput+0xa7/0x16f? [<ffffffff815292bc] ? system_call_fastpath+0xa7/0x16f??

二、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/sdagrub> quitshell > reboot

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

附加:BASH 故障的解决方法

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

## 故障现象如为:系统无法初始化,init 命令不存在,其实什么指令都不能执行
## 进入急救模式重新安装 bash

shell > mkdir /media # 直接在光盘系统中操作,因为这时无法 chroot 到 /mnt/sysimageshell > mount /dev/sr0 /media # 挂载光盘镜像,/dev/sr0 代表光驱,如果是 IDE 接口应该是 /dev/hdcshell > cd /media/Packagesshell > rpm -ivh --replacepkgs --root /mnt/sysimage bash-4.1.2-29.e16.x86_64.rpm # 将 bash 安装到 --root 指定根目录中 --replacepkgs 是替换原有包shell > reboot

## OK ,故障已经修复!




原标题:CentOS Grub、BASH 故障、解决方法

关键词:Centos

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

速卖通平台能否顺利完成第三次转型?:https://www.ikjzd.com/articles/111880
实操:在虾皮做一件代发的流程详解!:https://www.ikjzd.com/articles/111881
Instagram账户怎样设置才能提高网站流量呢?:https://www.ikjzd.com/articles/111882
旺季促销后,我们还需要做什么?复购才是重点:https://www.ikjzd.com/articles/111883
亚马逊遭起诉,原因竟是外观设计专利!:https://www.ikjzd.com/articles/111884
亚马逊虚假评论怎样避免?越过这个坑。:https://www.ikjzd.com/articles/111885
从园岭新村到大梅沙海滨总站坐什么车:https://www.vstour.cn/a/363191.html
七月份适合去日本旅游吗 7月份去日本哪里好玩:https://www.vstour.cn/a/363192.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流