Is the virtualization stack working?

Video 013 of 140 in Virtualization Foundations, in the unit “Setting up your lab machine”. 3:23, with English and Hindi audio.

Once Ubuntu and the course packages are installed, you should check the virtualization stack before you build anything. The stack is made of layers, and each layer depends on the one below it. Two commands test most of it. This article explains each layer, what the two checks prove, and how to read the results when one of them fails.

What you will learn

The three layers under the commands you type

At the bottom is the processor, with its virtualization support switched on. Above it is KVM, the part of the Linux kernel that uses that support. The kernel is the core of the operating system.

Above KVM is libvirt, a service that starts and watches virtual machines. Its command line tool is called virsh. At the top are the commands you type, which talk to libvirt.

Check from the bottom up. If a lower layer fails, the layers above it cannot work, so the fault is usually in the layer that failed first.

How to confirm that KVM can be used

The kvm-ok command checks whether this machine can run virtual machines with KVM acceleration. It must run with sudo, so that it can read the state of the kernel.

Check that KVM acceleration can be used
sudo kvm-ok

How to confirm that libvirt answers you

The virsh list command asks libvirt which virtual machines it manages. The all option includes machines that are switched off. Its header line has three columns: the ID, the name and the state.

List every virtual machine that libvirt knows
virsh list --all

On a new lab, the list has no rows. That is correct, because you have not created a virtual machine yet.

Note: A permission error means your user is not in the libvirt group. Add the user to the groups with the command below, then log out and log in again. Group changes apply only at the next login.

Add your user to the libvirt and kvm groups
sudo usermod -aG libvirt,kvm $USER

How to read the results when a check fails

Run the two first checks

Run these on the lab machine after the packages are installed. You need a terminal and sudo rights. Each step shows what the check proves.

  1. Check that KVM acceleration can be used. This tests the processor support and the KVM device file together.

    sudo kvm-ok

    What you should see: You should see INFO: /dev/kvm exists and then KVM acceleration can be used.

  2. Ask libvirt which virtual machines it knows. This tests that your user can reach libvirt without sudo.

    virsh list --all

    What you should see: A header with ID, Name and State, and no rows on a new lab. A permission error means your user needs the group.

  3. If you saw a permission error, add your user to the libvirt and kvm groups. Then log out and log in again before you test once more.

    sudo usermod -aG libvirt,kvm $USER

    What you should see: Log out and log in again, so the new group membership applies. Then run virsh list --all once more.

Terms

KVM
The part of the Linux kernel that uses the processor's virtualization support to run virtual machines quickly.
libvirt
A service that starts, stops and watches virtual machines, and that its command line tool, virsh, talks to.
Kernel
The core of the operating system, which controls the hardware and runs everything else.
Group
A named set of users that Linux allows to use certain resources, such as libvirt.

Check yourself

What does the line KVM acceleration can be used tell you?

KVM can run virtual machines at full speed on this machine, so the processor support and the KVM device are working.

Why is an empty list from virsh list --all a good result on a new lab?

The list shows the virtual machines that exist. On a new lab you have not created any yet, so no rows is correct.

What should you do if virsh reports a permission error?

Add your user to the libvirt and kvm groups, then log out and log in again so the change applies.

Previous: Installing the course packages. Next: Downloading the Ubuntu cloud image.