Saturday, August 15, 2015

Grub recovery : Recover the gnu linux boot menu after windows installation

If you happen to install any gnu/linux OS distros before Windows installation, the Windows makes itself start by default and the gnu/linux distro disappears from boot menu.

So, how to recover the grub ? It's pretty simple.
Use the Live CD/USB of gnu/linux distro, say, Ubuntu.

The steps mentioned below are tested on Ubuntu versions 11.04, 11.10 and 12.04.

--------------------------------------------------------------------------------------------

Open the Terminal and follow these steps:

theTechGeany:~$ sudo fdisk -l | more


Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4b2459d9

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      102400    7  HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2              13        3053    24414208    7  HPFS/NTFS
/dev/sda3            3053       10456    59468800   83  Linux        <=====[Note sda<number> of THIS Partition.sda3 in my laptop]
/dev/sda4           10456       38913   228581217+   5  Extended
/dev/sda5           10706       20104    75497436    b  W95 FAT32
/dev/sda6           20105       29503    75497436    b  W95 FAT32
/dev/sda7           29504       38913    75585793+   b  W95 FAT32

Disk /dev/sdb: 4089 MB, 4089445376 bytes
126 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 7812 * 512 = 3999744 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00059dc3

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        1022     3991901    c  W95 FAT32 (LBA)



theTechGeany:~$ sudo mount /dev/sda3 /mnt    <======[Use "Your" appropriate sda<number> here. sda3 in my system]



theTechGeany:~$ sudo grub-install --root-directory=/mnt /dev/sda
Installation finished. No error reported.



theTechGeany:~$ sudo update-grub                
# might get error. /usr/sbin/grub-probe: error: failed to get canonical path of `/cow`
# might get error. cannot find device for /
Solution (follow these only if you get any error)
        $ for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done    # mount you virtual filesystems

        $ sudo chroot /mnt (get into root and now install)
        # update-grub
It should run successfully.


Now Shutdown. Remove the Pen Drive/CD. Power On.
Grub Should be Corrected now and you can choose between the OS available.

No comments:

Post a Comment