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