Sunday, December 6, 2009

Reinstalling GRUB with LVM from the Ubuntu cd

This post is mostly a reminder to myself. Every time I reinstall Windows, it overwrites my boot sector, and I need to reinstall it from the Ubuntu live CD to get my dual-boot system back. However, since my Ubuntu install is inside an LVM partition, this is not very straightforward. Here are the instructions. I kept them general so that they may be of use to someone else as well.

  • Start from the Ubuntu CD and open a terminal.
  • Install LVM:
    sudo apt-get install lvm2
  • Find the name of the volume group:
    sudo vgdisplay
  • Make the volume group available:
    sudo vgchange -ay name-of-vg
  • Mount the root and boot file systems, and bind the dev file system:
    sudo mkdir foo
    sudo mount /dev/name-of-vg/name-of-root-lv foo
    sudo mount /dev/name-of-boot-partition foo/boot
    sudo mount -obind /dev foo/dev
  • Change to the root of your system:
    sudo chroot foo
  • Drop into the GRUB prompt:
    sudo grub
  • Install the GRUB MBR (assuming that (hd0) is your boot drive and (hd0,0) your boot partition):
    root (hd0,0)
    setup (hd0)
  • Reboot and have your boot menu back!

No comments: