Fix GRUB Config

Fixing a Broken GRUB
Whenever you want to fix GRUB you will need to know several things; Partition Containing the Kernel, Kernel Name and Path and Partition Which Contains /sbin/init.

Lesson 5 | Lesson 7

Many things can break GRUB.  This is an illustration on how to fix line that are incorrect in the grub.conf.  If you system does not boot, you will need to know or be able to locate the correct information in order to fix the problem.

Locate Your /boot partition and copy down the exact name of the kernel and initrd image.  You have several options so make sure both the kernel and initrd image match versions.
config-2.6.18-128.1.16.el5      symvers-2.6.18-128.1.16.el5.gz
config-2.6.18-128.el5           symvers-2.6.18-128.el5.gz
initrd-2.6.18-128.el5.img       vmlinuz-2.6.18-128.1.16.el5
lost+found                      vmlinuz-2.6.18-128.el5

kernel = vmlinuz-2.6.18-128.1.16.el5
initrd image = initrd-2.6.18-128.1.16.el5.img

Use the df command to verify where the boot partition is and where /sbin/init is, located in the / partition.

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda2              3968124   1044720   2718576  28% /
/dev/hda3               988116     17756    919356   2% /home
/dev/hda1               101086     16688     79179  18% /boot

boot partition = /dev/hda1    
root partition = /dev/hda2

A Broken GRUB
Here is an example of a grub.conf that will not work.
title CentOS (2.6.18-128.1.16.el5)
root (hd2,30)
kernel /vmlz-2.6.18-128.1.16.el5 ro root=LABEL=/
initrd /initrd-2.6.18-128.1.16.el5.img

When you boot, you need to select the broken boot lines so you can fix them.  Here you can see two options, the first one is deliberately broken.  Now if you cannot fix the first one you could boot to the second kernel....but what you want to do is learn how to fix the one  you broke.  

Select is and then choose “e” to edit.


Choose “e” again so you can change the line to reflect the correct location for the /boot directory.  Remember that /dev/sda1 is the same as hd0,0 in GRUB thinking.


You will need to do this with each line you broke, modifying them to reflect the correct path and kernel.


The kernel line above is broken but you can see below that is fixed.


Here is an example of fixing the initrd line, the image that contains the Linux device drivers.


Once it is all fixed select “b” to boot and it should start correctly, if not try again.  Remember if all else fails you can return to the kernel choices and boot from the good kernel.

If you select “c” you will be sent to the command line for GRUB.