Restore the GRUB Bootloader

This guide contains useful information to access a damaged linux installation. To proceed you need to get the live Condres OS.

Start the compunter with the live 

Check the name of the partition that contains the installation with the command

fdisk -l

mount the installation partition in the / mnt directory, for example /dev/sda2

sudo su
mount /dev/sda2 /mnt

if the /boot or /var (or any other) folders are in a separate partition, you need to mount them inside the /mnt, example:

mount /dev/sda3 /mnt/var
mount /dev/sda1 /mnt/boot

Mount the rest of the devices with the controls:

mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

Run the chroot command specifying the destination folder and shell to use

chroot /mnt /bin/bash

For BIOS Systems

1. Install a new GRUB bootloader with the following command:

grub-mkconfig -o /boot/grub/grub.cfg
grub-install /dev/sda
note: sda is the disk device where you want to install GRUB. You can check it using lsblk -f or using GParted as explained before.

2. Recheck to ensure the that installation has completed without any errors:

grub-install --recheck /dev/sda

3. Finally, configure the freshly installed GRUB bootloader:

update-grub

All done! Now close the terminal and reboot your system to use your freshly re-installed GRUB.

Warning: this procedure can cause a chroot error

1.) First of all check the partition for the ESP (EFI System Partition). An ESP is a fat32 partition and contains .efi files for booting.

It can be checked using Gparted or from the terminal using fdisk -l

(Note: If you do not have a EFI partition, you will need to create it. Use Gparted for that.

Type- fat32

Size- 512 mb to 1 gb)

2.) Create the /boot/efi directory

sudo mkdir /boot/efi

3.) Mount the EFI partition as /boot/efi

sudo mount /dev/sdXY /boot/efi

X = Alphabet of the drive = a,b,c … Y = Partition number of the EFI partition = 1,2,3,4…

Example – /dev/sda4

4.) Re-install Grub.

sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=condres --recheck

5.) Update Grub configuration file.

sudo update-grub

Note

If you get something like

EFI variables are not supported on this system.

Then install the efibootmgrdosfstools and grub packages and try steps 4 and 5 again.

If it still doesn’t work, then try exiting the chroot environnment by typing exit, then loading the efivarfs module:

sudo modprobe efivarfs

and in the chroot

mount -t efivarfs efivarfs /sys/firmware/efi/efivars

And if you get something like

grub-install: error: failed to get canonical path of `union'.
Calogero Scarnà
Calogero Scarnà
Articoli: 299

Newsletter

Inserisci il tuo nome e il tuo indirizzo email qui sotto e iscriviti alla nostra newsletter