Core Linux

Putting Life In “grub rescue” – Linux

I was try to dual boot (ubuntu + windows). After successfully installing ubuntu i am going to install windows but when windows installation is completed and system is reboot. I got the following error

Ok, Friends we got the above error so in this blog we are going to resolve this error and understand deep concept  behind this

Why This Error Come

  • Whenever you install any operating system on hardware to loading that operating system on hardware it required the bootloader.
  • Every operating system has it own bootloader like for windows it may be the NTLDR or for ubuntu it is grub or for macOS it is bootx.
  • Primary working of bootloader is to load the operating system.
  • Now come back to our error. Before explaining topic I want share some case with you
  • Case I :-  When we first install ubuntu it come with it own bootloader called grub2 and it will work fine but we you are going to install second operating system windows that time windows replace grub2 with it own bootloader called NTLDR and it complete installation. Now you reboot the system it load windows operating system.
  • Case II:-  When we first install window it come with it own bootloader called NTLDR and it will work fine but we you are going to install second operating system ubuntu that time ubuntu replace NTLDR with it own bootloader called grub and it complete installation. Now you reboot the system it will show both windows and ubuntu. If you select ubuntu it will load ubuntu OS or else you select windows it will load windows OS.
  • Case III:- Consider you do Dual boot with first case and you want both operating system then below solution will help you.
  • Now we are see why grub rescue error come
    • If your grub bootloader is corrupted.
    • When you delete any partition which contains operating system.
    • When you change the starting and ending blocks of any partition which contains operating system.

Requirements To Solve Error

  • You must have required a live DVD/USB of the same version of OS
  • You must have internet connection(for package installation)

How To Fix Error

We see that why this error is come now we are going to resolve this problem. Just follow the proper following step and your ubuntu will be recover. Start with like I mention is requirement section you required ubuntu bootable DVD/USB. Insert that ubuntu bootable to your system and boot with that DVD/USB. When the system is up follow the following steps

1. Identify Your Root Partition(of ubuntu)

    • Open a terminal(Ctrl+Alt+T)
    • Be the Root User using “sudo su” command
    • Check partition using “fdisk -l” command

Here, you will see the drive name and partition number. It should look like sdXY. Where X is the drive letter and Y is the partition number. Usually it should be like sdb1.  You have to recognize the partition which has your older boot is installed.

2. Mount That Root Partition(of ubuntu)

Once we have got the partition where ubuntu has been installed, we’ll mount the that partition temporary location

    • Create directory called /mnt/temp using “mkdir /mnt/temp”
    • Mount the Ubuntu partition on it using “mount /dev/sdXY /mnt/temp”

    XY is replace by drive and partition letter.

3. Mount /dev , /proc and /sys directory

Before command we should understand imp of /dev directory in linux

The /dev directory contains the special device files for all the devices. Now many point is linux consider all device as a file. Device related files is add to /dev directory on run time when system is booting.

So as of now we should mount our current live system /dev directory on temporary mount system /dev directory.

    • mount /dev directory using “mount –bind  /dev /mnt/temp/dev ”

/proc is very special in that it is also a virtual filesystem. In this /proc directory contains all files related running process.

The sysfs file system enumerates the devices and busses attached to the system into a file system hierarchy that can be accessed from user space.

    • mount /proc directory using “mount –bind  /proc /mnt/temp/proc ”
    • mount /sys directory using “mount –bind  /sys /mnt/temp/sys ”

4. Do CHROOT To That Temporary mounted ubuntu

chroot is run command or with special root directory

    • Do chroot to temporary mounted ubuntu using “chroot /mnt/temp”

If the above commands run successfully, you will see the root@ubuntu:/# in the terminal indicating that you are in chroot mode.

5. Fire Update Command

After chroot the fire update command it will update the package versions of the system

    • Update using “apt-get update”

6. Purge Grub packages

Now we are going to purge grub package

    • Grub purge using “apt-get purge grub-common grub-pc ”

7. Install Grub Package

Now we are going to install grub package which load our operating system.

    • Grub installation using “apt-get install grub-common grub-pc ”

8. Fire Update-Grub Command

Now we are going to fire update-grub command which will find all operating system From Hard Disk using OS-probe.

    • Grub update using “update-grub”

9. Unmount the partition

Unmount the all mounted partition from that system

    • Unmount /mnt/temp/dev using “umount /mnt/temp/dev”
    • Unmount /mnt/temp/sys using “umount /mnt/temp/sys”
    • Unmount /mnt/temp/proc using “umount /mnt/temp/proc”
    • Unmount /mnt/temp/ using “umount /mnt/temp/”

10. Reboot The System

Now it time to reboot your system.