KVM/QEMU Setup
This guide covers setting up KVM/QEMU virtualization on Arch Linux.
Prerequisites
Section titled “Prerequisites”Enable VT-x and VT-d in your BIOS/UEFI settings first.
Step 1: Enable IOMMU
Section titled “Step 1: Enable IOMMU”Add kernel parameters to GRUB. Edit /etc/default/grub:
# For IntelGRUB_CMDLINE_LINUX_DEFAULT="... intel_iommu=on iommu=pt"
# For AMDGRUB_CMDLINE_LINUX_DEFAULT="... amd_iommu=on iommu=pt"Regenerate GRUB config:
sudo grub-mkconfig -o /boot/grub/grub.cfgReboot and verify:
dmesg | grep -i iommuStep 2: Install Packages
Section titled “Step 2: Install Packages”sudo pacman -S --needed qemu-full libvirt virt-install virt-manager \ virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat edk2-ovmf \ tuned qemu-img guestfs-tools iptables-nft libosinfoFor Windows VMs (VirtIO drivers):
paru -S virtio-winPackage Overview
Section titled “Package Overview”| Package | Purpose |
|---|---|
qemu-full | QEMU hypervisor for VM emulation |
libvirt | API and daemon for managing VMs |
virt-manager | GUI for VM management |
virt-viewer | Display tool for VMs (SPICE/VNC) |
dnsmasq | DHCP/DNS for NAT networks |
bridge-utils | Network bridge management |
edk2-ovmf | UEFI firmware for VMs |
swtpm | TPM 2.0 emulator (Windows 11) |
virtio-win | VirtIO drivers for Windows guests |
Step 3: Load Kernel Modules
Section titled “Step 3: Load Kernel Modules”Verify KVM modules:
lsmod | grep kvmYou should see kvm and kvm_intel or kvm_amd.
Step 4: Enable Services
Section titled “Step 4: Enable Services”Option A: Modular Daemons (Recommended)
Section titled “Option A: Modular Daemons (Recommended)”for drv in qemu interface network nodedev nwfilter secret storage; do sudo systemctl enable virt${drv}d.socket sudo systemctl enable virt${drv}d-ro.socket sudo systemctl enable virt${drv}d-admin.socketdoneOption B: Monolithic Daemon
Section titled “Option B: Monolithic Daemon”sudo systemctl enable --now libvirtd.serviceDo not enable both modular and monolithic daemons.
Step 5: Configure User Permissions
Section titled “Step 5: Configure User Permissions”Add your user to required groups:
sudo usermod -aG libvirt,kvm,input,disk $USERLog out and back in for changes to take effect.
Step 6: Set ACL on Image Directory
Section titled “Step 6: Set ACL on Image Directory”sudo setfacl -R -m u:$USER:rwX /var/lib/libvirt/imagessudo setfacl -R -m d:u:$USER:rwX /var/lib/libvirt/imagesStep 7: Enable Default Network
Section titled “Step 7: Enable Default Network”sudo virsh net-autostart defaultsudo virsh net-start defaultVerify Installation
Section titled “Verify Installation”virt-host-validateLook for PASS on QEMU and KVM checks.
Optional: TuneD Optimization
Section titled “Optional: TuneD Optimization”Install and enable TuneD for better VM performance:
sudo pacman -S tunedsudo systemctl enable --now tuned.servicesudo tuned-adm profile virtual-host