Overview
KVM (Kernel-based Virtual Machine) is the native Linux virtualization solution. Combined with QEMU and virt-manager, it offers near-native performance for running Linux guests on a Linux host.
What You Need
- A running Linux system (Ubuntu/Fedora/Debian recommended)
- CPU with virtualization support (Intel VT-x or AMD-V) — check with:
egrep -c '(vmx|svm)' /proc/cpuinfo - Virtualization enabled in BIOS/UEFI
Install KVM and Tools
Ubuntu/Debian
sudo apt update
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager
sudo usermod -aG libvirt,$USER
sudo usermod -aG kvm,$USER
# Log out and back in for group changes
Fedora/RHEL
sudo dnf install @virtualization
sudo systemctl enable --now libvirtd
sudo usermod -aG libvirt,$USER
Arch Linux
sudo pacman -S qemu-full virt-manager libvirt dnsmasq vde2 bridge-utils ebtables openbsd-netcat
sudo systemctl enable --now libvirtd
sudo usermod -aG libvirt,$USER
Verify Installation
# Check KVM modules are loaded
lsmod | grep kvm
# Should show kvm_intel or kvm_amd
Create a VM Using virt-manager (GUI)
- Launch Virtual Machine Manager from your applications menu
- Click the computer icon with "+" to create a new VM
- Select "Local install media" → Forward
- Browse to your Linux ISO file → Forward
- Choose OS type and version (or let it auto-detect) → Forward
- Allocate RAM and CPU cores → Forward
- Create or select virtual disk storage → Finish
The installer will launch — follow the prompts for your chosen distribution.
Create a VM Using Command Line (virt-install)
virt-install \
--name ubuntu-server \
--ram 4096 \
--vcpus 2 \
--disk size=25,format=qcow2 \
--cdrom /path/to/ubuntu.iso \
--os-type linux \
--os-variant ubuntu24.04 \
--network network=default \
--graphics spice \
--noautoconsole
Use virt-viewer ubuntu-server to connect to the VM console after creation.
Networking Options
NAT (Default)
The VM shares the host's IP. The host can access the VM, and the VM can reach the internet.
# Find VM's internal IP from the host
virsh net-dhcp-leases default
Bridged Networking
The VM gets its own IP on your physical network.
# Create a bridge (example for Ubuntu with Netplan)
sudo nano /etc/netplan/01-netcfg.yaml
# Add bridge configuration, then:
sudo netplan apply
Host-Only Network
VM can only communicate with the host — useful for isolated testing.
Storage Management
Disk Formats
- qcow2: Recommended — supports snapshots, compression, thin provisioning
- raw: Slightly faster but uses full disk space immediately
Snapshots
# Create a snapshot
virsh snapshot-create-as ubuntu-server pre-install
# List snapshots
virsh snapshot-list ubuntu-server
# Revert to a snapshot
virsh snapshot-revert ubuntu-server pre-install
Add Extra Disk
# Create new disk image
qemu-img create -f qcow2 /var/lib/libvirt/images/extra-disk.qcow2 10G
# Attach to running VM
virsh attach-disk ubuntu-server /var/lib/libvirt/images/extra-disk.qcow2 vdb --subdriver qcow2
Advanced Configuration
Passthrough USB Device
# List USB devices
virsh nodedev-list --tree
# Attach USB to VM
virsh attach-device ubuntu-server usb.xml --config --live
Enable VRAM for Graphics
Edit VM XML: virsh edit ubuntu-server, find the graphics section, and add:
<video>
<model type='virtio' vram='16384' heads='1' primary='yes'/>
</video>
Clone a VM
virt-clone --original ubuntu-server --name ubuntu-test --auto-clone
Troubleshooting
- "No KVM acceleration": Enable virtualization in BIOS and verify with
lsmod | grep kvm - "Permission denied": Ensure your user is in the libvirt and kvm groups
- VM won't start: Check logs:
virsh dominfo ubuntu-serveranddmesg | tail