libvirt and qemu/kvm -snapshot option

6,590

Solution 1

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

Solution 2

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

Share:
6,590

Related videos on Youtube

Admin
Author by

Admin

Updated on September 17, 2022

Comments

  • Admin
    Admin over 1 year

    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?

  • antpaw
    antpaw over 14 years
    Nice solution, looking forward to playing around with this on other switches unsupported by libvirt too.
  • Admin
    Admin over 14 years
    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