Reinstall GRUB from Live USB (UEFI + LVM)

There are many reasons why you may need to reinstall GRUB: corrupted boot partition; GRUB got overridden after Windows installation; some unsupported Linux kernel parameters have been set in a GRUB configuration file and the system is not booting anymore but this can’t be fixed from a GRUB menu as it is not showing up, etc.

In this note i am describing a particular case of how to repair GRUB by reinstalling it from a live USB if a broken system is configured to boot in UEFI mode and a system’s disk is partitioned to LVM.

I have tested this GRUB reinstallation on Ubuntu Linux, though all of the commands below should work for the other Linux systems as well.

Cool Tip: How to create a Linux rescue USB stick! Read more →

Reinstall GRUB from Live USB

UEFI or BIOS? The easiest way to find out if the system has booted in UEFI or BIOS mode is to look for a folder /sys/firmware/efi. The folder will be present if your system is using UEFI.

Boot from the rescue media (this can be a special SystemRescue USB stick or a simple live USB with Ubuntu or Linux Mint or any other system with a Linux shell prompt).

Scan all disks for logical volumes:

[root@sysrescue ~]# lvscan
-- sample output --
  ACTIVE            '/dev/vgubuntu/root' [114.02 GiB] inherit
  ACTIVE            '/dev/vgubuntu/swap_1' [980.00 MiB] inherit

Mount a “root” LVM partition:

# mount /dev/vgubuntu/root /mnt

Find out a name of the UEFI system partition (the first partition of a primary disk drive, i.e. in the example below it is /dev/sda1):

# lsblk
-- sample output --
NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0                 7:0    0 679.8M  1 loop /run/archiso/sfs/airootfs
sda                   8:0    0 115.5G  0 disk 
├─sda1                8:1    0   512M  0 part 
└─sda2                8:2    0   115G  0 part 
  ├─vgubuntu-root   254:0    0   114G  0 lvm  /mnt
  └─vgubuntu-swap_1 254:1    0   980M  0 lvm  
sdb                   8:16   1  28.9G  0 disk 
├─sdb1                8:17   1   744M  0 part /run/archiso/bootmnt
└─sdb2                8:18   1   1.4M  0 part 

Mount the UEFI partition:

# mount /dev/sda1 /mnt/boot/efi

Bind the directories required by the grub-install and update-grub commands:

# for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt$i; done

chroot into a broken system:

# chroot /mnt

Install GRUB on the primary disk drive (in our case it is /dev/sda):

# grub-install /dev/sda
-- sample output --
Installing for x86_64-efi platform.
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 825: grub-install
File descriptor 4 (/dev/sda1) leaked on vgs invocation. Parent PID 825: grub-install
grub-install: warning: EFI variables are not supported on this system..
Installation finished. No error reported.

Optionally, you may want to update a GRUB’s configuration (for example, if the system was not booting properly due to some incorrect modifications you made in the /etc/default/grub file earlier – this is a time to fix them):

# vi /etc/default/grub

As an example you can take a GRUB’s default configuration file locate here:

# cat /usr/share/grub/default/grub

Generate the main configuration file /boot/grub/grub.cfg:

# update-grub
-- sample output --
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/50_linuxmint.cfg'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-88-generic
Found initrd image: /boot/initrd.img-5.4.0-88-generic
Found linux image: /boot/vmlinuz-5.4.0-74-generic
Found initrd image: /boot/initrd.img-5.4.0-74-generic
grub-probe: error: cannot find a GRUB drive for /dev/sdb1.  Check your device.map.

The last error in our case can be ignored as /dev/sdb1 is a partition on a live USB stick.

Cool Tip: How to mount an LVM Partition in a rescue mode! Read more →

Once GRUB has been reinstalled on the primary disk drive and its configuration file has been regenerated with the proper settings, you can power off the computer, eject the live USB stick and boot normally.

Was it useful? Share this post with the world!

Leave a Reply