Grub is a Linux bootloader which can boot all conceivable operating systems. Occasionally you will find yourself with a broken grub if you are spending a lot of time in Linux. Specially if you have Windows alongside Linux, re-installing Windows will wipe out grub.
To fix grub with Ubuntu live CD, boot the system from the live CD and open up a terminal.
Step#1. Mount Ubuntu partition
sudo fdisk -l
sudo mount /dev/sdXY /mnt
Replace XY. In my case it is /dev/sda1
If you are not sure where you installed Ubuntu, fdisk or gparted will show all the available partitions in your system. Ubuntu installation should be in a ext4 Linux partition.
Step#2. Mount boot partition(only if you have a separate boot partition)
sudo mount /dev/sdYY /mnt/boot
Replace YY. In my case I do not have a separate boot partition.
Step#3. Mount virtual filesystems(for step 4)
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
Using bind mounts, we can mount all, or even part of an already-mounted filesystem to another location, and have the filesystem accessible from both mount points at the same time.
Chroot is the process of changing of the apparent disk root directory (and the current running process and its children) to another root directory. When you change root to another directory you cannot access files and commands outside that directory. This directory is called a chroot jail. Changing root is commonly done for system maintenance, such as reinstalling the bootloader or resetting a forgotten password.
sudo chroot /mnt
Now we are in the chrooted environment!
Step#5. Install, check, and update grub
grub-install --recheck /dev/sdX
Replace sdX with your boot device. ‘grub-install’ command will perform a complete re-installation of grub.
Step#6 Exit chroot and unmount
sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys
sudo umount /mnt/boot
sudo umount /mnt
Unmount boot partition only if you followed step 2
sudo reboot -h now