if you are interested to contribute your LAB PROGRAM Please send mail to jkumaron@gmail.com

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
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

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
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

Grub2 Add New Boot Menu - How To Make Dual Boot Using Grub2.
Step 1: the new Linux os initrd and vmlinux file will be there under /boot directory.
Step 2: /etc/grub.d/40_custom -> create new OS menu entry like
menuentry "windows 10" {
set root='(hd0,0)'
chainloader +1
Step 3: using grub2-mkconfig -o /boot/grub2/grub.cfg make new grub configuration.
Useful Video: Edit grub2 https://www.youtube.com/watch?v=TDf_fRAophc

Grub2.cfg LVM menuentry - Just add into grub.cfg file.
menuentry 'CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-

advanced-47fb4a89-9d5e-4454-866f-813765825119' {
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod lvm
        insmod xfs
        set root='lvmid/b2nnEV-gxrb-MepI-oa4O-Byde-CDcH-Nqa6za/wbdD3m-1K4u-N0HS-c7pL-YBjs-eKHz-DTepaN'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='lvmid/b2nnEV-gxrb-MepI-oa4O-Byde-CDcH-Nqa6za/wbdD3m-1K4u-N0HS-c7pL-YBjs-eKHz-DTepaN'  47fb4a89-9d5e-4454-866f-813765825119
          search --no-floppy --fs-uuid --set=root 47fb4a89-9d5e-4454-866f-813765825119
        linux16 /boot/vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
        initrd16 /boot/initramfs-3.10.0-327.el7.x86_64.img

Related post