Skip to content

How to reinstall Grub after Windows installation

Published: at 06:06 AM

Introduction

When you install or reinstall Windows on a system that previously had Linux, the Windows installation process often overwrites the GRUB bootloader with its own. GRUB (Grand Unified Bootloader) is the bootloader used by most Linux distributions to manage the boot process and allow users to choose between different operating systems. Once GRUB is overwritten, your Linux installation becomes inaccessible, and the system boots directly into Windows.

In this article, we’ll guide you through the process of restoring GRUB after a Windows installation. Whether you’re dual-booting Linux and Windows or simply need to recover access to your Linux system, this step-by-step guide will help you restore GRUB and regain control over your boot process. We’ll cover the necessary commands and techniques to reconfigure GRUB, ensuring that you can boot into both Windows and Linux without any issues.

Table of contents

Open Table of contents

Boot from live USB

Booting from a live USB drive allows you to start your computer using an operating system stored on a portable USB device, rather than from the computer’s internal hard drive. This is particularly useful for troubleshooting, repairing, or installing a new operating system. To boot from a live USB, you typically need to insert the USB drive into your computer, restart the system, and access the boot menu by pressing a specific key (like F2, F12, ESC, or DEL) during startup. From the boot menu, you select the USB drive as the boot device, which then loads the operating system stored on it. This method is commonly used in scenarios like recovering data, diagnosing hardware issues, or restoring the GRUB bootloader after it has been overwritten by another operating system installation.

Here you can find tutorials on how to create a live Ubuntu USB drive and how to boot from live usb.

Mounting filesystems

Now when you booted your computer from USB drive, start the Terminal and switch to root user:

sudo -i

Then list available disks:

fdisk -l

In case when your hard drive is encrypted, first you need to unlock Luks partition (remeber to replace /dev/XXXX with actual partition name on your hard drive)

cryptsetup luksOpen /dev/XXXX

Then mount encrypted Luks partition in /mnt

mount /dev/mapper/XXXX /mnt

Mount Linux /boot partition

mount /dev/XXXX /mnt/boot

Mount other required filesystems - /dev/, /proc, /sys and efivars

mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars

or using the one-liner:

for i in /dev /proc /sys /sys/firmware/efi/efivars; do mount --bind $i /mnt$i; done

Chroot and installation

To restore GRUB and regain access to your Linux installation, we need to use chroot command. The chroot stands for “change root,” and it allows you to temporarily switch the root directory of your current shell environment to the root directory of another installed system — in this case, your Linux installation. By doing this, you can run commands as if you were operating within your original Linux environment, even though you’ve booted from a live USB.

chroot /mnt

Then we are ready to re-install Grub:

grub-install -d /usr/lib/grub/x86_64-efi --boot-directory=/boot /dev/XXXX

Conclusion

Restoring GRUB after a Windows installation will allow to regain access to your Linux system in a dual-boot setup. By following the steps outlined in this article — booting from a live USB, setting up a chroot environment, and reinstalling GRUB — you can recover your Linux bootloader and ensure that both operating systems are accessible at startup. This process not only restores functionality but also reinforces your understanding of how Linux and Windows manage the boot process.