KVM
KVM (Kernel-based Virtual Machine) is built into the Linux kernel and handles the low-level CPU and memory details. QEMU (Quick EMUlator) emulates the various hardware components of a physical machine, and often utilizes KVM when hardware support is available. Finally, libvirt provides the tools for creating and managing VMs. I use virt-manager and virsh as graphical and console interfaces respectively.
First, check whether the host computer's CPU supports virtualization:
egrep -c '(vmx|svm)' /proc/cpuinfo
A result of 1 or more means the CPU supports virtualization extensions. A result of 0 means it does not, though double-check the BIOS and see if the extensions are available and just need to be enabled.
lscpu | grep Virtualization
I'm using an Intel processor. So I'm getting VT-x as output. If you have an AMD processor, the output should be AMD-V.
Now verify kvm kernel module is installed
ls /dev/kvm
As long as this exists KVM is available and QEMU will utilize KVM for its abstractions. Now install libvert-daemon-system which contains dependencies for QEMU and libvert clients. Also install bridge-utils
sudo apt install libvirt-daemon-system
(Optionally) verify QEMU is installed based on the architecture of hardware you are using (e.g. qemu-system-x86_64, qemu-system-arm, qemu-system-arm64, qemu-system-risc32, qemu-system-risc64).
qemu-system-<arch> --version
Now verify libvert
sudo systemctl status libvirtd
Finally verify the libvert client, virsh, is connected all the way to QEMU
virsh version --daemon
You should see output like the following that verifies it is able to connect to libvertd, and that libvertd connects to the QEMU service. --daemon to include libvert daemon version targets.
Compiled against library: libvirt 11.3.0
Using library: libvirt 11.3.0
Using API: QEMU 11.3.0
Running hypervisor: QEMU 10.0.7
Running against daemon: 11.3.0
Add Your User to Necessary Groups: To manage virtual machines without root privileges, add your user to the libvirt and kvm groups by running the following and logging out and back in:
sudo adduser $USER libvirt
sudo adduser $USER kvm
To avoid having to use the --connect flag on every command, the URI string can be set in the LIBVIRT_DEFAULT_URI environment variable:
export LIBVIRT_DEFAULT_URI='qemu:///system'
QEMU
QEMU is a generic and open source machine emulator and virtualizer.
QEMU can be used for system emulation, where it provides a virtual model of an entire machine (CPU, memory and emulated devices) to run a guest OS. In this mode the CPU may be fully emulated, or it may work with a hypervisor such as KVM, Xen or Hypervisor.Framework to allow the guest to run directly on the host CPU.
According to QEMU and the package reroute in apt qemu-kvm is deprecated and automatically uses qemu-system-x86 instead.
qemu-system - This metapackage provides the full system emulation binaries for all supported targets, by depending on all per-architecture system emulation packages which QEMU supports.
qemu-system-x86 - QEMU is a fast processor emulator: currently the package supports i386 and x86-64 emulation. By using dynamic translation it achieves reasonable speed while being easy to port on new host CPUs.
This package provides the full system emulation binaries to emulate the following x86 hardware: i386 x86_64 (amd64).
In system emulation mode QEMU emulates a full system, including a processor and various peripherals. It enables easier testing and debugging of system code. It can also be used to provide virtual hosting of several virtual machines on a single server.
On x86 host hardware this package also enables KVM kernel virtual machine usage on systems which supports it.
Libvirt
Libvirt is a C toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes). The library aims at providing a long term stable C API for different virtualization mechanisms. It currently supports QEMU, KVM, XEN, OpenVZ, LXC, and VirtualBox.
- libvirt-daemon - The core libvert library. This package contains the daemon libvirtd to manage the hypervisors.
- libvirt-clients - This package contains
virsh, a command line tool that can be used to control the libvirt daemon, as well as a few additional utilities. - libvirt-daemon-system - This package doesn't contain any files on its own, and is intended as a convenient way to create the most common type of libvirt setup (local QEMU hypervisor) in one go, including
libvert-daemon,libvert-clients,libvirt-daemon-driver-qemuwhich subsequently installs theqemu-systemdependency, among others.
Optionally, we can install this user interface:
sudo apt virtinst virt-manager
