Recovering LVM2 with Debian Installer RC2

Your disk with a LVM2 configuration and Debian GNU/Linux just died. You have a backup on another server and another disk you can recycle to recover. What do you do?

If you’re running Debian, you can just use that nifty Debian Installer CD you used for your initial install to recover. It has the LVM tools you need, not to mention automatic hardware detection and OpenSSH. Let’s rock.

First, stick the DI CD in the box you want to recover on. Reboot with your replacement disk. Select expert26 to jump right into the installer. Run through the configuration, especially Detect and mount CD-ROM. When you make it to Load installer components from CD make sure you choose to load lvmcfg: Configure the Logical Volume Manager. Also select openssh-client-udeb…. You may want mdcfg: Configure MD devices, but I did not. Configure the network and Detect hardware. You’ll need network access later.

Drop to console with ALT-F2. How shiny. You’ll want dm-mod.

~ # modprobe dm_mod

There are two ways you can fly with this.

If you’re restoring to disks the same size or larger, you can restore your partition tables from backup. Next, you can use vgcfgrestore to restore your LVM2 LVs from backup, in /etc/lvm/backup.

If you’re restoring to some alternate setup, as I am, it’s time for some fun. Your previous configuration is possibly worthless, so it’s time to recreate your LVM setup by hand. In my case, my previous VG was sys and my previous, sole LV was root. I’m going to simply recreate those. Adjust as necessary for your setup.

~ # pvcreate /dev/ide/host0/bus1/target0/lun0/part5
~ # vgcreate sys /dev/ide/host0/bus1/target0/lun0/part5
~ # lvcreate -n root -L 2G sys
~ # mkfs.reiserfs /dev/mapper/sys-root

With that magic done, it’s time to find a way to get the data back onto the box.

In the box of tools I found ssh and cat. Close enough. I copied a static copy of rsync on a neighboring box.

jasonb@faith:~/src/rsync-2.6.3 $ CFLAGS="-static" ./configure
jasonb@faith:~/src/rsync-2.6.3 $ make
jasonb@faith:~/src/rsync-2.6.3 $ file rsync
rsync: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
for GNU/Linux 2.2.0, statically linked, not stripped

Now it’s time to retrieve it.

~ # cd /tmp
/tmp # ssh jasonb@faith 'cat ~/src/rsync-2.6.3/rsync' > rsync
/tmp # chmod u+x rsync

Excellent. Now, assuming you backed up the whole filesystem tree with Dirvish you can restore simply.

/tmp # mount -t reiserfs /dev/mapper/sys-root /floppy
/tmp # rsync -aH root@sarah:/snapshot/media/media-home/20050206/tree/ /floppy

You’ll want to adjust /floppy/etc/fstab accordingly if anything magic changed.

Next it’s time to install the boot loader. I installed LILO. If your LVM2 configuration or target disk is different, you may need to edit /etc/lilo.conf accordingly.

/tmp # chroot /floppy
# mount -t proc proc /proc
# lilo -b /dev/hdc -t
# lilo -b /dev/hdc

Abort the install and remove the CD as the system reboots. If all is well, you should boot into your LVM’d installation of Linux, ready to rock.

Some useful reference links for LVM2 include: