Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Using libvirt, I want to use QEMU's '-snapshot' option. That way, when the machine shuts down, all of the disk changes that were made get destroyed.

Here is the manual for the -snapshot option:

Write to temporary files instead of disk image files. In this case, the raw disk image you use is not written back. You can however force the write back by pressing C-a s.

Similar abilities exist that almost do what I want (qcow2 overlay images, libvirt backing store), but the difference is that I want a fresh environment every time I boot up the VM. Is this possible?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

The only way to add command-line switches that libvirt doesn't support yet is to create a wrapper script and change your VM's configuration to use it instead. For example,

# cat >/usr/local/bin/qemu-snapshot <<'END'
#!/bin/sh
exec /usr/bin/qemu "$@" -snapshot
END
# chmod +x /usr/local/bin/qemu-snapshot
# virsh -c qemu:///system edit my_vm
change
    <emulator>/usr/bin/qemu</emulator>
to
    <emulator>/usr/local/bin/qemu-snapshot</emulator>

(It might be /usr/bin/kvm or something like that for you.)

share|improve this answer
1  
Nice solution, looking forward to playing around with this on other switches unsupported by libvirt too. –  nedm Feb 11 '10 at 5:07
    
Thanks, that worked. One further bit of trouble I had was I was getting the error "error: internal error cannot parse QEMU version number in ''". I had to add my script to my apparmor profiles. See: bugs.launchpad.net/ubuntu/+source/libvirt/+bug/490370 –  user34480 Feb 11 '10 at 20:52

You just have to send kvm's monitor commit all to make the equivalent of CTRL+a...

share|improve this answer

Have you figured out how to commit snapshot changes to disk img? C-a s doesn't seem to do squat. even tried, ctrl ctrl ctrl-a s. virsh doesn't have a commit command either.

If you figured it out, passing that along would be very helpful! :D

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.