Skip to content

Libvirt

  • Resource monitoring tool: virt-top
  • dom-configs liegen in /etc/libvirt/qemu/
  • logs etc. in /var/lib/libvirt/qemu/

libvirt/kvm install

Steps:

sudo apt install --no-install-recommends qemu-system libvirt-clients libvirt-daemon-system

Configure libvirt

Issues

Autostart after boot fails

Ubuntu bug: Cannot start VMs without routable IPv4 address

If autostart during boot doesn't work and libvirtd logs these errors:

libvirtd[1157]: internal error: Failed to autostart VM 'dapple-agent2':
  internal error: process exited while connecting to monitor:
  2023-07-13T15:22:04.228127Z qemu-system-x86_64: warning:
  Spice: ../server/reds.cpp:2551:reds_init_socket: getaddrinfo(127.0.0.1,5900):#
  Address family for hostname not supported

Add a systemd drop-in /etc/systemd/system/libvirtd.service.d/autostart.conf with this config:

[Unit]
Require=network-online.target
[Service]
# Still wait a bit to prevent libvirt autostarting VMs too early
# https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1492621
ExecStartPre=/bin/sleep 10

Run virsh and access libvirt as a regular user

adduser <youruser>  libvirt
reboot

Boot Live-CD

kvm -cdrom /home/tostado/Software/ubuntu-12.04-beta2-desktop-amd64.iso --network=bridge:virbr0

Libvirt Console Access

in guest VM run the following

systemctl enable serial-getty@ttyS0.service
systemctl start serial-getty@ttyS0.service

in guest VM in /etc/default/grub set

GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0"
GRUB_TERMINAL="serial console"

in guest VM run the following

guest# update-grub

Virt-Manager

Install:

sudo pacman -S virt-manager

Setup:

SSH_ASKPASS in Arch defaults to /usr/lib/ssh/ssh-askpass, if this file doesn't exist export it to a ssh_askpass binary installed, i.e.:

export SSH_ASKPASS=/usr/lib/seahorse/ssh-askpass

German keyboard config

Change the libvirt xml config for that host to

<graphics type='vnc' port='-1' autoport='yes' keymap='de'/>

On the VM, change the keyboard config

dpkg-reconfigure console-data
dpkg-reconfigure keyboard-configuration
service keyboard-setup restart

and reboot it.

Virt-viewer

Install:

sudo pacman -S virt-viewer

Usage:

virt-viewer -c qemu:///system  leap-baseimage
virt-viewer -c 'qemu+ssh://root@dapple/system?known_hosts_verify=ignore' dapple-controlplane
  • Release mouse after grabbed by virt-viewer: Shift + F12

Snapshots

Take snapshot:

virsh snapshot-create-as develop fresh1
virsh snapshot-list develop
virsh snapshot-revert develop fresh1
virsh snapshot-delete develop fresh1

Cloning of VMs

virt-clone -o artful -n artful_fresh_install --auto-clone

Static DHCP leases for VMs

KVM/libvirt: How to configure static guest IP addresses on the virtualisation host

libvirt dnsmasq config file: /var/lib/libvirt/dnsmasq/default.conf

First, find out the MAC addresses of the VMs you want to assign static IP addresses:

virsh  dumpxml  $VM_NAME | grep 'mac address'

Remove possible old lease from lease spool file

/var/lib/libvirt/dnsmasq/default.leases

Add host entries for your VMs

virsh net-update default add ip-dhcp-host --xml "<host mac='52:54:00:73:e9:6c' \
  name='staging.pixelated-project.org' ip='192.168.136.24'/>" --live --config

Reload dhnsmasq to pick up changes

kill -HUP $(cat /var/run/libvirt/network/default.pid)

New static IP should show up here:

cat /var/lib/libvirt/dnsmasq/default.hostsfile

Then, reboot your VM (or restart its DHCP client, e.g. ipdown eth0; ifup eth0)

Issues:

  • What's the IPs inside /var/lib/libvirt/dnsmasq/virbr0.status ?
  • why does virsh net-dhcp-leases default show different values than virsh net-dumpxml default ?