How to repair the Grub in Linux

How to Restore GRUB After Reinstalling Windows

Many of us dual-boot Windows and Linux. A common problem is that reinstalling Windows overwrites the Linux MBR (Master Boot Record). After this, your Linux installation won’t appear as a boot option, and you can’t start it from your hard drive.

No worries, you can fix it using a Live Linux system.

Step 1: Boot from Live Linux

  • Use a USB or CD with your Linux installation and boot into the Live system.
  • Open a terminal, this is where we’ll run all commands.

Step 2: Mount Your Linux Partition

First, create a root mount directory:

mkdir /mnt/root

Next, find your Linux partition:

sudo fdisk -l

You’ll see output like:

Device Boot Start End Blocks Id System
/dev/sda1      2048 206847 102400 7 Linux

Here /dev/sda1 is your Linux partition.

Now mount it:

sudo mount /dev/sda1 /mnt/root

Also, mount the proc subsystem and dev:

sudo mount -t proc none /mnt/root/proc sudo mount -o bind /dev /mnt/root/dev

Step 3: Chroot Into Your Linux System

Use chroot to change the root directory for the terminal to your Linux installation:

sudo chroot /mnt/root /bin/bash

Now you are “inside” your Linux system as if it were booted normally.

Step 4: Reinstall GRUB

Depending on your distro:

For Ubuntu / GRUB (legacy):

grub-install /dev/sda

or if you need to specify root directory:

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

For Fedora / GRUB2:

grub2-install /dev/sda

Tip: Use --force if any errors appear.

Step 5: Update GRUB Configuration

After reinstalling GRUB, update its config so it detects all OSes:

Ubuntu / GRUB:

grub-mkconfig -o /boot/grub/grub.cfg

Fedora / GRUB2:

grub2-mkconfig -o /boot/grub2/grub.cfg

Step 6: Reboot

Exit chroot, unmount partitions if needed, and reboot. Your GRUB menu should now be restored, letting you boot into Linux and Windows again.