How to Set Up KVM Virtualization
Set up KVM/QEMU virtualization on Linux with libvirt and virt-manager. Covers hardware checks, installation on Ubuntu, Fedora, and Arch, networking, and creating VMs.
Before you start
- ▸A CPU with Intel VT-x or AMD-V virtualization extensions enabled in firmware
- ▸A 64-bit Linux install with kernel 5.15 or newer
- ▸sudo or root access on the host machine
- ▸At least 8 GB RAM and 30 GB free disk space for a usable guest
KVM (Kernel-based Virtual Machine) turns Linux into a Type-1 hypervisor by loading two kernel modules—kvm and either kvm_intel or kvm_amd—that expose hardware virtualization extensions directly to guest VMs. Paired with QEMU for device emulation and libvirt as a management layer, the stack is production-grade and runs everything from desktop test VMs to large-scale cloud infrastructure. This guide walks through the full setup: checking CPU support, installing the software stack, configuring networking, and launching your first VM with virt-manager.
1. Verify Hardware Virtualization Support
KVM requires Intel VT-x or AMD-V extensions enabled in firmware. Check before installing anything.
grep -Eoc '(vmx|svm)' /proc/cpuinfo
A number greater than 0 means extensions are present. vmx is Intel, svm is AMD. If the output is 0, enter your UEFI/BIOS settings and enable the relevant virtualization option (often called Intel Virtualization Technology or AMD-V/SVM).
You can also run the dedicated check tool:
sudo apt install cpu-checker # Debian/Ubuntu only
sudo kvm-ok
Expected output: INFO: /dev/kvm exists — KVM acceleration can be used. On Fedora/Arch this tool is not packaged; the /proc/cpuinfo check is sufficient.
2. Install KVM, QEMU, and libvirt
Debian / Ubuntu
sudo apt update
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients \
bridge-utils virt-manager virtinst
Fedora / RHEL 9 / Rocky Linux 9
sudo dnf install -y @virtualization
The @virtualization group pulls in qemu-kvm, libvirt, virt-install, virt-manager, and supporting tools in one shot.
Arch Linux
sudo pacman -S qemu-full libvirt virt-manager virt-viewer \
dnsmasq bridge-utils openbsd-netcat
On Arch, qemu-full includes all architecture targets. Use qemu-base if you only need x86_64 guests and want a smaller install.
3. Enable and Start libvirtd
libvirt exposes a management daemon that virt-manager and virsh connect to. Enable it at boot and start it now.
sudo systemctl enable --now libvirtd
Verify it is running:
sudo systemctl status libvirtd
The output should show active (running). On Fedora 38+ the socket-activated units (libvirtd.socket) are used by default—this is fine; libvirtd starts on demand.
4. Add Your User to the libvirt Group
Without group membership every libvirt command requires sudo. Adding your user to libvirt (and kvm on some distros) grants unprivileged access to the daemon and the /dev/kvm device.
sudo usermod -aG libvirt,kvm $(whoami)
Log out and back in, or use newgrp libvirt in the current shell, for the group change to take effect. Confirm with:
groups
5. Configure Networking
libvirt ships with a default NAT network (virbr0) that works out of the box for outbound internet access from guests. For guests that need to be addressable on your LAN—servers, for example—set up a bridge instead.
Option A: Use the Default NAT Network (Simplest)
Confirm the default network is active:
sudo virsh net-list --all
If default shows inactive, start and auto-start it:
sudo virsh net-start default
sudo virsh net-autostart default
Option B: Create a Bridged Network
A bridge gives guests a real IP on your physical network. The steps below use NetworkManager, which is present on Fedora, recent Ubuntu, and most desktop distros.
# Replace enp3s0 with your actual physical NIC (ip link to find it)
sudo nmcli connection add type bridge ifname br0 con-name br0
sudo nmcli connection add type ethernet ifname enp3s0 \
master br0 con-name br0-slave
sudo nmcli connection modify br0 bridge.stp no
sudo nmcli connection up br0
After this, create a libvirt network definition that uses br0, or select the bridge directly in virt-manager when creating a VM.
6. Create a VM with virt-manager
virt-manager is a GTK application that wraps libvirt. It runs under both X11 and XWayland without any extra configuration.
- Launch virt-manager from your application menu or run
virt-managerin a terminal. - Click File → New Virtual Machine.
- Choose Local install media (ISO image or CDROM) and browse to your ISO.
- Set RAM and CPU. A minimum of 2048 MB RAM and 2 vCPUs is reasonable for most Linux guests.
- Create a disk image—20 GB is a safe starting point. The default location is
/var/lib/libvirt/images/. - On the final screen, tick Customize configuration before install if you want to change firmware (UEFI vs BIOS), add extra disks, or change the NIC model.
- Click Begin Installation. A console window opens and the guest boots from the ISO.
7. Create a VM from the Command Line with virt-install
For scripting or headless servers, virt-install is the right tool.
sudo virt-install \
--name ubuntu2404 \
--ram 2048 \
--vcpus 2 \
--disk path=/var/lib/libvirt/images/ubuntu2404.qcow2,size=20,format=qcow2 \
--cdrom /tmp/ubuntu-24.04-server-amd64.iso \
--os-variant ubuntu24.04 \
--network network=default \
--graphics vnc,listen=127.0.0.1 \
--noautoconsole
Use osinfo-query os | grep ubuntu to find the correct --os-variant string for your guest. Once the VM is created, connect to its console with:
sudo virsh console ubuntu2404
8. Verify the Setup
List all defined VMs and their states:
sudo virsh list --all
Check that KVM acceleration is actually in use (not software emulation):
sudo virsh domcapabilities | grep -i "kvm"
Inside a running guest, confirm the kernel sees a KVM clock source:
cat /sys/devices/system/clocksource/clocksource0/current_clocksource
# Expected: kvm-clock
Troubleshooting
Permission denied on /dev/kvm
Your user is not yet in the kvm group, or the group change has not been applied in the current session. Run newgrp kvm or log out completely and back in.
libvirtd fails to start
Check the journal for details:
sudo journalctl -u libvirtd -n 50 --no-pager
A common cause on Fedora is SELinux denials. Check with sudo ausearch -m avc -ts recent and, if needed, run sudo restorecon -Rv /var/lib/libvirt.
VM is slow or CPU usage is very high
Confirm the guest is using KVM acceleration, not TCG (software emulation). In virt-manager, open the VM details and check that the CPU type is not set to a software-only model. On the host, ls /dev/kvm should exist; if it does not, the KVM kernel modules are not loaded. Load them manually with sudo modprobe kvm_intel or sudo modprobe kvm_amd.
No network inside the guest
Verify IP forwarding is enabled on the host:
cat /proc/sys/net/ipv4/ip_forward
# Should be 1
If it is 0, enable it:
sudo sysctl -w net.ipv4.ip_forward=1
# To persist across reboots:
echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-kvm-forward.confFrequently asked questions
- Can I run KVM inside a virtual machine (nested virtualization)?
- Yes, but you must explicitly enable nested virtualization on the host. For Intel, run: echo 'options kvm_intel nested=1' | sudo tee /etc/modprobe.d/kvm-nested.conf and reload the module. The guest VM must also be configured to expose the vmx/svm CPU flag.
- What is the difference between QEMU, KVM, and libvirt?
- KVM is a kernel module that enables hardware-accelerated virtualization. QEMU is the user-space emulator that creates and runs VM processes. libvirt is a management API and daemon that sits on top of both, providing a consistent interface for tools like virt-manager and virsh.
- Should I use qcow2 or raw disk images?
- qcow2 is the default and most flexible format: it supports thin provisioning, snapshots, and compression. Raw images have slightly lower overhead and are better for maximum I/O throughput in production. For desktop and test VMs, qcow2 is the right choice.
- How do I take a snapshot of a running VM?
- Use virsh snapshot-create-as: sudo virsh snapshot-create-as --domain myvmname --name snap1 --description 'before update'. List snapshots with sudo virsh snapshot-list myvmname and revert with sudo virsh snapshot-revert myvmname snap1.
- Does virt-manager work on Wayland?
- Yes. virt-manager is a GTK3 application that runs under XWayland on any Wayland compositor without extra configuration. The display manager for VM consoles (SPICE or VNC) is handled by virt-viewer, which also works correctly under XWayland.
Related guides
AI and Artificial-Life Tools on Linux
Set up open-source AI/ML and artificial-life toolkits on Linux: PyTorch, JAX, DEAP, Avida, NetLogo, and RL environments with GPU driver guidance.
Assembly Language on Linux: A Starter Guide
Write x86-64 assembly on Linux from scratch: install NASM and GAS, learn syscalls, assemble and link a working program, then inspect and debug it.
How to Benchmark Disk Performance with fio
Learn to benchmark Linux disk performance with fio: writing job files, testing latency and throughput, and interpreting IOPS and percentile output correctly.
The Linux Boot Process Explained
Trace the full Linux boot sequence from UEFI firmware through GRUB2, the kernel, initramfs, and systemd to your login prompt — with diagnostics at each stage.