Reputation: 3296
I would like to use libvirt to run multiple Domains (VMs) based on the same image at once. The image itself should not be modified. The image should be considered as a starting point or template.
An obvious possibility would be to create a (temporary) copy for every domain. Since the image might take multiple GB, I don't want to create a full copy of it every time. It would like to store differences only. As I understand the documentation, external snapshots are using such technics. But it seems that snapshots are bound to a domain and I cannot use them as template.
According to documentation of qemu, I could use qemu directly while passing option -snapshot
. As far as I'm not committing changes manually, it should work.
qemu-system-x86_64 -snapshot -hda <image>
Is there a way to achieve something similar in libvirt?
Upvotes: 9
Views: 11006
Reputation: 336
All you need is to use qcow2 backing files. In the next steps I'll assume that you already have your base image as a qcow2.
Create a disk image backed by your base image:
qemu-img create -f qcow2 \
-o backing_file=/path/to/base/image.qcow2 \
/path/to/guest/image.qcow2
Then in your guest, use /path/to/guest/image.qcow2
as disk. This file will only get the difference with the base image.
Check qemu-img's man page for more details. qemu-img also has commands to commit the overlay file changes into the base image, rebase on another base, etc.
Upvotes: 15