In this tutorial, you will learn how to install KVM on Ubuntu 24.04. KVM (Kernel-based Virtual Machine) is an opensource, virtualization tool for Linux systems with Intel-VT or AMD-V based-processors hardware virtualization extensions.
Table of Contents
Installing KVM on Ubuntu 24.04
To be able to run and use KVM on your Ubuntu 24.04, there are few items that the system must meet.
Check Virtualization Support
KVM runs on systems equipped with Intel or AMD processors. You need to verify if this support is already enabled on your system by executing the command below.
grep --color -iE 'vmx|svm' /proc/cpuinfo
The command looks for the CPU flags; Intel vmx (Virtual Machine Extension) or AMD svm (Secure virtual Machine).
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch pti tpr_shadow flexpriority ept vpid fsgsbase bmi1 avx2 bmi2 invpcid rdseed clflushopt vnmi md_clear flush_l1d arch_capabilities
vmx flags : vnmi invvpid ept_x_only flexpriority tsc_offset vtpr vapic ept vpid unrestricted_guest ple
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch pti tpr_shadow flexpriority ept vpid fsgsbase bmi1 avx2 bmi2 invpcid rdseed clflushopt vnmi md_clear flush_l1d arch_capabilities
vmx flags : vnmi invvpid ept_x_only flexpriority tsc_offset vtpr vapic ept vpid unrestricted_guest ple
From the output above, you can see that my system is using Intel processor.
If the command output is empty, find out how to enable virtualization on your respective machine BIOS.
Similarly, you can use the command below to check Virtualization support.
lscpu | grep Virtualization
Sample output;
Virtualization: VT-x
Virtualization type: full
You can also use the cpu-checker, kvm-ok, command to check if the system has virtualization support enabled.
sudo apt install cpu-checker
The above provides the kvm-ok command, which you can use to check the virtualization support by running;
kvm-ok
Such an output confirms that the virtualization support is on.
INFO: /dev/kvm exists
KVM acceleration can be used
Installing KVM on Ubuntu 24.04
If your system meets the above requirements, you can then proceed to install KVM by executing the command below;
sudo apt update
sudo apt install virt-manager qemu-system libvirt-daemon-system qemu-utils
The packages installed above are:
virt-manager
: Virt-Manager is a graphical user interface (GUI) tool for managing virtual machines through libvirt-daemon.qemu-system
is an open source virtualizer that provides hardware emulation for the KVM hypervisor. It acts as a virtual machine monitor together with the KVM kernel modules, and emulates the hardware for a full system such as a PC and its associated peripherals.libvirt-daemon-system
provides API libraries that enables GUI apps such as virt-manager to communicate with libvirtd daemon, a system servicelibvirtd
, and avirsh
CLI tool.
If you are running an headless server with no GUI, then it suffices to just run the command below;
sudo apt install qemu-system libvirt-daemon-system virtinst qemu-utils
Once the installation is done, check if KVM modules are loaded;
lsmod | grep -i kvm
kvm_intel 487424 0
kvm 1437696 1 kvm_intel
irqbypass 12288 1 kvm
Start libvirt Daemon (libvirtd)
According to man pages, the libvirtd program is the server side daemon component of the libvirt virtualization management system. This daemon runs on host servers and performs required management tasks for virtualized guests. This includes activities such as starting, stopping and migrating guests between host servers, configuring and manipulating networking, and managing storage for use by guests. The libvirt client libraries and utilities connect to this daemon to issue tasks and collect information about the configuration and resources of the host system and guests.
Thus, start and enable this service to run on system boot;
sudo systemctl enable --now libvirtd
Check the status;
systemctl status libvirtd
By default, the libvirtd daemon listens for requests on a local Unix domain socket. Using the -l | --listen
command line option, the libvirtd daemon can be instructed to additionally listen on a TCP/IP socket. The TCP/IP socket to use is defined in the libvirtd configuration file.
Add User to Libvirt Group
If you are launching virt-manager as standard user, you may be prompted to enter your administrator password to run it, “system policy prevents management of local virtualized systems”.
To fix this, add the standard user to libvirt
and kvm
group (Replace USERNAME with your user account).
sudo usermod -aG libvirt,kvm USERNAME
Next, log the user out completely, if they were logged in when you executed the command above.
Launch KVM Virtual Machine Manager
If you are running a desktop system, then you can launch the Virtual Machine manager from your applications or command line;
To launch it from command line;
virt-manager
You can now start creating virtual machines and run them over KVM!
If QEMU/KVM is not connected, log out the user from the SSH session as well as from the desktop and re-login and relaunch the virtual manager.