Is there a simple way to move/copy a logical volume from one volume group to another? (LVM2)

I'm rearranging a bunch of disks on my server at home and I find myself in the position of wanting to move a bunch of LVM logical volumes to another volume group. Is there a simple way to do this? I saw mention of a cplv command but this seems to be either old or not something that was ever available for Linux.


Solution 1:

If you can arrange for the logical volume to be on a separate subset of physical volumes from the rest of the source volume group (lvconvert sourcevg/sourcelv /dev/pv1 ... may help), you can use vgsplit to split off the lv into a new vg and vgmerge to merge the new vg into the target vg.

Although LVM has a mirroring feature, you can't (sanely) use it to make a copy between volume groups, because both legs of the mirror must live on the same vg and the association can't be broken.

You can copy an LVM volume to another the way you'd copy any volume to another: create a target lv of the appropriate size, then copy the contents with dd if=/dev/sourcevg/sourcelv of=/dev/targetvg/targetlv bs=4M. If the source volume is active, you can leverage LVM to make a consistent copy: first take a snapshot of the source lv with lvcreate -s, then copy the snapshot.

Solution 2:

pvmove -n lvol1 /dev/sdb1 /dev/sdc1

pvmove can move data between physical volumes: LVM Administrator's Guide