Category: General

  • Create VG
pvcreate /dev/mapper/...
vgcreate vg0 ...
lvcreate -L10G -nimagename vg0
  • Extend the size of LV
lvextend -L +25GB /dev/vg0/some-disk
e2fsck -f /dev/vg0/some-disk
resize2fs /dev/vg0/some-disk
  • Reduce size of LV
resize2fs /dev/myvg/homevol 524288
lvreduce -L -1G /dev/myvg/homevol
  • Add hard disk to lvm
    # Format the disk to an ext3 file system by running ‘cfdisk /dev/(device identifier)’
    # Run ‘pvscan’ to make sure you can see the new physical volume
    # Run ‘pvcreate /dev/(device)’ to create the partition
    # Use vgextend to add the new hard disk to the volume group (eg vgextend vg0 /dev/sdb1)
    # Unmount the LVM (eg umount /dev/vg0)
    # Extend the volume groups using lvextend for each machine (eg lvextend -L+10GB /dev/vg0/maze)
    # Check the file systems using e2fsck (eg e2fsck -f /dev/vg0/maze)
    # Resize the partition using resize2fs (eg resize2fs /dev/vg0/sorb-disk)
    # Remount the volume group (eg mount /dev/vg0)
    # pvcreate /dev/(device)
    # vgextend vg0 /dev/(device)

 

  •  __Mount lvm partitions__
  • Create mapping
kpartx -a /dev/VolGroup01/hardy1-disk
  • Device /dev/mapper/hardy1-disk1 will be created
  • Delete mapping
kpartx -d /dev/VolGroup01/hardy1-disk

Create an LVM snapshot
lvcreate -L 1G -s -n $SNAPSHOT $VMDISK
  • dd snapshot to a file
dd if=$SNAPSHOT 2>/dev/null|gzip > $BACKUPFILE 
  • Restore the lvm from the file
gunzip -c snapshot.img.gz|dd of=/dev/vg0/destination-disk   
  • Copy and restore with dd over ssh
dd if=/dev/vg0/source-lvm-disk | pv| gzip | ssh root@ 'gunzip | dd of=/dev/vg0/destination-lvm-disk'

OR

ssh root@destination 'dd if=/dev/vg0/source-lvm-disk | gzip'  | gunzip | dd of=/dev/vg0/destination-lvm-disk
  •  __Merge Snapshots__
  • Take snapshot
lvcreate -L 5G -s -n $SNAPSHOT $VMDISK
  • Restore back from the snapshot
lvconvert --merge $SNAPSHOT
  •  __fix broken VG__
  • Run, to determine which device is missing
vgdisplay --partial --verbose
multipath -ll
  • Determine the latest lvm archive log
ls -latr /etc/lvm/archive/
  • Recreate the metadata for missing disk
pvcreate --uuid "XUo7SJ-mbie-vMfI-9dqd-gaLf-UYp9-Jawvl7" --restorefile /etc/lvm/archive/vg0_00085.vg  /dev/mapper/mpath3
  • Restart the lvm
/etc/init.d/lvm restart

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.