Fix OVH Server Struck at grub2 prompt

One of our clients today had problem with their soyoustart.com (an ovh.com brand) server. The server was not booting up. OVH provide an option to boot the server from a rescue disk. So I used that feature to boot the server in rescue mode. Then mounted the server disks and check the system log, boot log, checked the disks etc. But they were of no help and all seems to be fine. So rebooted it again and looked at the IPMI screen( Another feature from OVH ) and found that it was struck at grub prompt. So the problem was with grub2 and it had to be fixed. So I booted the server again rescue mode and followed below steps to fix/reset the grub2.

First of all mount the disks in /mnt. This server had RAID disk. /dev/md2 as /boot and /dev/md3 as “/” partition. So I mounted them accordingly.

root@rescue:~# mount /dev/md3 /mnt/
root@rescue:~# mount /dev/md2 /mnt/boot/

Then binded /dev, /proc and /sys to /mnt and chrooted to /mnt

root@rescue:~# mount --bind /dev /mnt/dev
root@rescue:~# mount --bind /proc /mnt/proc
root@rescue:~# mount --bind /sys /mnt/sys
root@rescue:~# chroot /mnt

Now it’s time to fix the grub

[root@rescue /]# grub2-mkconfig -o  /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.9.161-xxxx-std-ipv6-64
Found initrd image: /boot/initramfs-4.9.161-xxxx-std-ipv6-64.img
done
[root@rescue /]# grub2-install /dev/sdb
Installing for i386-pc platform.
Installation finished. No error reported.
[root@rescue /]# grub2-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
[root@rescue /]#

Grub is fixed and we are good to go now. Exit the chroot, umount the partitions and reboot the server back in normal mode

[root@rescue /]# exit
root@rescue:~# umount /mnt/dev
root@rescue:~# umount /mnt/proc
root@rescue:~#  umount /mnt/sys
root@rescue:~# umount /mnt/boot
root@rescue:~# umount /mnt
root@rescue:~# reboot

After rebooting from hard disk (normal mode) the server was backup.

About 

Sreejit is the founder of Server Management Plus. His motto is "If there's an easier way, Why do it any other way" and following it, he has created a lots of automation scripts for the company using which we are able to resolve issue at an extremely fast rate and save lots of time. He has a very keen interest in new technologies and spend most of his free time online researching about it apart from listening music and watching movies.