KVM
Table of Contents
Bridge Configuration
Set up a bridge on interface for VMs
sudo apt install bridge-utils
Disable netfilter for bridges
Listing 1: /etc/sysctl.d/bridge.conf
net.bridge.bridge-nf-call-ip6tables=0 net.bridge.bridge-nf-call-iptables=0 net.bridge.bridge-nf-call-arptables=0
Listing 2: /etc/udev/rules.d/99-bridge.rules
ACTION=="add", SUBSYSTEM=="module", KERNEL=="br_netfilter", RUN+="/sbin/sysctl -p /etc/sysctl.d/bridge.conf"
Note that gateway shouldn't be set more than once in the interfaces file or it will cause errors for the systemd networking unit.
Listing 3: /etc/network/interfaces
# Bridge interface for VMs iface enp9s0 inet manual auto br0 iface br0 inet static hwaddress ether fa:ke:ma:ca:dd:rs address 0.0.0.0 bridge_ports enp9s0 bridge_stp off bridge_fd 0
Reset virtual network
virsh --connect qemu:///system net-destroy default virsh --connect qemu:///system net-start default
VM Install
apt install qemu-kvm libvirt-clients qemu-utils libvirt-daemon-system
Initial vm setup
virt-install --virt-type kvm --name pixy --memory 4096 --cdrom downloads/debian-9.9.0-amd64-netinst.iso --disk size=30 --os-variant debian9 --network bridge=br0 virsh --connect qemu:///system autostart <vmname>
Do some network setup after install just like a normal debian host.
Allocate extra vcpus if needed.
A few commands for general work on the VM:
virsh --connect qemu:///system list --all virsh --connect qemu:///system edit <vmname> virsh --connect qemu:///system shutdown <vmname> virsh --connect qemu:///system undefine <vmname> virsh --connect qemu:///system destroy <vmname>
Give the guest read only access to a host directory (use virsh edit)
Listing 4: /etc/libvirt/qemu/<vmname>.xml (excerpt)
<domain type='kvm'> <devices> <filesystem type='mount' accessmode='passthrough'> <source dir='/path/to/video'/> <target dir='/mnt/video'/> <readonly/> <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/> </filesystem> </devices> </domain>
Listing 5: /etc/fstab
video /mnt/video 9p trans=virtio 0 0