Recovering from a damaged or deleted grub installation

What to do when you damage or destroy your grub boot loader completely. First of all, do not panic. It is likely straightforward to fix. A few methods are available to you to fix this ranging from simple to slightly more complex.

Method 1 – Easy Mode #

The chances are, you discovered this issue when you rebooted your server, so you are already without your operating system. If only there were a way for you to get back into your operating system to install grub on your live environment… Well, there is, Super Grub Disk 2, grab this ISO:

Mount the ISO using your IPMI (ask for IPMI access through a support ticket if you do not have it) and then boot the server from the Super Grub Disk ISO, from the menu that loads select ‘Detect all operating systems’ This will scan your hard disks for available operating systems and it will craft a 1 time grub config in the live environment to then boot your server even if you completely deleted grub or the MBR from the disk.

Once you are in your operating system, you can then reinstall grub with ‘grub-install’ or ‘grub2-install’ depending on your operating system. Your grub config files should still be in place as they were, if not you can also run ‘grub-mkconfig’ or ‘grub2-mkconfig’ depending which version of grub your OS uses as a standard, then you should be able to reboot trouble-free in future.

Method 2 – Welcome to chroot #

Using our control panel you can boot your server to rescue mode, once you have done that and are logged in via ssh run the following commands:

fsarchiver probe simple

This will list your disks and partitions, you are looking for the root filesystem, in this example, lets assume that is sda2 and that /boot is on sda1

Now you need to mount your proc dev and sys directories from your disk partition containing your root filesystem, for example:

mkdir /mnt/linux
mount /dev/sda2 /mnt/linux
mount -o bind /proc /mnt/linux/proc
mount -o bind /dev /mnt/linux/dev
mount -o bind /sys /mnt/linux/sys
mount /dev/sda1 /mnt/linux/boot # This step is not needed if /boot is also on sda2

Now you need to chroot your root filesystem:

chroot /mnt/linux /bin/bash

And install grub again:

grub-install /dev/sda

You should see a confirmation message that looks similar to this:

Installation finished. No error reported.
This is the contents of the device map /boot/grub/
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
# this device map was generated by anaconda
(hd0)     /dev/sda

Now you need to unmount all the filesystems you had mounted

umount /mnt/linux/{dev,proc,sys}
umount /mnt/linux/boot
umount /mnt/linux