Repair Grub 2 from a live DVD

Suppose Grub 2 is broken and you can no longer boot into Ubuntu Mate. No need to panic, you can repair Grub 2 from a live DVD, or Live USB session.

Insert your Live DVD, or Live USB, and reboot your system. Select the live media, and boot from it.

Once the Live media is booted select the option to “Try Ubuntu Mate” and wait for it to finish loading.

From the live session open a terminal and run

sudo fdisk -l

This should return a output similar to this

[email protected]:~$ sudo fdisk -l
Disk /dev/loop0: 1.6 GiB, 1656864768 bytes, 3236064 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier:

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 15728639 15726592 7.5G 83 Linux
/dev/sda2 15730686 16775167 1044482 510M 5 Extended
/dev/sda5 15730688 16775167 1044480 510M 82 Linux swap / Solaris
[email protected]:~$

In the example above /dev/sda is the hard drive of the machine that the live DVD, or Live USB booted from.

Now find the Linux partition. In the example above it would be /dev/sda1 which is labled as Linux

Next, you need to mount the Linux partition.

From the terminal run

sudo mount /dev/sda1 /mnt

This will temporarily mount the Linux partition so there is access to the Grub configuration files that are necessary to reinstall Grub on your system.

Next, to reinstall Grub run the following in the terminal

sudo grub-install --boot-directory=/mnt/boot /dev/sda

This command is going to tell Grub to install the configuration located in the Linux partition /boot directory, which is mounted at /mnt, and install to the MBR of the hard drive on your system represented here as /dev/sda

This should return a output similar to the following if everything worked correctly

Installing for i386-pc platform.
Installation finished. No error reported.

At this point Grub should be repaired, and you should be able to boot into your system normally once again.

Notes:

This tutorial assumes you can no longer boot into your system because Grub is broken. The instructions given will repair Grub if you enter each command correctly. However, I do not recommend that you try this on a working system because if you do something incorrectly, you could cause your system to not boot.

There are many variables you may encounter. For example, if you have more than one hard drive you may see both /dev/sda and /dev/sdb listed. It’s up to you to determine which one your Linux partition resides on, and which one you need to install Grub to. Or if you have more than one Linux installation, you will see Linux listed more than once. It’s up to you to determine which Linux partition you need to repair Grub from. If you get stuck on any variables that you may encounter, a quick google search should shed some light on the subject.

I keep a condensed version of these instructions in my home folder. That way it can be accessed from a live session, this will allow me to copy and paste the commands, which I find to be safer and quicker than typing them. You may wish to do the same if you find these instructions useful.

My systems are somewhat dated, If there are other variables that I am unaware of related to newer hardware, please feel free to add them in a reply.

4 Likes

Unfortunately this doesn’t appear to work for me.

It tells me this GPT partition label contains no BIOS Boot Partition and embedding won’t be possible.

Perhaps this will help -

https://www.dedoimedo.com/computers/grub2-efi-recovery.html

Good luck @j07

2 Likes

That’s awesome! Cheers for the help.

Another way to do it, which you don’t see often, is to use the installer’s bootloader to boot the installed system. For example, if you are booting in UEFI mode then the installer will first boot into grub2. Here you can drop into the grub2 command-line interface prompt where you could enter something like:

ls set root=(hd0,msdos2) ls / linux /boot/vmlinuz root=/dev/sda2 quiet splash ro initrd /boot/initrd.img boot
Once you have your installed system running:

sudo grub-install 
sudo update-grub
1 Like

Some input about this, since I found some different instructions elsewhere —

  1. --root-directory works just as well, I've tested that using a separate USB media.
  2. With the inclusion of gnome-disks there is no reason why users shouldn't just run that to find their system partition for use with /mnt.
  3. I was able to do this with just two commands once I answered two important questions;
    • Where is my operating system? (Answered with a cursory glance at gnome-disks.)
    • Where do I want to install GRUB? (Again, answered in gnome-disks.)

But also, do note this only works if the boot media is formatted as MBR, so in GNOME disks the hamburger menu at the upper right should be used for format the disk you want to put GRUB on. A partition also has to be made on it.

All of this because I wanted to pull something from an older live session and overwrote my boot media. Oops.

Just thinking... would it be simply easier to use Boot Repair ?

W

In a live session, Boot Repair refused to see the device, and as I said I was able to bang it out with two commands — No need for a PPA or installation of extraneous tools. I tried multiple formations of the media to see if that was the issue — it was not.

Boot Repair only seems to function on media which already have Ubuntu and Windows on them. It's a dual-boot fix'r up'r for people who didn't bother putting GRUB on a separate USB stick like I had, because I want to let Windows be Windows and do the Windows things without constantly worrying if an update will break my instance of GRUB.

The way I get around that is to effectively use a USB media as an ignition key. Once it's going, the stick can be removed and the system operates like I need it to. Update to Windows? Upgrade to 10X in the future? No worries since GRUB is completely isolated and air-gapped.

I see. Different case here. I walked away from W completely. No second thought, no walk back, no regrets. No conflicts.
My view may be extreme to some. But to me keeping both systems means asking for trouble. I did for a little while; with exactly that - problems. Like living and moving across Syria and Irak frontier these days; maybe things may go well some way.
But your way of booting from 'outside' (USB) probably address half potential problems, i guess.

W