Reinstall GRUB bootloader
Hi Linuxers 👋
Installed Windows after Linux? Unable to access your Linux partition? Don't panic, I'm here to help you. This tutorial speaks about reinstalling GRUB.
Even I have faced this problem at the beginning, when it's been only a couple of months since I've started learning Linux. Without further delay, let's move on!
The Live USB method
The easiest method which I've been using is, reinstalling GRUB using a Live USB. It could be a Live USB of any distro. It'll do the job.
Step 1: Download a live installation ISO of any distro [it could be Ubuntu, Fedora, Arch Linux, etc. (Don't choose Debian, it does not have a live interface)]
Step 2: Flash the live image (Linux) to a USB stick, which must be atleast 8 GB (the ISO which you're downloading may exceed 4 GB).
Step 3: Once the image is flashed, close all programs and Reboot your computer.
Step 4: At the BIOS, spam the [F8] key ([F12] in case of Lenovo, or [Delete] in some models) and select the boot device.
Note: If your computer features UEFI, then you may have to disable secure boot in the Firmware settings
Step 5: Once you've selected the boot device (from the boot menu), it'll automatically boot into the live image which you've previously flashed into the USB drive. In my case, I'm using Ubuntu.
Step 6: After getting into the live interface, click Try Ubuntu (varies according to the distro).
Open the terminal in Live mode (Ctrl+Alt+T):Open the terminal and run these commands:
sudo mount -t ext4 /dev/sdXY /mnt
This command mounts your partition in the hard drive, which contains Linux. Replace the X and Y with your drive letters (It's /dev/sda1 in my case. Open GParted or Gnome-Disks to check your drive letter).
After executing them, execute these (mounts other folders which is necessary):
sudo mount --bind /dev /mnt/dev &&
sudo mount --bind /dev/pts /mnt/dev/pts &&
sudo mount --bind /proc /mnt/proc &&
sudo mount --bind /sys /mnt/sys
Now, we will be accessing the Linux partition in the hard drive using chroot.
sudo chroot /mnt
Now, let's install the GRUB bootloader.
Note: We will be using the drive letter alone (like /dev/sda), without the partition number) to install the bootloader into the MBR of the hard drive.
Debian-based Distros (like Ubuntu, Mint, etc):
grub-install /dev/sdX
update-grub
Red Hat-based Distros (like Fedora, Cent OS, Oracle Linux, etc):
grub2-install /dev/sdX
grub2-mkconfig -o /boot/grub2/grub.cfg
Arch-based Distros (like Manjaro, ArcoLinux, etc):
grub-install /dev/sdX
grub-mkconfig -o /boot/grub/grub.cfg
Now, exit from the terminal (which we've accessed through chroot) by pressing Ctrl+D or typing exit Once you're successful in running those commands (according to your distro), you have to unmount all the partitions which you've previously mounted. To do that, run these commands:
sudo umount /mnt/sys &&
sudo umount /mnt/proc &&
sudo umount /mnt/dev/pts &&
sudo umount /mnt/dev &&
sudo umount /mnt
Congratulations! You've restored / reinstalled your GRUB bootloader!
Now, you can reboot the computer (remove the USB drive if asked) and GRUB will be visible.
I hope this tutorial helps you. If you experience any kind of problem, or if you have doubts, drop them in the comment section.
Happy Linuxing :)
P.S: Credit goes to howtoubuntu.org (I've used their method as the template. I've corrected the mistakes in it and gave you the article).
Comments
Post a Comment