Create "linked clone" or layered shared disks with QEMU
Does QEMU support a feature like VMware's "linked clone"?
What I'm trying to accomplish: I'm setting up a test environment with a handful of VMs, that are all nearly identical. However, a fresh Windows install takes over 20 GiB, which would be duplicated for each VM.
In VMware, one would create a "linked clone", which is most likely a copy-on-write layer atop the original disk image.
Can we do this with QEMU? I'm specifically trying to accomplish this using virt-manager
(libvirt).
Related:
- Linked Cloning? (convirture.com)
QEMU's primary virtual disk format is QCOW2, which stands for QEMU Copy-On-Write 2. It is desiged specifically to enable these kinds of setups.
You can do this manually using qemu-img
. (Skip directly to the second command if you already have a base image)
$ qemu-img create -f qcow2 base-image.qcow2 1M
Formatting 'base-image.qcow2', fmt=qcow2 size=1048576 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
$ qemu-img create -f qcow2 -b base-image.qcow2 linked-image.qcow2
Formatting 'linked-image.qcow2', fmt=qcow2 size=1048576 backing_file='base-image.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
$ qemu-img info base-image.qcow2
image: base-image.qcow2
file format: qcow2
virtual size: 1.0M (1048576 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
$ qemu-img info linked-image.qcow2
image: linked-image.qcow2
file format: qcow2
virtual size: 1.0M (1048576 bytes)
disk size: 196K
cluster_size: 65536
backing file: base-image.qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16