9

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?

1 Answer 1

15

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! I will check it out. :)
It works this way. I would like to avoid calling qemu-img directly but to create such images with libvirt, I have to define storage-pools. I thing I will use qemu-img directly since using libvirt seems to be much overhead in this case.
This command needed a -F qcow2 to work for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.