Informational Website publish

Blog

News about our company, tutorials about IT and much more you will find in this page.

How to Rebuild GRUB on a Linux Server

Janeiro 31st, 2018

GRUB is the most important part of the Linux OS. GRUB is the Boot Loader for Linux, hence without it Linux OS cannot be booted or start, it is the most important part in the Linux Booting process. When this GRUB is damaged or corrupted its core files in your Linux OS cannot be booted. In many cases, the GRUB boot loader can mistakenly be deleted, corrupted, or replaced by other operating systems.
The following steps detail the process on how GRUB is reinstalled on the master boot record.

Note: This tutorial assumes that you already know how to use our recovery tools available on your client area or at least that you know how to boot your OS into recovery mode using a live/installation CD. If you don’t know how to do this, follow this How to Reset Root Password With Rescue tutorial to learn how to put your server in recovery mode, before proceeding any further.

Example Case A

In this example we will assume that /boot is on sda1 and / on sda2.

Start by entering recovery mode through SSH and mount all the partitions needed:

  • mount /dev/sda2 /mnt/
  • mount -o bind /dev /mnt/dev
  • mount -o bind /proc /mnt/proc
  • mount /dev/sda1 /mnt/boot

Now we are going to need to chroot into this newly mounted root partition:

  • chroot /mnt /bin/bash

All we need to do now is install GRUB on our drive by accessing the GRUB command line.

  • grub
grub> root (hd0,0)
grub> setup (hd0)

If GRUB returns a successful installation, then you’re all set. Leave recovery mode and your server should boot into the OS again.
 

Example Case B

In this example we will assume that /boot is on md0 and / on md1 of a RAID1 array.

Start by entering recovery mode through SSH and mount all the partitions needed:

  • mount /dev/md1 /mnt/
  • mount -o bind /dev /mnt/dev
  • mount -o bind /proc /mnt/proc
  • mount /dev/md0 /mnt/boot

Now we are going to need to chroot into this newly mounted root partition:

  • chroot /mnt /bin/bash

All we need to do now is install GRUB on our drive by accessing the GRUB command line, but since we have two drives in a RAID1 configuration we will install GRUB on both drives, so if one fails the server can still boot into the OS through the other.

  • grub
grub> root (hd1,0)
grub> setup (hd1)
grub> root (hd0,0)
grub> setup (hd0)

If GRUB returns a successful installation, then you’re all set. Leave rescue mode and your server should boot into the OS again.
 

Example Case C

In this example we will assume that /boot and / are on md0 on a RAID1 array.

Start by entering recovery mode through SSH and mount all the partitions needed:

  • mount /dev/md0 /mnt/
  • mount -o bind /dev /mnt/dev
  • mount -o bind /proc /mnt/proc

Now we are going to need to chroot into this newly mounted root partition:

  • chroot /mnt /bin/bash

All we need to do now is install GRUB on our drive by accessing the GRUB command line, but since we have two drives in a RAID1 configuration we will install GRUB on both drives, so if one fails the server can still boot into the OS through the other.

  • grub
grub> root (hd1,0)
grub> setup (hd1)
grub> root (hd0,0)
grub> setup (hd0)

If GRUB returns a successful installation, then you’re all set. Leave rescue mode and your server should boot into the OS again.