FAQ: libvirt+kvm

In my current job, I am working constantly with libvirt/kvm combination on Ubuntu based hosts, where I encounter problems with varying degrees of difficulty. From my experience, I’ve compiled following small FAQ:

Q:virsh shutdown vmname doesn’t work. Why?

A: You need ACPI installed on guest. For debian based distro do aptitude install acpid.

Libvirt logo

Q: How to autostart VM “vmname” on boot?

A: virsh autostart vmname

Q: I am getting the following error, while creating snapshot: error: internal error unable to execute QEMU command 'blockdev-snapshot-sync': An undefined error has ocurred

A: Disable apparmor for libvirt:

ln -s /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/
ln -s /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper /etc/apparmor.d/disable/
apparmor_parser -R /etc/apparmor.d/usr.sbin.libvirtd
apparmor_parser -R /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper
reboot

Q: I am getting following error, while creating snapshot: error: internal error unable to execute QEMU command 'transaction': Could not open '/home/user/vmname/rootdisk.snapshot1'

A: Same as above. Disable apparmor.

Q: I get the following error, when I try to execute virsh snapshot-create-as vmname snapshot1 "test snapshot nr.1" --disk-only --atomic command in virsh: error: command 'snapshot-create-as' doesn't support option --atomic

A: Live snapshooting is currently(as of Ubuntu 12.04) not fully implemented. You could try some workarounds.

Q: While trying to merge snapshots back with the original disk via virsh blockpull --domain vmname --path /home/user/vmname.kvm/disk_root.snapshot1 command, I get following error: error: Requested operation is not valid: Command 'block_stream' is not found

A: Live snapshooting is currently(as of Ubuntu 12.04) not fully implemented. You could try some workarounds.

Q: I am running libvirt on Ubuntu server and I would like to create Ubuntu VM. Is there a simple way to achieve this?

A: ubuntu-vm-builder package is designed specifically for this task. You can create a new VM with a command as simple as this one: ubuntu-vm-builder kvm precise --addpkg vim --addpkg openssh-server --mem=2048 --swapsize=2048 -d /home/user/vmname/ --domain=example.com --components 'main,universe,restricted' --rootsize=10240 --cpus=2 --hostname=vmname --ip=172.16.1.2 --mask=255.255.255.0 --net=172.16.1.0 --bcast=172.16.1.255 --gw=172.16.1.1 --dns=172.16.1.1 --bridge=br0 --timezone=Europe/Berlin --libvirt qemu:///system where “precise” is a valid ubuntu distro name, “–addpkg vim –addpkg openssh-server” preinstalls vim and ssh, you will have 2GB of RAM and swap, VM will be saved in /home/user/vmname directory, domain will be set to example.com, you will have 10GB root partition and hostname “vmname“, network interface will be bound to br0 bridge on Host and it will have 172.16.1.2 network address. For more info, man vmbuilder.

One thought on “FAQ: libvirt+kvm”

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? *