Desktop Virtualization with KVM

Wed 18 May 2016

The following is a basic tutorial for getting up and running with using KVM for virtualization on a desktop running Fedora or CentOS and other RHEL variants. KVM is built-in to the Linux kernel and offers excellent performance. Its inclusion with most major distributions makes it a great for development work or testing on your desktop/laptop workstation.

If you like watching Youtube videos, I walked through this and recorded a little video:

Installing KVM Packages

First, install packages.

The following was tested for Fedora 22+. Will probably work without much variation on earlier releases.

$ sudo dnf group install @virtualization

For CentOS 7, and other RHEL 7 variants:

$ sudo yum group install "Virtualization Host"
$ sudo yum install virt-manager

By default, the services should be enabled and running. To verify:

$ systemctl status libvirtd
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/etc/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/libvirtd.service.d
   Active: active (running) since Tue 2016-04-05 08:26:26 MDT; 1 months 12 days ago
     Docs: man:libvirtd(8)
 Main PID: 6482 (libvirtd)
   CGroup: /system.slice/libvirtd.service
           └─6482 /usr/sbin/libvirtd

Notice, the Active: line should state running.

Configuring polkit

You'll need to do some further configuration so that non-root users can manage KVM guests. The following will create a local group called virt and add the user mike to to that group.

$ sudo groupadd virt
$ sudo usermod -aG virt mike
$ sudo mkdir -p /etc/polkit-1/localauthority/50-local.d/

Now, create a file, /etc/polkit-1/localauthority/50-local.d/50-org.example.libvirt-access.pkla with the contents:

[libvirt Admin Access]

GUI Management

Use the app virt-manager to manage your KVM installation through the GUI. It's a very straighforward and easy to use GUI. Watch the video above for a quick walkthrough.

CLI Management

The environment variable LIBVIRT_DEFAULT_URI can be used to specify the libvirt instance to connect to. Put this in your .bash_profile:

export LIBVIRT_DEFAULT_URI=qemu:///system

Use virt-install to install VMs, use virsh to manage them. I almost never use virt-install and instead prefer to install through the GUI, but virsh is a very useful utility.

$ man virt-install
# List all guests/domains on system, including those that are powered off
$ virsh list --all
# Turn on a guest
$ virsh start <domain>
# Shutdown the guest
$ virsh shutdown <domain>
# Pull the plug
$ virsh destroy <domain>
$ man virsh

VirtIO for Windows

In general, the virtiod evices (NIC, storage) provide the best performance. Most recent Linux kernels (since version?) have these drivers included. Windows guests won't.

You'll need to mount an ISO containing the virtio drivers during Windows guest installation. See this Fedora Wiki article. This also includes the memory balloon drivers.

$ sudo wget \
>     -O /etc/yum.repos.d/virtio-win.repo
$ sudo dnf install virtio-win
$ sudo yum install virtio-win

During installation, mount the ISO /usr/share/virtio-win/virtio-win.iso and load the vistor, netkvm, and balloon drivers.


That should cover the basics of using KVM as a virtualization platform. Please let me know if you have any suggestions to improve this tutorial or questions. You can use the comments below.