Cloning Logical Volume using LVM

Sometime it is necessary to clone full LV (Logical Volume). Here we will try to do this using LVM2 commands. First let's create a test LV:

# lvcreate -n test -L1g /dev/rootvg
# mkfs.ext3 -j -m0 /dev/rootvg/test
# mount /dev/rootvg/test /mnt/s

Copy some files on it to verify the integrity of the content later. Now let's make it a mirror. The --type mirror flag will enforce the use classic LVM mirror instead of newly RAID1 technology, --alloc anywhere lets you create mirror copies on VG wich contains a single PV (that is true in most situation). If your LV is big enough use -b flag to run converting in background.

# lvconvert --type mirror --alloc anywhere -m1 /dev/rootvg/test
  rootvg/test: Converted: 0.00%
  rootvg/test: Converted: 23.44%
  rootvg/test: Converted: 46.88%
  rootvg/test: Converted: 70.31%
  rootvg/test: Converted: 93.75%
  rootvg/test: Converted: 100.00%
# lvs -a -o +devices | egrep "LV|test"
  LV              VG     Attr       LSize .. ove Log       Cpy%Sync Convert Devices                          
  test            rootvg mwi-aom--- 1.00g      [test_mlog] 100.00           test_mimage_0(0),test_mimage_1(0)
  [test_mimage_0] rootvg iwi-aom--- 1.00g                                   /dev/sda5(87200)                 
  [test_mimage_1] rootvg iwi-aom--- 1.00g                                   /dev/sda5(36009)                 
  [test_mlog]     rootvg lwa-aom--- 4.00m                                   /dev/sda5(66575)                 

Check that Cpy%Sync is 100% finished; both copies are in sync then. Now let's break the mirror !

# lvconvert --splitmirrors 1 --name testCopy /dev/rootvg/test
  Logical volume test converted.
# lvs
  LV          VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  test        rootvg -wi-ao----  1.00g                                                    
  testCopy    rootvg -wi-a-----  1.00g                                                    
# mount /dev/rootvg/testCopy /mnt/d

Verify content of /mnt/d if you do not trust LVM technology.

Updated on Fri Feb 17 09:50:15 IST 2017 More documentations here