Tips for libvirt/virtmanager

Static IP

You can affect a static IP to a guest of a libvirt instance with the following command:

virsh net-update default add ip-dhcp-host "<host mac='52:54:00:7d:2a:5e' name='leap' ip='192.168.122.42' />" --live --config

Launch Virtual Machine manager without a root password

  1. Add the users that need to do this to the libvirt group.
  2. Create a new polkit rule in /etc/polkit-1/rules.d/10-libvirt.rules containing:
polkit.addRule(function(action, subject) {
 if (action.id == "org.libvirt.unix.manage"
         && subject.local
         && subject.active
         && subject.isInGroup("libvirt")) {
     return polkit.Result.YES;
  }
 });

Compress QCOW2 images

Linux guest

Run in the guest:

  1. fstrim -av
  2. dd if=/dev/zero of=/mytempfile
  3. rm -f /mytempfile

Run on the host:

  1. mv image.qcow2 image.qcow2_backup
  2. qemu-img convert -O qcow2 image.qcow2_backup image.qcow2 or if you want compression to further reduce the disk size but reduce performance: qemu-img convert -O qcow2 -c image.qcow2_backup image.qcow2

Then boot your machine and check everything is OK.

Windows guest

Run in the guest:

  1. The defragementer tool
  2. Download sdelete
  3. Run sedelete -z c:

Run on the host:

  1. mv image.qcow2 image.qcow2_backup
  2. qemu-img convert -O qcow2 image.qcow2_backup image.qcow2 or if you want compression to further reduce the disk size but reduce performance: qemu-img convert -O qcow2 -c image.qcow2_backup image.qcow2

Then boot your machine and check everything is OK.


Pages

blogroll

social

>