Recovering GRUB Linux

Usually on each disk there is an MBR (master boot record) and when the computer is turned on, the BIOS accesses it for information for further download. On Linux systems, GRUB is used as the boot loader, I will write about the recovery options of which below.

You can see the version of GRUB using the command:

grub-install --version

1) First option.
We start the system with LiveCD/USB, for example in the Ubuntu Desktop image, in addition to the installation, it is possible to start the system.
Open the terminal, for this press Alt+F2 and enter the command:

gnome-terminal

Let’s see the list of sections:

sudo fdisk -l
ls /dev/[hsv]d[a-z]*[0-9]*

Suppose the partition with the loader on /dev/sda1, connect it to the directory /mnt:

sudo mount /dev/sda1 /mnt

If software RAID is used, then:

ls /dev/md*
mount /dev/md2 /mnt

Either LVM:

ls /dev/mapper/*
mount /dev/mapper/vg0-root /mnt

And install grub in MBR with the following command:

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

You may also need to update the grub menu:

sudo update-grub --output=/mnt/boot/grub/grub.cfg

Done, grub is restored!

2) The second option through chroot.
Again, you need to start the system from the LiveCD/USB and open the terminal.
We will admit the partition with the loader together with the main partition on /dev/sda1.

We will connect it to /mnt, and also we will tie several necessary directories:

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

If /boot finds on a separate partition, then connect it to /mnt/boot, for example:

sudo mount /dev/sda2 /mnt/boot

Let’s move on to chroot:

sudo chroot-prepare /mnt
sudo chroot /mnt

Install GRUB:

grub-install /dev/sda

In case of an error, we type:

grub-install --recheck /dev/sda

It is possible still so:

grub-install --recheck --no-floppy /dev/sda

Exit the chroot:

exit

Disconnect the sections:

sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys
sudo umount /mnt

Similarly /boot if it is separate:

sudo umount /mnt/boot

Restart the computer:

sudo reboot

3) The third option, using recovery mode.
Let’s see what partitions are the next command (the numbering of disks starts with 0, and the partitions with 1, that is, the disk /dev/sda can be called for example hd0, and the partition /dev/sda1 – hd0,1):
ls

We indicate this section:

set prefix=(hd0,1)/boot/grub 
set root=(hd0,1)

And let’s check if there is grub:

ls /boot/grub

If there are, we load the modules:

insmod ext2
insmod normal
normal

If the section is in the format btrfs, then execute a few other commands:

set prefix=(hd0,1)/@/boot/grub
set root=(hd0,1)
insmod btrfs
insmod normal
normal

After the commands, Grub will start and determine which operating systems are installed.
Finally, run Linux and from the root user install grub on the correct disk, for example /dev/sda:

grub-install /dev/sda

Restart the system and check:

reboot

Done.

Leave a comment

Leave a Reply