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 stack runs from the processor, through KVM and libvirt, up to the commands you type.
- kvm-ok checks the processor support and the KVM device file.
- virsh list checks that libvirt answers your user.
- An empty list is correct for a new lab, because no virtual machines exist yet.
- A permission error usually means a missing group, not a broken machine.
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.
sudo kvm-ok- The line INFO: /dev/kvm exists means the KVM device file is present. Programs use that file to ask the kernel to run virtual machines.
- The line KVM acceleration can be used is the good result. Your virtual machines will run fast.
- Any other answer means the processor support is off. Go back to the firmware setting and switch it on.
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.
virsh list --allOn 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.
sudo usermod -aG libvirt,kvm $USERHow to read the results when a check fails
- Both checks pass: the lab is ready for the rest of its work.
- kvm-ok fails: the problem is below libvirt, so look at the processor setting in the firmware first, not at your commands.
- virsh is denied: the processor is usually fine. Your user needs the group and a fresh login.
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.
Check that KVM acceleration can be used. This tests the processor support and the KVM device file together.
sudo kvm-okWhat you should see: You should see INFO: /dev/kvm exists and then KVM acceleration can be used.
Ask libvirt which virtual machines it knows. This tests that your user can reach libvirt without sudo.
virsh list --allWhat 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.
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 $USERWhat 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.