This applies to the situation that when Windows and Ubuntu coexist on a computer and we reinstall Windows for some reasons, the Grub loader is lost. However, Ubuntu is still there. Do the following to recover.

2. sudo grub
3. Use find /boot/grub/stage1 to find where the Grub is installed. For example (hd0,6).
4. root (hd0,6)
5. setup (hd0)
6. quit
7. Restart the computer, and it’s done!

Update: with the introduction of Grub 2, the above method is not working. See here for a solution, adapted for my case below.

1. Use gparted to figure out where the system has been installed. For my case, / is at /dev/sda11, and /home is at /dev/sda9.
2. Mount the root directory. mount /dev/sda11 /mnt
3. Install the Grub 2 loader. grub-install --root-directory=/mnt/ /dev/sda
4. Restart the system and the Grub 2 loader is shown.
5. Use the following to boot the system.
grub> find /boot/grub/core.img
grub> root (hdx,y)   (previous command will output the x,y)
grub> kernel /boot/grub/core.img
grub> boot

6. After the system is booted, install the bootloader. sudo grub-install /dev/sda