I have a computer which grub broke on many times and setup a system for repairing grub anytime that died thanks to the wonderful folks over at #grub on irc.freenode.net.
To do this, you'll need to boot to a live Ubuntu environment for your respective version.
Since my commands are aging, and I haven't done them in quite some time, please do not do the "OPTIONAL" marked ones unless you know of some good reason to do them.
Here are the commands I run:
- mount /dev/sda1 /mnt (for your partition)
- mount -B /dev /mnt/dev
- mount -B /proc /mnt/proc
mount -B /sys /mnt/sys
/--------------- OPTIONAL ---------------\
grub-install /dev/sda --root-directory=/mnt
\--------------- -------- ---------------/
- chroot /mnt
- update-grub
update-initramfs -ck all
/--------------- OPTIONAL ---------------\
- apt-get install grub-pc
- grub-mkconfig -o /boot/grub/grub.cfg
- grub-install /dev/sda
- grub-install --recheck /dev/sda
\--------------- -------- ---------------/
- umount /mnt/sys
- umount /mnt/proc
- umount /mnt/dev
- umount /mnt
- reboot
Use sudo where necessary.
Sources: