How to Install and Configure KVM in ArchLinux/Manjaro

Kernel-based Virtual Machine(KVM) is a virtualization module in the Linux kernel that allows the kernel to function as a hypervisor. It is the leading open source virtualisation technology for Linux. It installs natively on all Linux distributions and turns underlying physical servers into hypervisors so that they can host multiple, isolated virtual machines (VMs). KVM comes with no licenses, type-1 hypervisor capabilities and a variety of performance extensions which makes it an ideal candidate for virtualisation and cloud infrastructure implementation. 

# Step 1 – Checking support for KVM

# Hardware support

KVM requires that the virtual machine host’s processor has virtualization support (named VT-x for Intel processors and AMD-V for AMD processors). You can check whether your processor supports hardware virtualization with the following command:

$ LC_ALL=C lscpu | grep Virtualization


$ grep -E --color=auto 'vmx|svm|0xc0f' /proc/cpuinfo

If nothing is displayed after running either command, then your processor does not support hardware virtualization, and you will not be able to use KVM.

# Kernel support

Arch Linux kernels provide the required kernel modules to support KVM.

  • One can check if the necessary modules, kvm and either kvm_amd or kvm_intel, are available in the kernel with the following command:
$ zgrep CONFIG_KVM /proc/config.gz

The module is available only if it is set to either y or m.

  • Then, ensure that the kernel modules are automatically loaded, with the command:
➜ lsmod | grep kvm
kvm_intel             364544  0
kvm                  1097728  1 kvm_intel
irqbypass              16384  1 kvm

# Step 2 – Install KVM for ArchLinux/Manjaro

Fire up the terminal and run the following code for a direct install of KVM:

sudo pacman -S virt-manager virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat

Also install ebtables  and iptables packages:

sudo pacman -S ebtables iptables

libguestfs is a set of tools used to access and modify virtual machine (VM) disk images. You can use this for:

  • viewing and editing files inside guests
  • scripting changes to VMs
  • monitoring disk used/free statistics
  • creating guests
  • P2V
  • V2V
  • performing backup e.t.c
sudo pacman -S libguestfs

# Start KVM libvirt service

Once the installation is done, start and enable libvirtd service to start at boot:

sudo systemctl enable libvirtd.service<br>sudo systemctl start libvirtd.service

Status show it’s running:

➜ systemctl status libvirtd.service                                                                                                                                             (gke_upvest-production_europe-west3-c_sandbox-kiows4/default)
● libvirtd.service - Virtualization daemon
     Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: disabled)
     Active: active (running) since Fri 2022-05-20 09:32:11 EAT; 10s ago
TriggeredBy: ● libvirtd.socket
             ● libvirtd-ro.socket
             ● libvirtd-admin.socket
       Docs: man:libvirtd(8)
   Main PID: 22933 (libvirtd)
      Tasks: 19 (limit: 32768)
     Memory: 18.1M
        CPU: 184ms
     CGroup: /system.slice/libvirtd.service
             └─ 22933 /usr/bin/libvirtd --timeout 120

May 20 09:32:11 home-pc systemd[1]: Starting Virtualization daemon...
May 20 09:32:11 home-pc systemd[1]: Started Virtualization daemon.

# Enable normal user account to use KVM

Since we want to use our standard Linux user account to manage KVM, let’s configure KVM to allow this.

Open the file_ /etc/libvirt/libvirtd.conf_ for editing with your text editor. I am using vim.

sudo vim /etc/libvirt/libvirtd.conf

Set the UNIX domain socket group ownership to libvirt, (around line 85)

unix_sock_group = "libvirt"

Set the UNIX socket permissions for the R/W socket (around line 102)

unix_sock_rw_perms = "0770"

Add your user account to libvirt group.

sudo usermod -a -G libvirt $(whoami)<br>newgrp libvirt

Restart libvirt daemon.

sudo systemctl restart libvirtd.service

# Enable Nested Virtualization (Optional)

Nested Virtualization feature enables you to run Virtual Machines inside a VM. Enable Nested virtualization for kvm_intel / kvm_amd by enabling kernel module as shown.

# For Intel Processor
sudo modprobe -r kvm_intel
sudo modprobe kvm_intel nested=1

# For AMD Processor
sudo modprobe -r kvm_amd
sudo modprobe kvm_amd nested=1

To make this configuration persistent,run:

echo "options kvm-intel nested=1" | sudo tee /etc/modprobe.d/kvm-intel.conf

Confirm that Nested Virtualization is set to Yes:

# For Intel processors
➜ systool -m kvm_intel -v | grep nested
    nested              = "Y"
    nested_early_check  = "N"

➜ cat /sys/module/kvm_intel/parameters/nested

# For AMD Processor
$ systool -m kvm_amd -v | grep nested
    nested              = "Y"
    nested_early_check  = "N"

$ cat /sys/module/kvm_amd/parameters/nested 

# Using KVM on Arch Linux / Manjaro

You have successfully installed KVM, QEMU and Virt Manager on Arch Linux and Manjaro. You are now good to go.

Open virt-manager from your launcher to get started.

You can install a Linux or Windows OS Virtual Machine and build your labs.

Related content:

[1]: data:image/svg+xml,%3Csvg xmlns=%22 width=%221024%22 height=%22490%22%3E%3C/svg%3E

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy