Andrew Mercer
on this page

KVM host setup

Part of the KVM overview. Install KVM and libvirt, verify hardware support, and set up permissions and SELinux.

Check hardware support

grep -Ec '(vmx|svm)' /proc/cpuinfo     # > 0 means virtualization extensions are present
ls -l /dev/kvm
virt-host-validate qemu                # full check (libvirt-client)

If KVM is unavailable, enable "Virtualization Technology" (VT-x / AMD-V) in the BIOS/firmware and reboot.

Ubuntu / Debian

sudo apt-get -y install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker virtinst libguestfs-tools
sudo systemctl enable --now libvirtd
kvm-ok

RHEL / Rocky / Alma / Fedora

sudo dnf install @virtualization        # Fedora; on RHEL-family: sudo dnf group install "Virtualization Host"
sudo dnf install virt-install virt-manager virt-top libguestfs-tools
sudo systemctl enable --now libvirtd

Reference: https://phoenixnap.com/kb/install-kvm-centos

Permissions

sudo usermod --append --groups libvirt "$(whoami)"    # log out and back in afterwards

Without this, remote and GUI tools fail with authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'.

URI Scope
qemu:///system System-wide VMs (images in /var/lib/libvirt/images)
qemu:///session Per-user VMs (images under ~/.local/share/libvirt/images)

virsh -c qemu:///session list selects one explicitly; the two see different sets of VMs.

SELinux and non-default image directories

If you keep images outside /var/lib/libvirt/images, label the directory:

sudo semanage fcontext -a -t virt_image_t "/data/images(/.*)?"
sudo restorecon -Rv /data/images

An ISO in your home directory that QEMU cannot open (Could not open '...iso': Permission denied) needs an ACL for the qemu user:

sudo setfacl -m u:qemu:rx "$HOME"