Restore Recreate Lost MBR Grub Boot Loader Linux

Problem - lost grub.conf & MBR Master Boot Record
In my system due to unclean shutdown, grub.conf and mbr are corrupted.So when I restart the system it is going to the grub window.I restart the Operating system using rescue mode.
After I loading we need to do the following things
SOLUTION Restore MBR grub loader
1)Find where the grub.conf file are located.
grub> find /boot/grub/stage1
(hd0,0)
2)Find the File system of the root partition
grub> root (hd0,0)
File system type is ext2fs, partition type 0x83
3)using setup command install grub.conf file
grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
Running "embed /boot/grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
Running "install /boot/grub/stage1 (hd0,0) /boot/grub/stage2 p /boot/grub/grub.conf "... succeeded
Done.

NOTE:if boot Parition is present in root (hd0,5) then we have to install like
setup (hd0) that is correct method setup. Because it will install in to the mbr of hard disk 0. (hd0,5) it is Not correct one.Because we can't give any gurantee it will install  into the mbr of hd0.
4)Now load the kernel and initrd
grub> kernel /boot/vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet
   [Linux-bzImage, setup=0x1e00, size=0x1c31b4]
grub> initrd /boot/vmlinuz-2.6.18-164.el5
Possible files are: vmlinuz-2.6.18-164.el5 vmlinuz-2.6.18-164.el5xen
There initrd these boot loader initialized a ram disk.
Finally type the #boot command it will boot your operating system.

Restore Grub trouble shooting related command
fsck.ext3 /dev/hda1 >>check the file system.
grub-install --root-directory=/mnt /dev/hda1 >> install grub boot loader
chroot /mnt/sysimage >> it will change the default root directory to /mnt/sysimage
mount -t ext2 /dev/hda2 /mnt/sysimage >> if hardisk unable to mount we can using these command
Login to the resuce mode for Linux redhat centos fedora to resolve the grub and mbr corrupted file.
grub> find /boot/grub/stage4
Error 15: File not found

if you get Error 15 File not found Then try with following command
grub> find (hd0,0)/boot/grub/stage1
(hd0,0)
grub>root (hd0,0)
grub>setup (hd0,0)
Error 15: File not found
grub>kernel (hd0,X)/boot/
/dev/sda1 will be hda(0,0)
/dev/sda2 will be hda(0,1)
/dev/sdb1 will be hda(1,0)
/dev/sdb2 will be hda(1,1).Error 15: File not found

Related post