LVM vs S/W mirroring comparison environment


  • Test environment consists of a Centos 6.3 Kernel Virtual Machine (guest).
  • Two virtual disks, hdb and hdc, 10 gigs each.

Set up

  • guest shut down:
# virsh list --all
 Id    Name                           State
 9     guest1                         running
 10    python                         running
 -     guest                          shut off
  • Verify no pre-existing disks:
# virsh vol-list default
Name                 Path
guest.img            /var/lib/libvirt/images/guest.img
guest1.img           /var/lib/libvirt/images/guest1.img
python.img           /var/lib/libvirt/images/python.img
  • Create volumes, add them to guest, and restart guest
for x in 1 2
echo virsh vol-create-as default guest-${x}.img 10g
virsh vol-create-as default guest-${x}.img 10g
virsh vol-create-as default guest-1.img 10g
Vol guest-1.img created
virsh vol-create-as default guest-2.img 10g
Vol guest-2.img created
# virsh vol-list default | grep guest
guest-1.img          /var/lib/libvirt/images/guest-1.img
guest-2.img          /var/lib/libvirt/images/guest-2.img
guest.img            /var/lib/libvirt/images/guest.img
guest1.img           /var/lib/libvirt/images/guest1.img
# virsh attach-disk guest /var/lib/libvirt/images/guest-1.img hdb --persistent
Disk attached successfully
# virsh attach-disk guest /var/lib/libvirt/images/guest-2.img hdc --persistent
Disk attached successfully
# virsh domblklist guest
Target     Source
hda        /var/lib/libvirt/images/guest.img
hdb        /var/lib/libvirt/images/guest-1.img
hdc        /var/lib/libvirt/images/guest-2.img
# virsh start guest
Domain guest started
  • Verify new disks on guest
# h
# grep sd /proc/partitions | sort -k 4
   8        0   20971520 sda
   8        1     512000 sda1
   8        2   20458496 sda2
   8       16   10485760 sdb
   8       32   10485760 sdc


Straight forward scrpt to ensure repeatability:


# shut down guest if required:

echo 'Checking if guest is running'
virsh list --all | grep -i guest | grep -v guest1 | \
    grep -qi running && virsh destroy guest

# remove disks from guest:

echo 'Removing test disks from guest'
for pv in $(virsh domblklist guest | grep ^hd | \
    grep -v hda | awk '{print $1}')
    virsh detach-disk guest ${pv} --persistent

# delete disk images:

echo 'Deleting test disks'
for img in $(virsh vol-list default | grep guest- | awk '{print $NF}')
    virsh vol-delete ${img} default

# recreat test disks

echo 'Recreating test disks'
for x in 1 2
    virsh vol-create-as default guest-${x}.img 10g

# attaching test disks to guest:
echo 'Attaching test disks to guest'
virsh attach-disk guest /var/lib/libvirt/images/guest-1.img hdb --persistent
virsh attach-disk guest /var/lib/libvirt/images/guest-2.img hdc --persistent

# restart guest

echo 'restart guest'
virsh start guest