KVM Installation
KVM (Kernel-based Virtual Machine) is the Linux kernel's built-in hypervisor. It turns Linux into a Type-1 hypervisor, allowing you to run multiple isolated virtual machines on a single physical host. Combined with QEMU (which provides hardware emulation) and libvirt (a management API), KVM gives you full virtualization comparable to VMware ESXi or Hyper-V at zero licensing cost. Ubuntu uses this stack for its own cloud infrastructure.
What is KVM?
KVM virtualization stack:
Physical Hardware (CPU with VT-x/AMD-V extensions)
|
Linux Kernel + KVM module (hardware virtualization support)
|
QEMU (hardware emulation: virtual disks, NICs, etc.)
|
libvirt (management API and daemon)
|
virsh (CLI) / virt-manager (GUI) / Cockpit (web UI)Hardware requirements
# Verify CPU supports hardware virtualization:
grep -c -E "vmx|svm" /proc/cpuinfo # > 0 means virtualization supported
# vmx = Intel VT-x
# svm = AMD-V
# Check if KVM module is loaded:
lsmod | grep kvm
Expected output on capable hardware
kvm_intel 331776 0 ← Intel VT-x (OR kvm_amd for AMD)
kvm 987136 1 kvm_intel
Installing KVM
sudo apt update
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager
# Add your user to the libvirt group (to manage VMs without sudo):
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER
newgrp libvirt # Apply group change in current session
# Enable and start libvirtd:
sudo systemctl enable --now libvirtd
# Verify installation:
virsh list --all # Should show empty list (no VMs yet)
Creating your first VM
# Create a VM using virt-install:
sudo virt-install --name ubuntu-test --ram 2048 --vcpus 2 --disk path=/var/lib/libvirt/images/ubuntu-test.qcow2,size=20 --os-variant ubuntu22.04 --network network=default --graphics none --console pty,target_type=serial --location 'http://archive.ubuntu.com/ubuntu/dists/jammy/main/installer-amd64/' --extra-args 'console=ttyS0,115200n8 serial'
# Or with an ISO file:
sudo virt-install --name ubuntu-test --ram 2048 --vcpus 2 --disk path=/var/lib/libvirt/images/ubuntu-test.qcow2,size=20 --cdrom /home/irfan/ubuntu-22.04-server.iso --network network=default
Conclusion
After installing the KVM stack, run virsh list --all to verify libvirtd is working correctly. The default NAT network (network=default) provides outbound internet access for VMs without additional configuration. For VMs that need to be reachable from the local network, you need a bridged network (covered in the libvirt-basics article). KVM VMs live in /var/lib/libvirt/images/ as QCOW2 disk images.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Work with Muhammad Irfan Aslam