When you think of working with virtual machines, chances are you default to either VMWare or VirtualBox. But there’s another player in town — a full virtualization solution, owned by Red Hat, called KVM (Kernel-based Virtual Machine). Why would you choose KVM over VirtualBox? There are plenty of reasons to choose one over the other. One good reason for KVM is that it’s faster and the necessary drivers are included in the official kernel tree.

No matter which way you turn, it’s always good to have choice; and KVM offers just that. So, if you want to get KVM up and running, I am here to show you how. The process is quite easy (though maybe not quite as easy as VirtualBox), so you should have your virtual machines up and running in no time.

I’ll be demonstrating on a Ubuntu Linux 17.10 host.

Testing and installing

The first thing you need to do is ensure you desktop or server includes hardware support for virtual machines. You can do this by way of a single command. Open up your terminal window and issue the command:

egrep -o '(vmx|svm)' /proc/cpuinfo

You should get either vmx (for Intel) or svm (for AMD) reported back. Once you’re certain your machine is capable of running the virtual machines, you are ready to install the necessary software. Go back to your terminal window and issue the command:

sudo apt-get install kvm qemu-kvm libvirt-bin virt-manager bridge-utils

Once the installation command completes, you need to add your user to the libvirtd group with the command:

sudo useradd -g libvirtd USERNAME

Where USERNAME is the name of the user who will be working with KVM. With that complete, log out of the system and log back in. You are ready to create your first KVM-driven virtual machine.

Creating a virtual machine

From whatever desktop menu you use, locate the Virtual Machine Manager and fire it up. In the resulting window, click File | New Virtual Machine. When the New VM wizard starts (Figure A), walk through the steps of creating your new virtual machine.

Figure A

If you’ll be creating your VM from an .iso file, select Local install media and click Forward. In the next window, select Use ISO image and then click Browse. This will open up the Storage Volume Manager (Figure B).

Figure B

The first thing you’re going to do create a new storage pool to be used for the virtual machine (as the default lies in /var/lib/libvirt/images and you probably don’t want to use that, due to size and security issues). In the left pane, click the + button. In the resulting window, name your new storage pool and select dir:Filesystem Directory from the drop-down (Figure C).

Figure C

In the next window, locate the target path to house your new pool and click Finish.

Once you’ve done that, click Browse Local and locate your .iso to be used for the virtual machine. Click Forward and, in the next window (Figure D), allocate the necessary amount of RAM and CPUs for your VM.

Figure D

Now we need to select the storage pool we created earlier. In the next window click Select or create custom storage and click the Manage button (Figure E).

Figure E

Select the new pool from the left pane and then click the + button next to Volumes. Configure the storage volume to meet your needs (give it a name, select qcow2 from the drop-down, and then size it as required). Click Finish and the storage volume will appear in the right pane. Select that new volume and click Choose Volume. Back in the New VM window, click Forward. Give the new VM a name and click Finish. The VM will start up and the .iso will boot so you can install your guest operating system.

The choice is yours

KVM isn’t nearly as user-friendly as the likes of VirtualBox; but what you lose in simplicity, you gain in flexibility and performance. Once you get used to creating virtual machines with KVM, you might find yourself not wanting to go back to the competition.