logo

KVM + QEMU + libvirt

The stack:

  • KVM: Linux kernel module that allows a user space program access to the hardware virtualization features of various processors; allows the kernel to function as a hypervisor. KVM itself emulates very little hardware, instead deferring to a higher level client application such as QEMU.
  • QEMU: provides a set of different hardware and device models for the machine, supports the emulation of various architectures; can boot many guest operating systems. QEMU = Quick Emulator.
  • libvirt: the lib to manage KVM, Xen, VMware ESXi, QEMU.
  • virt-manager: using libvirt; included in many linux distros.
  • kubevirt: brining VMs to k8s. Using libvirt + QEMU + KVM.

From Commandline

List VMs

Each VM started with qemu-system-x86_64 corresponds to a process on the host machine. This means that a list of qemu-system-x86_64 processes corresponds to the list of VMs that are currently running on the host.

$ ps -ef | grep qemu-system-x86_64

This will list all the qemu-system-x86_64 processes, their pids and the parameters used to start the VM.

$ ps -ef | grep qemu-kvm

Create VMs

Emulates Intel x86 64-bit architecture.

$ qemu-system-x86_64

How to check if kvm is enabled?

Use kvm-ok to check if kvm is enabled?

$ kvm-ok

If kvm-ok is not available, you can get it by installing cpu-checker:

$ sudo apt install cpu-checker

If without kvm-ok:

$ ls /dev/kvm
$ lsmod | grep kvm

Check if CPU virtualization is enabled:

# Intel
# vmx=Virtual Machine Extensions
$ cat /proc/cpuinfo | grep vmx

# AMD
# svm=Secure Virtual Machine
$ cat /proc/cpuinfo | grep svm

How to enable KVM?

If you KVM is not running, make sure the virtualization features are enabled in BIOS:

  • SVM (Secure Virtual Machine) by AMD
  • Virtualization Technology by Intel
  • IOMMU: Input–output memory management unit

How to install QEMU?

On Debian / Ubuntu:

# Install qemu related packages
$ sudo apt install qemu-utils qemu-system-x86 qemu-system-gui