You will, not might, need this at some point in time. It will happen to you. :) When you find that grub2 is no longer on your MBR so the system will not boot or even find grub. For example you installed Windows, dumb move, but heh! You may also have cloned the hard disk and forgot to copy the MBR.
This will get you back up and running again!
You will need an Ubuntu LIVE cd or Desktop for your current install. Boot the system with Live cd. Once booted open a terminal.
sudo fdisk -l
Disk /dev/sda: 250.1 GB, 250059350016 bytes 255 heads, 63 sectors/track, 30401 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00032781 Device Boot Start End Blocks Id System /dev/sda1 * 1 31 248976 83 Linux /dev/sda2 32 29780 238958842+ 83 Linux /dev/sda3 29781 30401 4988182+ 5 Extended /dev/sda5 29782 30401 4980150 82 Linux swap / Solaris
Mount the partition that has your root directory in it, my the case above that would be /dev/sda1. mount it directly in /mnt as we will chroot it later. You also need to /dev/and /proc to their subdirectories in /mnt. If you have a separate /boot partition then mount that too, as /mnt/boot
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
We can now create a chroot environment at /mnt and then proceed to install grub2.
sudo chroot /mnt
After chrooting, you we will have changed user to root so not need to sudo.
Now we are ready to install/reinstall Grub2.
grub-install /dev/sda
If you get errors with that command try running the next command too
grub-install --recheck /dev/sda
Make sure to rebuild the menus with the new disk info
update-grub
Now you can exit the chroot, umount the system and reboot your with your shiny new grub2 install :D
exit
sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys
sudo umount /mnt
sudo reboot