Lvm – How to clone LVM thin provisioning volume

lvmthin-provisioning

I googled many times but couldn't find an answer. What I want is cloning an LVM thin provisioning volume to another thin volume.

For now I know dd can clone a thin volume as following:

dd if=/dev/mapper/vg_thin01 of=/dev/mapper/vg_thin02 bs=1M

But the new cloned volume will be full size! How can I make it to sparse/thin volume?

(Actually the thin volume will be used for DomU storage in Xen or KVM )

Best Answer

Cloning a thin volume is as simple as taking a snapshot of the to-be-cloned volume. When using thin volumes, snapshot and new volumes really are the same thing, with different default flags.

From the kernel docs:

Once created, the user doesn't have to worry about any connection between the origin and the snapshot. Indeed the snapshot is no different from any other thinly-provisioned device and can be snapshotted itself via the same method. It's perfectly legal to have only one of them active, and there's no ordering requirement on activating or removing them both. (This differs from conventional device-mapper snapshots.)

So it is perfectly legal to snapshot a thinly-provisioned volume to create a CoW clone. From the man page:

Example
       Create first snapshot of an existing ThinLV:
       # lvcreate -n thin1s1 -s vg/thin1