Bringing up KVM on Arch

It’s reasonably simple to bring up a new KVM system on Arch, assuming your hardware supports VT-x or AMD-V (and almost everything does).

First, check that you have the capabilities needed. The first command checks that the CPU supports virtualisation, and thr second whether your kernel has the appropriate modules available:

$ lscpu | grep "Virtualization"
$ zgrep CONFIG_KVM /proc/config.gz

Assuming there are no surprises, now install libvirt and a few helpers. We use qemu as it provides a lot of useful utilities for dealing with disk images (among others), and virt-install is a useful helper script for quickly setting up new virtual machines.

$ sudo pacman -S libvirt dnsmasq qemu virt-install

Start the service:

$ sudo systemctl enable libvirtd.service

Now we use the virsh client to connect to the KVM daemon:

$ virsh -c qemu:///session

Now, we need to create a storage pool, as a precursor to creating a storage volume:

virsh # pool-list --all
 Name   State   Autostart
virsh # $ pool-define-as main dir - - - - /home/jonathan/.local/libvirt/images
Pool main defined

virsh # pool-build main
Pool main built

virsh # pool-start main
Pool main started

virsh # pool-autostart main
Pool main marked as autostarted

virsh # pool-list --all
 Name   State    Autostart
 main   active   yes

Now, create a storage volume (in this example, I’m calling the volume ‘storvol’, but I’d adapt this to your VM’s role, so ‘mail’ or ‘www’ or similar):

virsh # vol-create-as main storvol 20GiB --format qcow2
Vol mail created

Finally, we can create a new VM (or ‘domain’ in libvirt parlance). First, exit virsh with ^D. Then:

$ virt-install --name yourvmname --memory 2048 --vcpus=2 --cpu host --cdrom=/home/user/downloads/archlinux-2019.08.01-x86_64.iso --disk size=10,format=qcow2 --network user --virt-type kvm --console pty,target_type=serial