Tecmint: Linux Howtos, Tutorials & Guides

How to Rescue, Repair and Reinstall GRUB Boot Loader in Ubuntu

Recover Reinstall Ubuntu Grub Boot Loader

This tutorial will guide you on how to rescue, repair or reinstall a damaged Ubuntu machine which cannot be booted due to the fact that the Grub2 boot loader has been compromised and cannot load the boot loader which transfers the control further to the Linux kernel. In all modern Linux operating systems GRUB is the default boot loader.

This procedure has been successfully tested on an Ubuntu 16.04 server edition with the Grub boot loader damaged. However, this tutorial will only cover Ubuntu server GRUB rescue procedure, although the same procedure can be successfully applied on any Ubuntu system or on the majority of Debian-based distributions.

Requirements

    1. Download Ubuntu Server Edition DVS ISO Image

You try to boot your Ubuntu server machine and you see that the operating systems no longer starts-up and you discover that the boot loader program no longer works?

Typically, the GNU GRUB minimal console appears on your screen, as illustrated on the below screenshot. How can you restore the Grub in Ubuntu?

Ubuntu Grub Console

There are a lot of methods in Linux that can be used to re-install a broken grub, some can involve the ability to work and restore the boot loader by using the Linux command line and others are fairly simple and implies booting the hardware with a Linux live CD and using the GUI indications to repair the damaged boot loader.

Among the simplest methods, that can be used in Debian based distributions, especially on Ubuntu systems, is the method presented in this tutorial, which involves only booting the machine into the Ubuntu live DVD ISO image.

The ISO image can be downloaded from the following link: http://releases.ubuntu.com/

Reinstall Ubuntu GRUB Boot Loader

1. After you’ve downloaded and burned the Ubuntu ISO image, or created a bootable USB stick, place the bootable media into your appropriate machine drive, reboot the machine and instruct the BIOS to boot into Ubuntu live image.

Machine Boot Menu

2. On the first screen, choose the language and press [Enter] key to continue.

Choose Language

3. On the next screen, press F6 function key in order to open the other options menu and select Expert mode option. Then, hit Escape key to return to Boot Options line in editing mode, as illustrated in the below screenshots.

Ubuntu Expert Mode

Ubuntu Boot Options

4. Next, edit Ubuntu live image boot options by using the keyboard arrows to move the cursor just before the quiet string and write the following sequence as illustrated in the below screenshot.

rescue/enable=true 

Enable Ubuntu Rescue Boot Option

5. After you’ve wrote the above statement, press [Enter] key to instruct the live ISO image to boot into rescue mode in order to Rescue a broken system.

Ubuntu Rescue Mode

6. On the next screen select the language you want to perform the system rescue and press [enter] key to continue.

Choose Language in Rescue Mode

7. Next, select your appropriate location from the presented list and press [enter] key to move further.

Select Your Location

8. On the next series of screens, select your keyboard layout as illustrated in the below screenshots

Configure Keyboard

Select Keyboard Country Layout

Select Keyboard Layout

9. After detecting your machine hardware, loading some additional components and configuring the network you will be asked to setup your machine hostname. Because you’re not installing the system, just leave the system hostname as default and press [enter] to continue.

Detecting System Hardware

Keep System Hostname

10. Next, based on the supplied physical location the installer image will detect your time zone. This setup will accurately work only if your machine is connected to internet.

However, it’s unimportant if your time zone is not correctly detected, because you are not performing a system installation. Just press Yes to continue further.

Keep Timezone

11. On the next screen you’ll be directly transferred into rescue mode. Here, you should choose your machine root file system from the provided list. In case your installed system uses a logical volume manager to delimit partitions, it should be easy to detect your root partition from the list by reviewing volume group names as illustrated in the below screenshot.

Otherwise, in case you’re not sure which partition is used for the /(root) file system, you should try to probe each partition until you detect the root file system. After selecting the root partition press [Enter] key to continue.

Choose Root Partition

12. In case your system has been installed with a separate /boot partition, the installer will ask you whether you want to mount the separate /boot partition. Select Yes and press [Enter] key to continue.

Mount Boot Partition

13. Next, you will be provided with Rescue operations menu. Here, select the option to Reinstall the GRUB boot loader and press [enter] key to continue.

Reinstall Ubuntu Grub Loader

14. On the next screen, type your machine disk device where the GRUB will be installed and press [Enter] to continue, as shown in the below image.

Usually, you should install the boot loader on your first machine hard disk MBR, which is /dev/sda in most cases. The installation process of GRUB will start as soon as you hit the Enter key.

Select Disk to Install Grub Loader

15. After the live system installs the GRUB boot loader you will be directed back to main rescue mode menu. The only thing left now, after you’ve successfully repaired your GRUB, is to reboot the machine as shown in the below images.

Installing Ubuntu Grub Boot Loader

Reboot Ubuntu System

Finally, eject the live bootable media from the appropriate drive, reboot the machine and you should be able to boot into the installed operating system. The first screen to appear should be installed operating system GRUB menu, as illustrated in the below screenshot.

Ubuntu Boot Menu

Manually Reinstall Ubuntu Grub Boot Loader

14. However, if you like to manually reinstall the GRUB boot loader from Rescue operations menu, follow all the steps presented in this tutorial until you reach point 13, where you make the following changes: instead of choosing the option to reinstall GRUB boot loader, select the option which says Execute a shell in /dev/(your_chosen_root_partition and press [Enter] key to continue.

Select Execute a Shell in Root Partition

15. On the next screen hit Continue by pressing [enter] key in order to open a shell in your root file system partition.

Open Shell Mode

16. After the shell has been opened in the root file system, execute ls command as presented below in order to identify your machine hard disk devices.

# ls /dev/sd* 

After you’ve identified the correct hard disk device (usually the first disk should be /dev/sda), issue the following command to install the GRUB boot loader on the identified hard disk MBR.

# grub-install /dev/sda

After GRUB has been successfully installed leave the shell prompt by typing exit.

# exit

Install Ubuntu Grub Boot Loader

17. After you’ve exited the shell prompt, you will be returned to main rescue mode menu. Here, choose the option to reboot the system, eject the live bootable ISO image and your installed operating system should be booted without any issue.

Reboot System

That’s all! With a minimal effort you’ve successfully rendered your Ubuntu machine the ability to boot the installed operating system.