How to clone a LVM volume group
These methods allow to clone an LVM volume group and it's logical volumes. Both methods can be used when you need to create two or more identical instances of a volume group leaving them completely independent. The "lvsplit" command offers the easiest procedure when the logical volumes can coexist as members of the same volume group.
These methods rely heavily on the fact that volume group commands affect only the first physical extent, and that the filesystems are left intact if the same PE size is used.
Using "vgcfgrestore"
Alejandro Marin
This is a clean method. The main advantage is that it doesn't produce distracting error messages. The main disadvantage is that it requires you to prepare a volume group map file in advance to import back the volume group.
In this example, we are going to clone /dev/vg01 volume groups and logical volume into /dev/vg02.
1. Create vg01 and vg02 volume groups using the exact same paramete
# mkdir /dev/vg01 # mkdir /dev/vg02 # mknod /dev/vg01/group c 64 0x010000 # mknod /dev/vg02/group c 64 0x020000 # pvcreate -f /dev/rdsk/c4t9d0 # pvcreate -f /dev/rdsk/c4t11d0 # vgcreate /dev/vg01 /dev/dsk/c4t9d0 # vgcreate /dev/vg02 /dev/dsk/c4t11d0 # lvcreate -l 10 /dev/vg01 # lvcreate -l 20 /dev/vg01 # lvcreate -l 30 /dev/vg01 # lvcreate -l 10 /dev/vg02 # lvcreate -l 20 /dev/vg02 # lvcreate -l 30 /dev/vg02
2. Create a volume group map file from /dev/vg02
# vgexport -p -m /vg02.map /dev/vg02
3. Create the filesystems on /dev/vg01, mount them and place some information to verify that the data is in place after the cloning.
# newfs -F vxfs /dev/vg01/rlvol1 # newfs -F vxfs /dev/vg01/rlvol2 # newfs -F vxfs /dev/vg01/rlvol3 # mkdir /test1 # mkdir /test2 # mkdir /test3 # mount -F vxfs /dev/vg01/lvol1 /test1 # mount -F vxfs /dev/vg01/lvol2 /test2 # mount -F vxfs /dev/vg01/lvol3 /test3 # echo "This is LVOL1" > /test1/LABEL # echo "This is LVOL2" > /test2/LABEL # echo "This is LVOL3" > /test3/LABEL
4. Export the /dev/vg02 volume group.
# vgchange -a n /dev/vg02 # vgexport /dev/vg02
5. Extend /dev/vg01 volume group and create LVM logical volume mirrors of the /dev/vg01 logical volumes.
# pvcreate -f /dev/rdsk/c4t11d0 # vgextend /dev/vg01 /dev/dsk/c4t11d0 # lvextend -m 1 /dev/vg01/lvol1 /dev/dsk/c4t11d0 # lvextend -m 1 /dev/vg01/lvol2 /dev/dsk/c4t11d0 # lvextend -m 1 /dev/vg01/lvol3 /dev/dsk/c4t11d0
6. Reduce the logical volume. The logical volume will not longer be mirrored, but the filesystem date will still be available on the physical volumes.
# lvreduce -m 0 /dev/vg01/lvol3 /dev/dsk/c4t11d0 # lvreduce -m 0 /dev/vg01/lvol2 /dev/dsk/c4t11d0 # lvreduce -m 0 /dev/vg01/lvol1 /dev/dsk/c4t11d0 # vgreduce /dev/vg01 /dev/dsk/c4t11d0
7. Use vgcfgrestore to put the LVM configuration data back in /dev/vg02.
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c4t11d0
Note:
- This warning will be displayed alerting that /dev/vg02 is not longer on the /etc/lvmtab. This is a consecuence of having exported the /dev/vg02.
"vgcfgrestore: Volume group "/dev/vg02" does not exist in the "/etc/lvmtab" file. Volume Group configuration has been restored to /dev/rdsk/c4t11d0"
8. Recreate the configuration files for /dev/vg02 and import /dev/vg02 using the map file created on step 2.
# mkdir /dev/vg02 # mknod /dev/vg02/group c 64 0x020000 # vgimport -m /vg02.map /dev/vg02 /dev/dsk/c4t11d0
9. Verified that the logical volume structure has been imported sucessfully.
# ll /dev/vg02 crw-rw-rw- 1 root sys 64 0x020000 Aug 4 05:57 group brw-r----- 1 root sys 64 0x020001 Aug 4 05:57 lvol1 brw-r----- 1 root sys 64 0x020002 Aug 4 05:57 lvol2 brw-r----- 1 root sys 64 0x020003 Aug 4 05:57 lvol3 crw-r----- 1 root sys 64 0x020001 Aug 4 05:57 rlvol1 crw-r----- 1 root sys 64 0x020002 Aug 4 05:57 rlvol2 crw-r----- 1 root sys 64 0x020003 Aug 4 05:57 rlvol3
10. Activate /dev/vg02.
# vgchange -a y /dev/vg02
11. Test that the logical volumes can me mounted.
# umount /test1 # umount /test2 # umount /test3 # mount -F vxfs /dev/vg02/lvol1 /test1 # mount -F vxfs /dev/vg02/lvol2 /test2 # mount -F vxfs /dev/vg02/lvol3 /test3
Using "pvchange"
José Pla
This is an unclean method. The main advantage is that don't require to prepare volume group map files in advance. The main disadvantage is that produce distracting error messages and required that the system is fully patched to enable the OLR feature.
1. Create the volume group that needs to be cloned.
# mkdir /dev/vg01 # mknod /dev/vg01/group c 64 0x010000 # pvcreate -f /dev/rdsk/c4t9d0 # pvcreate -f /dev/rdsk/c4t11d0 # vgcreate /dev/vg01 /dev/dsk/c4t9d0 /dev/dsk/c4t11d0
2. Create the mirrored logical volumes.
# lvcreate -l 10 -s y -m 1 /dev/vg01 # lvcreate -l 20 -s y -m 1 /dev/vg01 # lvcreate -l 30 -s y -m 1 /dev/vg01
3. Create the filesystems on /dev/vg01, mount them and place some information to verify that the data is in place.
# newfs -F vxfs /dev/vg01/rlvol1 # newfs -F vxfs /dev/vg01/rlvol2 # newfs -F vxfs /dev/vg01/rlvol3 # mkdir /test1 # mkdir /test2 # mkdir /test3 # mount -F vxfs /dev/vg01/lvol1 /test1 # mount -F vxfs /dev/vg01/lvol2 /test2 # mount -F vxfs /dev/vg01/lvol3 /test3 # echo "This is LVOL1" > /test1/LABEL # echo "This is LVOL2" > /test2/LABEL # echo "This is LVOL3" > /test3/LABEL
4. Disable access to one of the mirror physical volumes.
# pvchange -a n /dev/dsk/c4t1d0
5. Force reduce the mirrors on /dev/vg01
# lvreduce -k -m 0 /dev/vg01/lvol1 # lvreduce -k -m 0 /dev/vg01/lvol2 # lvreduce -k -m 0 /dev/vg01/lvol3
7. Remove the inactive physical volume from /dev/vg01 volume group.
# vgreduce -l vg01 /dev/dsk/c4t1d0
8. Recreate the configuration files for /dev/vg02, create a volume group map file and import /dev/vg02 using the inactive physical volume and the created map file.
# mkdir /dev/vg02 # mknod /dev/vg02/group c 64 0x020000 # vgexport -p -m vg02.map vg01 # vgimport -m vg02.map /dev/vg02 /dev/dsk/c4t1d0 vgimport: Warning: Volume Group contains "2" PVs, "1" specified. Continuing. vgimport: Quorum not present, or some physical volume(s) are missing. Warning: A backup of this volume group may not exist on this machine. Please remember to take a backup using the vgcfgbackup command after activating the volume group.
9. Enable the /dev/vg02 volume group with quorum disable and reenable the physical volume. The logical volumes will contained wrong stale partitions.
# vgchange -a y -q n vg02 Activated volume group vgchange: Couldn't re-synchronize stale partitions of the logical volume: I/O error Volume group "vg02" has been successfully changed.
# pvchange -a y /dev/dsk/c4t1d0 Physical volume "/dev/dsk/c4t1d0" has been successfully changed. # lvdisplay -k -v /dev/vg02/lvol1 --- Logical volumes --- LV Name /dev/vg02/lvol1 VG Name /dev/vg02 LV Permission read/write LV Status available/stale Mirror copies 1 Consistency Recovery MWC Schedule parallel LV Size (Mbytes) 40 Current LE 10 Allocated PE 20 Stripes 0 Stripe Size (Kbytes) 0 Bad block on Allocation strict IO Timeout (Seconds) default --- Distribution of logical volume --- PV Name LE on PV PE on PV /dev/dsk/c4t1d0 10 10 --- Logical extents --- LE PV1 PE1 Status 1 PV2 PE2 Status 2 00000 0 00000 stale 1 00000 current 00001 0 00001 stale 1 00001 current 00002 0 00002 stale 1 00002 current 00003 0 00003 stale 1 00003 current 00004 0 00004 stale 1 00004 current 00005 0 00005 stale 1 00005 current 00006 0 00006 stale 1 00006 current 00007 0 00007 stale 1 00007 current 00008 0 00008 stale 1 00008 current 00009 0 00009 stale 1 00009 current
10. Force reduce the /dev/vg02 logical volumes to remove the stale references. Check that the stale extends are removed.
# lvreduce -m 0 -A n -k /dev/vg02/lvol1 0 # lvreduce -m 0 -A n -k /dev/vg02/lvol2 0 # lvreduce -m 0 -A n -k /dev/vg02/lvol3 0 # lvdisplay -v /dev/vg02/lvol1 --- Logical volumes --- LV Name /dev/vg02/lvol1 VG Name /dev/vg02 LV Permission read/write LV Status available/syncd Mirror copies 0 Consistency Recovery MWC Schedule parallel LV Size (Mbytes) 40 Current LE 10 Allocated PE 10 Stripes 0 Stripe Size (Kbytes) 0 Bad block on Allocation strict IO Timeout (Seconds) default --- Distribution of logical volume --- PV Name LE on PV PE on PV /dev/dsk/c4t1d0 10 10 --- Logical extents --- LE PV1 PE1 Status 1 00000 /dev/dsk/c4t1d0 00000 current 00001 /dev/dsk/c4t1d0 00001 current 00002 /dev/dsk/c4t1d0 00002 current 00003 /dev/dsk/c4t1d0 00003 current 00004 /dev/dsk/c4t1d0 00004 current 00005 /dev/dsk/c4t1d0 00005 current 00006 /dev/dsk/c4t1d0 00006 current 00007 /dev/dsk/c4t1d0 00007 current 00008 /dev/dsk/c4t1d0 00008 current 00009 /dev/dsk/c4t1d0 00009 current
11. Test that the logical volumes can me mounted.
# umount /test1 # umount /test2 # umount /test3 # mount -F vxfs /dev/vg02/lvol1 /test1 # mount -F vxfs /dev/vg02/lvol2 /test2 # mount -F vxfs /dev/vg02/lvol3 /test3