Like many other popular Linux distributions, Ubuntu Linux also uses the GRUB2 bootloader. Thus, if your GRUB2 stops working, you won’t be able to boot into your Linux device. Whether another operating system has overwritten your GRUB2 configuration or you simply deleted configuration files by accident, you won’t be able to boot until you restore your GRUB2 to normal. Thankfully, there are multiple ways to fix it. In this article, we are going to show you two easy methods to recover GRUB2 using a bootable Ubuntu storage media. Let’s get straight into the action.
1. Recover GRUB2 Using Boot Repair When Ubuntu Won’t Boot (Graphical Method)
Boot Repair is an open-source graphical tool that allows you to restore the GRUB2 using a few simple clicks. If you’re having a problem with your GRUB2, this is the perfect tool to repair it (In most cases), even if your Ubuntu device won’t boot. However, since your Ubuntu Linux device is refusing to boot, you need a bootable Ubuntu Linux storage media to boot into your computer first. Once you get your hands on a bootable storage media, and know Ubuntu won’t boot, do this to recover GRUB2 on your PC:
- Shut down your computer and connect the bootable storage media to it.
- Power on your PC and start pressing the “F1/ F2/ F10/ F12” key to enter the “BIOS settings.” Remember, the exact function key you need to press to enter BIOS will be depending on your PC’s model and its manufacturer. To get more information, visit your PC manufacturer’s official website and contact customer support.
- Once you enter the BIOS settings, set the live Ubuntu Linux storage media as the bootable drive and exit the BIOS settings.
- After your PC boots, click on the “Try Ubuntu” option. Make sure you have a stable internet connection before proceeding any further.
- Next, use “Dash” to open the “Terminal” window.
- Once you’re in Terminal, type and execute these commands in the following manner:
- sudo apt-add-repository ppa:yannubuntu/boot-repair
- sudo apt-get update
- sudo apt-get install -y boot-repair
- boot-repair
- The previous set of commands will install and launch Boot Repair on your PC. Once you execute the 4th command, “boot-repair,” the Boot Repair window will show up and the application will automatically start scanning your PC.
- After the scan is complete, click on the “Recommended Repair” option.
- Now, follow the instructions that appear on your PC screen. Occasionally, the instructions might ask you to copy-paste various command lines on the Terminal. After performing every instruction, click on the “Forward” option to continue throughout the instruction screen.
- Once Boot Repair finishes its job, restart your computer and immediately take the bootable storage media out of your computer.
That’s it. This procedure should recover your GRUB2 and your computer will boot without an issue.
2. Restore GRUB2 Using Terminal
Do you want to recover GRUB2 without relying on any third-party software when Ubuntu won’t boot? Don’t worry. You can still do so using your Terminal. However, you would still need a bootable Ubuntu storage media to use this method. Also, you need to make sure that the live storage media has the same version of Ubuntu as your computer. For example, if your PC has Ubuntu version 16.04, the OS in the bootable Ubuntu storage media must be Ubuntu 16.04 as well. Once you meet the requirements we have mentioned above, follow these instructions to recover GRUB2 using the Terminal:
- First, follow steps 1-5 mentioned in the previous method to open the “Terminal” after you boot into the live Ubuntu environment.
- Now, you need to identify which partition your PC’s Ubuntu Linux OS is installed in typing and executing these set of commands in the following order:
- sudo fdisk -1
- sudo blkid
The “sudo fdisk -1” command will help you identify the Ubuntu partition by mentioning “Linux” in the “Type” column. Meanwhile, the “sudo blkid” command will help you identify the partition by showing the “ext4” file system in the “Type” column. If the Terminal shows multiple “ext4” files, check the device name and the partition size to pinpoint the exact Ubuntu partition you need to look out for.
- Next, execute these commands in the following manner:
- sudo mkdir /mnt/ubuntu
- sudo mount /dev/sdX# /mnt/ubuntu
Here, you need to replace the “/dev/sdX#” of the second line of command with the device name of your Ubuntu partition. For example, if your Ubuntu partition device name is “/dev/sda2,” then the second line of the command will look like this:
sudo mount /dev/sda2 /mount/ubuntu
- Finally, you have to reinstall GRUB from the bootable Ubuntu storage device. To do that, execute this command in the Terminal:
- sudo grub-install –boot-directory=/mnt/ubuntu/boot /dev/sdX
Here, you need to replace “/dev/sdX” with the device name of the hard disk drive of your computer. Please note that you need to replace the code with the “hard disk drive name,” and not the “Ubuntu partition name.” From the previous example, if the Ubuntu partition name is “/dev/sda2,” then the hard disk drive name would omit the number, and it would be “/dev/sda.” Therefore, the command line would look something like this:
- sudo grub-install –boot-directory=/mnt/ubuntu/boot /dev/sda
- Now, once the Terminal responds with “Installation finished,” restart your PC and immediately disconnect the bootable storage media from your computer. Your GRUB2 should be fixed, and your PC should boot normally.