Grub-2 Repair Post Install

Hello reader,

If you aren’t a Linux user this won’t make much sense to you, but feel free to read along anyway. In most cases when we install 2 or more operating systems and Linux is one of them we opt to install Linux second. This is because it writes the menu at the beginning from which we select the operating system to use.

Grand Unified Boot Loader (Grub for short)

However there are times when we may need to repair the grub, such as following a reinstallation of Windows in a dual boot configuration.

There are several methods of doing this and I’ll list them from simplest to most involved:

  1. Booting into the live installation media of your Linux distribution and running a boot repir program.

Obviously booting in to a Ubuntu or Mint distro typically doesn’t give much room to write programs, however it does allow us with sufficient privileges to correct the bootloader.

sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update sudo apt-get install -y boot-repair && boot-repair

After entering your administrative password you’ll be prompted to select from options which include:

Use Recommended Repair

And after that you should find your bootloader in perfect working order. However for non Ubuntu/Mint users there are 2 more methods which need mentioning.

These were all collected from Linux forums i.e. Ubuntu forums etc and should work great. (Fair credit to the users who posted these!)

  1. Boot from the live CD.
  2. Determine the partition number of your main partition. GParted can help you here. I’m going to assume in this answer that it’s /dev/sda2, but make sure you use the correct partition number for your system!
  3. Mount your partition:
    sudo mount /dev/sda2 /mnt  # make sure that sda2 is correct!
    
  4. Bind mount some other necessary stuff:
    for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
    
  5. chroot into your Ubuntu install:
    sudo chroot /mnt
    
  6. At this point, you’re in your install, not the live CD, and running as root. Update grub:
    update-grub
    

    If you get errors, go to step 7. (Otherwise, it is optional.)

  7. Depending on your situation, you might have to reinstall grub:
    grub-install /dev/sda
    update-grub # I'm not sure if this is necessary, but it doesn't hurt.
    
  8. If everything worked without errors, then you’re all set:
    exit
    sudo reboot
    
  9. At this point, you should be able to boot normally.

If you cannot boot normally, and didn’t do step 7 because there were no error messages, try again with step 7.

  • Sometimes giving GRUB2 the correct configuration for your partitions is not enough, and you must actually install it (or reinstall it) to the Master Boot Record, which step 7 does. Experience helping users in chat has shown that step 7 is sometimes necessary even when no error messages are shown.

This final method involves more

https://wiki.ubuntu.com/Grub2#Recover

First of all, you must start your system from a live cd. Then

METHOD 3 – CHROOT

This method of installation uses the chroot command to gain access to the broken system’s files. Once the chroot command is issued, the LiveCD treats the broken system’s / as its own. Commands run in a chroot environment will affect the broken systems filesystems and not those of the LiveCD.

1) Boot to the LiveCD Desktop (Ubuntu 9.10 or later). Please note that the Live CD must be the same as the system you are fixing – either 32-bit or 64-bit (if not then the chroot will fail).

2) Open a terminal (Applications > Accessories > Terminal).

3) Determine your normal system partition – (the switch is a lowercase “L”)

sudo fdisk -l

If you aren’t sure, run

df -Th

Look for the correct disk size and ext3 or ext4 format.

4) Mount your normal system partition:

Substitute the correct partition: sda1, sdb5, etc.

sudo mount /dev/sdXX /mnt

Example: sudo mount /dev/sda1 /mnt

5) Only if you have a separate boot partition: sdYY is the /boot partition designation (for example sdb3)

sudo mount /dev/sdYY /mnt/boot

6) Mount the critical virtual filesystems:

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

7) Chroot into your normal system device:

sudo chroot /mnt

8) If there is no /boot/grub/grub.cfg or it’s not correct, create one using

update-grub

9) Reinstall GRUB 2:

Substitute the correct device – sda, sdb, etc. Do not specify a partition number.

grub-install /dev/sdX

10) Verify the install (use the correct device, for example sda. Do not specify a partition):

sudo grub-install --recheck /dev/sdX

11) Exit chroot: CTRL-D on keyboard

12) Unmount virtual filesystems:

sudo umount /mnt/dev/pts
sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys

13) If you mounted a separate /boot partition:

sudo umount /mnt/boot

14) Unmount the LiveCD’s /usr directory:

sudo umount /mnt/usr

15) Unmount last device:

sudo umount /mnt

16) Reboot.

sudo reboot

#Special thanks to the users who posted these I just wanted
to make them easier to find for my readers!

Spread the love

454 thoughts on “Grub-2 Repair Post Install

  1. Heya this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!

  2. Good day! Would you mind if I share your blog with my twitter group? There’s a lot of people that I think would really enjoy your content. Please let me know. Cheers

  3. Hi there just wanted to give you a brief heads up and let you know a few of the images aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same outcome.

Leave a Reply

Your email address will not be published. Required fields are marked *