Grub 引导修复

来源:互联网 发布:游族网络官网个人中心 编辑:程序博客网 时间:2024/05/16 13:51

Introduction

GNU GRUB (short for GNU GRand Unified Bootloader) is a boot loader package from the GNU Project. GRUB is the reference implementation of the Free Software Foundation's Multiboot Specification, which provides a user the choice to boot one of multiple operating systems installed on a computer or select a specific kernel configuration available on a particular operating system's partitions.


Purpose

Provide a background about GRUB, and a guide of how to fix problems.

Requirements

Skills

Basic Grub knowledge.

Common GRUB problems

  • Disk is broken.
  • Lost /boot/grub/grub.conf or /boot/grub2/grub.cfg.
  • grub.conf and grub.cfg code change.

edit]Tools

GNU GRUB 0.97 and GNU GRUB 2


TIPs

  • Every Linux system Grub is different, so we must confirm the type of operating system.
  • Every Grub version has different fix steps, this wiki just tell you how to fix Grub 0.97 and Grub2.

WARNING

Operation may cause the machine or the host machine kernel panic or CPU stop running.


Summary

  • Confirm Grub version.
  • Find fix way.
  • Rebuild grub.conf

Procedure

  • Determine Grub version

You can find Grub title like this:

GNU GRUB version 0.97

You can find Grub2 title like this:

GNU GRUB version 2.02
  • caution

Sometimes you can’t find version, you can type in “help”command. If you find so many commands this Grub is Grub 2, if you find have a little commands this Grub is Grub 0.97.


How to fix


CentOS 5.5

  • Confirm /boot location

use "find" command, you can confirm /boot location.(this step is very important) you can find have a disk is /boot (type is 0x83)

find (hd0,<button tab>)

If disk is broken, you cannot find any disk description.

Partition num: 0, Filesystem type unknown, partition type 0x8e
  • set root
root (hd0,0)     (if system /boot is on the hd0,0)
  • make a link /root
kernel /vmlinuz-******** ro root=/dev/VolGroup00/LogVol[number]( Useful Remember this path in the future)initrd /initrd-********.imgboot

if you can’t find LogVol[number] you can find form this path(but isn’t right path just can help you to find simple path, you need try this file name ). YOU CAN FIND THIS INFORMATIONTrying to resume from /dev/VolGroup00/LogVol[number]

  • rebuild grub.conf

If successfully entry system, you can find /boot/grub/ have a link (menu.lst->grub.conf), this is temporary, if you reboot the system will return to Grub mode, so you need to rebuild the grub.conf file.

CentOS 5.5 grub.conf template:

default=0timeout=5splashimage=(hd0,0)/grub/splash.xpm.gzhiddenmenutitle CentOS (2.6.18-194.el5)        root (hd0,0)        kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/LogVol[number] rhgb quiet        initrd /initrd-2.6.18-194.el5.img

CentOS 6.5

  • find where is /boot

use "find" command, you can confirm /boot location.(this step is very important) you can find have a disk is /boot (type is 0x83)

find (hd0,<button tab>)

If disk is broken, you cannot find any disk description.

Partition num: 0, Filesystem type unknown, partition type 0x8e
  • set root
root (hd0,0)     (if system /boot is on the hd0,0)
  • make a link /root
kernel /vmlinuz-******** ro root=/dev/mapper/vg_[hostname]-lv_root( Useful Remember this path in the future)initrd /initramfs-********.imgboot

if you can’t find vg_[hostname]-lv_root you can find form this path(this is just a piece of file name you need make this file name full ) YOU CAN FIND THIS INFORMATION dracut:Found volume group "vg_[hostname]" using metadata type lvm2

  • rebuild grub.conf

If successfully entry system, you can find /boot/grub/ have a link (menu.lst->grub.conf), this is temporary, if you reboot the system will return to Grub mode, so you need to rebuild the grub.conf file. CentOS 6.5 grub.conf template:

default=0timeout=5hiddenmenutitle CentOS (2.6.32-431.el6.x86_64)        root (hd0,0)        kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg_[hostname]-lv_root         initrd /initramfs-2.6.32-431.el6.x86_64.img
  • reboot and test

reboot system to test grub.conf.


CentOS 7.0

CentOS differs from CentOS 5.5 and CentOS 6.5, because CentOS 7.0 used Grub2 and you can find Grub title version. so you need use "help" to confirm Grub version. Grub2 fix way is very simple.

ls (hd0,<button tab>)

If disk is broken, you cannot find any disk description,like this:

Partition num: 0, Filesystem type unknown, partition type 0x8e
  • insert disk mode
insmod xfs
  • set /root
set root=(hd0,msdos1)     (if system /boot is on the hd0,msdos1)
  • make a link
linux16 /vmlinuz-xxxxx root=/dev/mapper/centos-rootinitrd16 /initramfs-.xxxxx.imgboot
  • rebuild grub.cfg

Open a terminal and type this command you can rebuild grub.cfg

grub2-mkconfig >/boot/grub2/grub.cfg
0 0
原创粉丝点击