3

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?

4 Answers 4

4

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.)

2
  • 1
    Nice solution, looking forward to playing around with this on other switches unsupported by libvirt too.
    – nedm
    Feb 11, 2010 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, 2010 at 20:52
1

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

0

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

0

note

xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0

in header, and just inspect that. This almost works!

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>...</name>
  <memory unit='KiB'>...</memory>
  <os>
    <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
  </os>

  <qemu:commandline>
     <qemu:arg value='-snapshot'/>
  </qemu:commandline>

  <devices>
    <emulator>/usr/bin/kvm</emulator>

    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/tmp/some/existing/image.qcow2'/>
      <target dev='hda' bus='ide'/>
<!--
    https://bugzilla.redhat.com/show_bug.cgi?id=832194
      <transient />
-->
    </disk>
  </devices>
</domain>

Unfortunatelly, this hapen:

internal error: process exited while connecting to monitor: qemu-system-x86_64: -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1: Device needs media, but drive is empty
qemu-system-x86_64: -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1: Device initialization failed.
qemu-system-x86_64: -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1: Device 'ide-hd' could not be initialized

But anyway this is much more clean way to pass custom qemu arguments

You must log in to answer this question.