{{announcement.body}}
{{announcement.title}}

How to Repair Grub

DZone 's Guide to

How to Repair Grub

This post shows how to install grub that has been overwritten by windows, and includes systems with separate boot partition.

· Open Source Zone ·
Free Resource

Last time, installing Windows stopped my Ubuntu from booting-up. After some research, I managed to fix the boot-loader. I thought it might be worth sharing my experience for those who may face the same problem.

First of all, you need a live cd or bootable USB stick of any flavor of Linux distribution. For example, Ubuntu, Mint, or Fedora can be used.

Boot to the live cd or USB that you have and open a terminal window( Ctrl + T ) and type the following: sudo fdisk -l

The output will be like what's on the following image.

Sudo fdisk -l output

We are going to install our grub on the highlighted partition.

sudo blkid: This is used to make sure you have selected the right device, and its output will be (nowadays ext4 is the default file system used):
Sudo blkid output

Now you are sure about where to install grub. By default, grub is installed in the /boot/grub directory when you install Ubuntu or other Linux distros. So you have to mount /dev/sda3 to a directory of your preference. To do this, type the following:

sudo mount /dev/sda3 /mnt, where /mnt is any directory you need.

Note: If you have a separate boot partition, skip the above command and mount the boot partition at /mnt/boot(sudo mount /dev/sdX /mnt/boot).

sudo grub-install --boot-directory=/mnt/boot /dev/sda: Make sure that the last argument( /dev/sda ) must be the device(hard disk), not some particular partition, like /dev/sda3, that you need to install the boot loader on.

Reboot your system, and it should boot properly.

Topics:
boot problem, grub, open source, tutorial, ubuntu, windows

Published at DZone with permission of Amanuel G. Shiferaw . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}