CentOS GRUB损坏怎么办?

点进来看~

CentOS 6.x

  1. 启动显示grub损坏界面,首先要猜测boot分区,一般来说,boot分区是安装操作系统时候划分的第一个分区,猜测为(hd0,0)(sd0,0)
  2. 猜测boot名称,标准分区一般为/dev/sda1, lvm如果没有特特殊定,一般为 /dev/mapper/VolGroup-lv_root

01

1
2
3
4
grub> root (hd0,0)
grub> kernel /vmlinuz-2.6.32-696.el6.x86-64 ro root=/dev/mapper/VolGroup-lv_root
grub> initrd /initramfs-2.6.32-696.el6.x86-64.img
grub> boot

01

  1. 进入系统后,新建一个/boot/grub/grub.conf文件,内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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/mapper/VolGroup-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-696.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-
8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto
rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-696.el6.x86_64.img

最简单的方法就是找到相同方式安装的服务器,直接copy一个过来~

CentOS 7.x

centos 7.x 使用的是grub2,方法更加简单方便。

01

挂载镜像,从光驱引导启动,选择“Troubleshooting(故障排错)”

01

选择“Recuse a CentOS System”

01

01

1
2
3
4
5
6
7
8
9
10
11
12
13
Grub2 用到的命令如下:
chroot /mnt/sysimage
grub2-install /dev/sda
grub2-mkconfig -o /boot/grub2/grub.cfg
exit
reboot
早期非 grub2 用到的命令如下:
chroot /mnt/sysroot
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
exit
reboot

参考:https://wiki.centos.org/zh/HowTos/Grub2

独学无友,孤陋寡闻;学习记录,欢迎拍砖!