Yes, you can install KVM (Kernel-based Virtual Machine) on Ubuntu using the qemu-kvm and libvirt packages, then manage virtual machines with Virtual Machine Manager. This guide walks through the exact commands, hardware checks, and common pitfalls so you can run Windows, Linux, or BSD guests on your Ubuntu host.
What KVM Actually Is
KVM is a virtualization module built into the Linux kernel. It turns your physical CPU into a hypervisor, letting you run multiple operating systems as guests with near-native performance. Unlike VirtualBox or VMware Workstation, KVM does not do software emulation for CPU instructions—it uses hardware virtualization extensions (Intel VT-x or AMD-V) directly, so a guest OS runs almost as fast as the host.
On Ubuntu, KVM is usually paired with two more pieces: QEMU, which emulates devices like the disk controller and network card, and libvirt, a management API that tools like Virtual Machine Manager and virsh use to create and control VMs. When people say “install KVM on Ubuntu,” they almost always mean this full stack.
Prerequisites and Hardware Check
Before installing anything, confirm your CPU supports virtualization. Run this command:
grep -E --color '(vmx|svm)' /proc/cpuinfo
If you see vmx (Intel) or svm (AMD), you are good. If nothing appears, virtualization is either disabled in BIOS/UEFI or your CPU does not support it. Enter your firmware settings at boot (usually Del, F2, or F12) and look for “Intel Virtualization Technology” or “SVM Mode” and enable it.
You also need enough RAM and disk. A single lightweight Linux guest can run in 1 GB of RAM, but Windows 11 wants at least 4 GB. Plan for the host to keep about 2 GB free for itself. Disk-wise, each VM stores its own virtual disk image, so check your free space with df -h before starting.
Installing KVM Packages
On modern Ubuntu releases (20.04 and later), the packages you need are in the main repository. Open a terminal and run:
sudo apt update sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager
Here is what each package does:
- qemu-kvm – the actual hypervisor that runs the VMs.
- libvirt-daemon-system – the libvirt daemon and its systemd service.
- libvirt-clients – command-line tools like
virsh. - bridge-utils – tools for creating a network bridge so VMs share your internet connection.
- virt-manager – a graphical interface for creating and managing VMs.
After installation, add your user to the libvirt and kvm groups so you can manage VMs without sudo:
sudo usermod -aG libvirt $USER sudo usermod -aG kvm $USER
Log out and back in for the group changes to take effect. Then check that the libvirt daemon is running:
sudo systemctl status libvirtd
If it shows “active (running),” you are ready. On older Ubuntu versions, the service name might be libvirt-bin instead of libvirtd.
Verifying KVM Works
Before creating a VM, confirm the kernel module loaded correctly:
lsmod | grep kvm
You should see kvm_intel or kvm_amd in the output. If not, the module may not have loaded—try sudo modprobe kvm_intel (or kvm_amd) and then check again.
Also run virsh list --all. It should return an empty list without errors. If it says “cannot connect to hypervisor,” the daemon is not running or your user is not in the right group yet.
Creating Your First Virtual Machine
The easiest way is through Virtual Machine Manager. Launch it from the applications menu or by typing virt-manager in a terminal. Then:
- Click the monitor icon (Create a new virtual machine).
- Choose your installation method: local ISO, network install, or existing disk image.
- Browse to your ISO file. If it is not in your home directory, you may need to copy it there or add your folder to the storage pool in the connection details.
- Set RAM and CPU count. A good starting point is 2 GB RAM and 2 vCPUs for a desktop OS.
- Create a disk image. The default 20 GB with “raw” or “qcow2” format works fine. qcow2 grows as you use it, so it does not take all 20 GB upfront.
- Finish the wizard and the VM will boot from the ISO.
If you prefer the command line, you can create a VM with virt-install. A minimal example:
sudo virt-install --name ubuntu-vm --ram 2048 --vcpus 2 --disk size=20 --cdrom /path/to/ubuntu.iso --os-variant ubuntu24.04
Replace the ISO path and OS variant with what you actually have. Use osinfo-query os to list valid --os-variant values.
Networking: Bridged vs NAT
By default, KVM uses a virtual NAT network (usually called default). Your guest can reach the internet and the host, but other machines on your LAN cannot reach the guest directly. That is fine for most personal use.
If you need the guest to appear as a normal device on your network (for file sharing, SSH from other computers, or running a game server), set up a bridge. The modern way on Ubuntu is with netplan. Create a bridge by editing /etc/netplan/01-netcfg.yaml (the filename varies) and adding a bridges: section that references your physical interface. Then run sudo netplan apply. After that, in virt-manager, choose “Bridge br0” as the network when creating the VM.
Alternatively, use virsh net-define with an XML file to create a custom NAT network with specific IP ranges, but the default NAT is enough for most people.
Common Problems and Fixes
Several issues crop up regularly when installing or running KVM on Ubuntu:
- “KVM is not available” error – Usually means hardware virtualization is off in BIOS, or your CPU is very old. Reboot, enable VT-x/AMD-V, and retry.
- Permission denied connecting to libvirt – You are not in the
libvirtgroup, or you have not logged out after being added. Runidto check your groups. - Guest is extremely slow – You may be running without KVM acceleration (check with
virsh capabilitiesand look for “domain type=’kvm’”). Also confirm the guest has enough RAM and that you enabled the virtio drivers for disk and network during installation. - No internet in guest – The default NAT network may be stopped. Run
sudo virsh net-start defaultandsudo virsh net-autostart defaultto fix it. - Cannot boot from ISO – The ISO may be in a directory the libvirt user cannot read. Move it to
/var/lib/libvirt/images/or change permissions.
KVM vs VirtualBox vs Docker
People often wonder why they should bother with KVM when VirtualBox is easier to install. The main differences are performance and integration. KVM runs guests with near-native speed because it uses hardware virtualization directly; VirtualBox also uses VT-x/AMD-V but has more overhead in its device emulation layer. KVM also scales better for servers—you can run dozens of VMs on one machine with less CPU waste.
Docker is not a replacement for KVM. Docker containers share the host kernel, so they cannot run Windows or a different Linux distribution with a different kernel. Use Docker for isolated apps; use KVM for full operating systems.
Frequently Asked Questions
Do I need a separate partition or special kernel to use KVM? No. KVM is built into the standard Ubuntu kernel. You just install the user-space tools and enable virtualization in BIOS.
Can I run Windows 11 on KVM? Yes, but Windows 11 requires TPM 2.0 and Secure Boot. Recent libvirt versions support a virtual TPM device. In virt-manager, add a TPM device (version 2.0) to the VM hardware and enable UEFI firmware instead of BIOS.
How much RAM should I give a guest? Start with 2 GB for a lightweight Linux desktop, 4 GB for Windows 10/11, and 8 GB or more for heavy workloads like compiling software or running databases. Leave at least 1–2 GB for the host.
Is KVM safe to use on a laptop? Yes, but watch battery life and heat. Running a VM uses more CPU and fans will spin up. Also, some laptops have power-saving features that can cause timing issues in guests; disabling C-states in BIOS helps if you see clock drift.
Can I migrate a VirtualBox VM to KVM? Usually yes. Export the VirtualBox disk as a raw or qcow2 image using VBoxManage clonehd, then create a new KVM VM and attach that image as the disk. You may need to reinstall the guest’s virtio drivers for best performance.
Do I need a dedicated GPU for GPU passthrough? For serious GPU passthrough (giving a guest direct access to a graphics card), you need a second GPU for the host or an iGPU in the CPU. This is an advanced setup and requires careful configuration of IOMMU groups; it is not necessary for normal VM use.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Set a Google Play Budget & Stop Accidental Purchases
- Destiny 2 Error Code Anteater: Fixes & Causes
- View Android Photos on Chromebook: Step-by-Step
- Fix Windows Could Not Prepare the Computer to Boot
- Windows 11 Security Settings: Best Config Guide
- Install Custom Recovery on Samsung Galaxy Trend