Create multiple VMs based on single image
Asked Answered
A

1

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?

Apperceive answered 12/11, 2016 at 4:26 Comment(0)
G
14

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.

Gleet answered 17/11, 2016 at 14:23 Comment(3)
Thanks! I will check it out. :)Apperceive
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.Apperceive
This command needed a -F qcow2 to work for me.Calli

© 2022 - 2024 — McMap. All rights reserved.