QEMU and KVM in Arch Linux

Q

KVM (Kernel-based Virtual Machine) is the native Virtualization System from RedHat; is a hypervisor built directly into the Linux kernel. The same system is also found in RedHat-derived distributions: CentOS, Scientific Linux, Oracle Linux or Fedora. KVM offers the ability to create and manage a lot of virtual machines on a single web host: the web host server that has one of the above mentioned distributions installed. Probably KVM is the most common form of virtualization for web hosting companies.

QEMU is a virtual machine emulator that uses the KVM hypervisor and uses process extensions (HVM) to run virtual machines, achieving performances that can be compared with the ones of the real system, and that’s because a big part of the code runs directly on the web host machine’s processor.

This short guide is for those who have installed the Arch Linux distribution and want to use KVM instead of Virtualbox.

Checking the KVM support

KVM requires the web host system’s processor to support virtualization (VT-x for Intel processors and AMD-V for AMD processors). To verify that our process supports virtualization, run the command:

lscpu | grep Virtualization

or

egrep –color=auto ‘vmx|svm|0xc0f’ /proc/cpuinfo

The answer to the two commands should look like below:

Virtualization: VT-x

or

flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflus h dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_g ood nopl cpuid aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm xsave lahf_lm tpr_shadow vnmi flexpriority dtherm

flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflus h dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_g ood nopl cpuid aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm xsave lahf_lm tpr_shadow vnmi flexpriority dtherm

If nothing is displayed, it means that your processor is not capable of running KVM (or you do not have the vitualization support enabled in BIOS).

You can check if the required modules are available in the kernel with the following command:

zgrep CONFIG_KVM /proc/config.gz

The answer should be (modules are available if they are marked with y or m):

CONFIG_KVM_GUEST=y
# CONFIG_KVM_DEBUG_FS is not set
CONFIG_KVM_MMIO=y
CONFIG_KVM_ASYNC_PF=y
CONFIG_KVM_VFIO=y
CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT=y
CONFIG_KVM_COMPAT=y
CONFIG_KVM=m
CONFIG_KVM_INTEL=m
CONFIG_KVM_AMD=m
CONFIG_KVM_MMU_AUDIT=y

Verify that the modules are automatically loaded from the kernel:

$ lsmod | grep kvm
kvm_intel 221184 0
kvm 626688 1 kvm_intel
irqbypass 16384 1 kvm

Otherwise, they must be loaded manually using the modprobe command:

modprobe kvm_intel

Installing QEMU in Arch Linux

With KVM support available, we need QEMU to create and manage virtual machines.
The qemu package is installed with the following command:

sudo pacman -Syu qemu

Unlike VirtualBox or VMware, QEMU does not provide graphical interface by default, so we need to install the following package:

sudo pacman -Syu virt-manager

We start the libvirtd service and let it boot:

sudo systemctl enable –now libvirtd

We check its status (it must be active):

sudo systemctl status libvirtd

If we try to start the Virtual Machine Manager menu, we are asked for the root password.

Using Virtual Machine Manager (virt-manager) as a non-root user

1. We will check if the libvirt group exists:

$ getent group | grep libvirt
libvirt:x:613:mvps

If it does not already exist in the system, we will create this group with the following command (where 7777 is the group ID):

# groupadd -g 7777 libvirt

2. Add our user to the libvirt group:

# usermod -aG libvirt username

Check if our user has been added to this group:

$ sudo id mvps | grep libvirt

3. Edit the libvirtd.conf configuration file:

sudo vi /etc/libvirt/libvirtd.conf

and add the following two lines at the end:

unix_sock_group = “libvirt”
unix_sock_rw_perms = “0770”

4. Restart the service:

sudo systemctl restart libvirtd

Logout and then Login to system

We launch Virtual Machine Manager either from the menu or from the command line:

$ virt-manager

Now we have QEMU and KVM in Arch Linux.

You can also install additional packages to ensure the network connectivity (required for non-rpm distributions such as Arch Linux):

• ebtables and dnsmasq for the default NAT/DHCP network
• bridge-utils can create bridge networks
• openbsd-netcat for remote SSH management.

About the author

Ilias spiros
By Ilias spiros

Recent Posts

Archives

Categories