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

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
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
Machine Boot Menu

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

Choose Language
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 Expert Mode
Ubuntu Boot Options
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
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
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
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
Select Your Location

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

Configure Keyboard
Configure Keyboard
Select Keyboard Country Layout
Select Keyboard Country Layout
Select Keyboard 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
Detecting System Hardware
Keep System Hostname
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
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
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
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
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
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
Installing Ubuntu Grub Boot Loader
Reboot Ubuntu System
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
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
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
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
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
Reboot System

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

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Matei Cezar
I'am a computer addicted guy, a fan of open source and linux based system software, have about 4 years experience with Linux distributions desktop, servers and bash scripting.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

6 Comments

Leave a Reply
  1. I have a quick grub2.02 display, however it’s ignored. and the computer boots straight to ‘line 1‘; despite a boot cd in the drive and a usb stick in a usb3 port. It’s as if the keyboard is never recognized until I get my Ubuntu screen.

    Reply
  2. Hello, thanks for the article. You mentioned in the intro “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.” …

    I don’t see these screens or menu options in non-server installs….how do you get to expert mode and modify the parameters etc.?

    Reply
  3. In below part of your post you said “before the quiet string” but the correct is “after the quiet string“. please check it out.

    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.

    Reply
  4. I think this information is not valid for modern SSD machines. In my system /dev/sda (/dev/sda1) is an external hard disk. The internal hard disk from which the OS boots is /dev/nvme0n1.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.