This tutorial teaches how to recover GRUB and GRUB2 to boot our Linux system again.
Both when we have installed Linux and Windows on a single hard drive, and we have to reinstall (for any reason) Windows, or if we have Linux and we want to install Windows with it, the Windows MBR may delete the GRUB, so that our Linux cannot boot. In this tutorial, we bring you a solution to recover GRUB and GRUB2.
What is GRUB?
A boot manager developed by the GNU project. It allows us to have multiple operating systems on our PC and boot from each of them.
How to recover GRUB
We will start by recovering the GRUB.
Insert the CD or USB with Linux and restart the PC, start in BIOS mode and configure the boot so that your external device is first. When you finished, save and reboot.
When you start again, you will do it through our Live CD.
Now, we execute the following commands, first:
sudo fdisk -l
Write down the device that has Linux type. In my case sda1. Now it's time to execute:
And in this case, we have to take into account what was seen in the fdisk command. If Linux is in sda the X will be 0, if it is sdb, it will be 1…, and the Y will be the number that appears next to sda, but subtracting 1.
When we finish we close the terminal and restart (do not forget to change the boot order or remove the external device) and we can access our Linux.
How to recover GRUB 2
Now let's see how to recover the GRUB 2 from Ubuntu.
Follow the first to steps in the previous section.
sudo fdisk -l
We will get information, look where it says in Type Linux and write down the Device column, in this case, /dev/sda1.
Now we have to mount the partition, for this we execute:
sudo mount /dev/sda5/mnt
The GRUB bootloader files are installed, execute the following, keep in mind that sda is the boot disk, put yours, mine, in this case, is sda:
sudo grub-install --root-directory=/mnt/ /dev/sda
Restart the PC, without forgetting to change the boot order or remove the external device. This will make us start the Ubuntu that we had installed.
Now we have to execute a few more commands, so reopen the terminal and execute:
sudo grub -mkconfig
It helps us to avoid errors in partitions and that we can start Windows from the GRUB. You'll see many letters come out on screen, quiet is usual, wait until it's over.
Now we execute a command to update the GRUB:
sudo update -grub2
You're done, you should be able to start your PC on both Windows and Linux.