2011-12-17

LUKS + LVM + Backups

Using LVM for storing data is easy, cool and sexy - especially if you come to point you need to resize the partitions as the projects grow. And what about backups? I keep dd bit copy of my drive for the case something bad happens with the master drive. When I wanted to restore just some bits from the drive I came to issues how to mount it because of duplicities. This is how I solved.


Just to check we are fighting in similar dojo:

  • /dev/sda9 - partition marked with type 8e (LVM)

  • partition is encrypted with LUKS

  • LVM contains volume group vgdata

  • vgdata contains several logical volumes

  • whole disk sda cloned to sdb (external usb drive) using dd if=/dev/sda of=/dev/sdb. Side effect is that all UUIDs are same




Boot rescue CD, disconnect the backup drive, change UUIDs on the master drive to avoid duplicities. Of course you can do change UUIDs on the backup drive on different machine for example:

#mount luks device
cryptsetup luksOpen /dev/sdb9 luks-backup
#Change UUIDs on the master drive (disconnect the backup drive)
pvchange -u /dev/mapper/luks-backup
vgchange -u vgdata




Boot back to primary system - rest can be done online as UUIDs of the physical volumes and vggroups are different now.

pvs
WARNING: Duplicate VG name vgdata: zCyBsK-5oAX-fk1T-ZtKu-bJsq-V32U-jefWxT (created here) takes precedence over bM4h3v-C22d-yKLg-k21k-vhaq-VyN4-zxOVtN
WARNING: Duplicate VG name vgdata: Existing zCyBsK-5oAX-fk1T-ZtKu-bJsq-V32U-jefWxT (created here) takes precedence over bM4h3v-C22d-yKLg-k21k-vhaq-VyN4-zxOVtN
PV VG Fmt Attr PSize PFree
/dev/mapper/luks-1c37deed-13d9-4364-bbda-944a4ae42618 vgdata lvm2 a-- 316.70g 136.70g
/dev/mapper/luks-backup vgdata lvm2 a-- 316.70g 91.70g

#This will not work - need to use the UUID
vgrename vgdata vgdata-bak
WARNING: Duplicate VG name vgdata: zCyBsK-5oAX-fk1T-ZtKu-bJsq-V32U-jefWxT (created here) takes precedence over bM4h3v-C22d-yKLg-k21k-vhaq-VyN4-zxOVtN
Found more than one VG called vgdata. Please supply VG uuid.

#Rename the volume group for the backup
vgrename zCyBsK-5oAX-fk1T-ZtKu-bJsq-V32U-jefWxT vgdata-bak

#Make the volume active
lvchange -a y /dev/vgdata-bak/lvdat1

#Mount
mkdir /mnt/bak
mount /dev/vgdata-bak/lvdat1 /mnt/bak



No comments:

Post a Comment