Fixing the Bootloader of a Ubuntu RAID system

Posted on Mon 19 August 2019 in Sysadmin

If the remote Ubuntu machine does not boot showing the following error

error: unknown filesystem
 Entering rescue mode...
 grub rescue>

the GRUB bootloader is broken and can be fixed in one of the following ways.

Using the GRUB rescue concole

Follow the steps described in this blog post.

Using a Live System

  1. Boot into a rescue system (can be done via your server provider's web interface).
  2. Connect via ssh using ssh root@ip.address.
  3. Once connected, make sure the mdadm tools are installed and assembled:

    apt-get install mdadm mdadm --assemble --scan

  4. Mount the system partition (e.g. /dev/md2):

    sudo mount /dev/md2 /mnt

  5. Check the mdadm.conf entries by looking at

    mdadm --examine --scan

  6. Mount the boot partition (e.g /dev/md1):

    mount /dev/md1 /mnt/boot

  7. Set up the other required mounts:

    mount -o bind /dev /mnt/dev mount -o bind /sys /mnt/sys mount -t proc /proc /mnt/proc cp /proc/mounts /mnt/etc/mtab

  8. Switch into the chroot environment:

    chroot /mnt /bin/bash

  9. Install GRUB 2 into the MBR of all relevant disks (e.g. /dev/sda and /dev/sdb2 in case of a RAID system with one mirror disk):

    grub-install /dev/sda grub-install /dev/sdb

  10. If any error occur during the last operation, try:

    grub-install --recheck /dev/sdX

  11. Recreate the file /boot/grub/grub.cfg using:

    update-grub

  12. Leave the chroot environment using CTRL+D.

  13. Reboot.