6

I have a QEMU image with a snapshot stored in it. Right now I'm using libvirt to start it.

However, I want to be able to run more than one instance out of the same image/snapshot.

I guess I can do that by cloning the virtual-hd and installing/creating a new domain (virsh) and then running revert from snapshot. But I want to be able to do that pretty much "on-the-fly" with as little as possible latency from the time I decide I need to run another instance of image X to the time that instance is running from the stored snapshot.

Anyone did anything like that? I started thinking maybe libvirt is not low-level enough for this ?

[EDIT: Sorry if this wasn't clear - I'm talking about a RAM+HD snapshot, not just HD snapshot, which I already know how to create...]

Thanks

2
  • This is both a programming and a system question, so I hope this is the right place. Commented Jun 1, 2014 at 16:18
  • Have you ever managed to get this to work with libvirt and not by using the -snapshot directly on qemu? Commented Jun 26, 2016 at 16:10

1 Answer 1

3
+25

I was able to run multiple concurrent qemu from the same snapshot using a command like the following. (Obviously the -arm, -kernel, -cpu etc. arguments will be different in your case)

qemu-system-arm -hda snapshot.qcow2 -snapshot -kernel some_vmlinux \
                -serial stdio -append 'root=/dev/sda2 rootfstype=ext4 rw'\
                -cpu arm1176 -m 256 -M versatilepb

The important argument here is -snapshot, so that temporary memory is used for disk writes.

What I havent tried is forcing a writeback to the underlying device, I suspect all manner of havoc could occur if this is possible and it happened... basically, don't forget the -snapshot argument!

If you want some writable storage that is different per instance you probably need to add a second virtual hard disk and have the common snapshot mount that somehow:

qemu-system-arm -hda snapshot.qcow2 -snapshot -kernel some_vmlinux \
                -serial stdio -append 'root=/dev/sda2 rootfstype=ext4 rw'\
                -cpu arm1176 -m 256 -M versatilepb -hdb drive_system1.img &
qemu-system-arm -hda snapshot.qcow2 -snapshot -kernel some_vmlinux \
                -serial stdio -append 'root=/dev/sda2 rootfstype=ext4 rw'\
                -cpu arm1176 -m 256 -M versatilepb -hdb drive_system2.img &

If you are using networking, dont forget to make the MAC address and any hostfw port values different.

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

3 Comments

Thanks, but it's not exactly what I wanted. I already have a snapshot stored in the qcow2 image (can be watched using qemu-img info <image_file>. I want to be able to revert from THAT snapshot (also includes RAM state)
the solution above is running from a previously created snapshot... admittedly, it doesnt include RAM state, perhaps you could add that requirement to the question?
No worries. Havent tried that with qemu, I usually use virtual box for vms that need memory saved so I'll be watching this with interest....

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.