RHCSA – Managing KVM based Virtual Machines

KVM overview

By the end of this article you should be able to answer the following questions:

What is the command to install all the vm related packages?

$ yum install \
virt-manager \
libvirt \
libvirt-client \
libvirt-python \
qemu-kvm \
qemu-img \

What is the command to enable the kernel's virtualisation feature, and how do check for it?

$ modprobe kvm
$ lsmod | grep kvm
kvm 461126 0

What is the command to start+enable the virtualization related service?

$ systemctl start libvirtd
$ systemctl enable libvirtd

What are the three main utilities that interacts with the above sevice?

– virt-manager # open gui tool
– virsh # cli tool for managing tools
– virt-install # cli alternative to gui tool

What is the command?

What is the command?

What is the command?

What is the command?

What is the command?

What is the command?

Hardware requirements

kvm is what reserves cpu resources and use the reserved cpu resources to hosts guest vms on the host machine. KVM allows virtualisation to happen.

If your RHEL machine is a vm, e.g. your machine is running inside a virtualbox, then you can’t run KVM inside it. Hence the first requirement is that you have to have a physical machine that’s running RHEL.

Another requirement is that your machine cpu must support the following features:

$ egrep 'vmx|svm' /proc/cpuinfo

Either vmx or svm flag needs to exist.

Most most modern cpu’s support this. If your’s don’t then it’s likely that you’re using a machine that has a rather old cpu.

Required packages

You need to use yum to install the following packages:

  1. virt-manager – this gives us the gnome based user interface for managing VMs. You can access this by going to Applications -> System tools -> Virtual Machine Manager. This utility interacts with with the libvirtd daemon. This get’s installed as a dependency when installing libvirt
  2. libvirt – this is a middleman that allows virt-manage/virsh to interact with qemu+kvm
  3. qemu-kvm
  4. qemu-img
  5. libvirt-python
  6. python-virtinst
  7. libvirt-client – this provides a commandline alternative (called virsh) to virt-manager.
$ yum install virt-manager libvirt qemu-kvm qemu-img libvirt-python python-virtinst libvirt-client

kernel requirements

You need to enable the following kernal module:

$ lsmod | grep kvm   
$ modprobe kvm
$ lsmod | grep kvm
kvm                   461126  0

The libvirtd service

The libvirtd is a service that manages virtualization in general, and is not just limited to kvm virtualization.

To manage vms, this service needs to be running+enabled:

$  systemctl status libvirtd -l
libvirtd.service - Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled)
   Active: active (running) since Mon 2015-05-04 14:06:49 BST; 18s ago
     Docs: man:libvirtd(8)
 Main PID: 2289 (libvirtd)
   CGroup: /system.slice/libvirtd.service
           └─2289 /usr/sbin/libvirtd

May 04 14:06:49 localhost.localdomain libvirtd[2289]: libvirt version: 1.2.8, package: 16.el7_1.2 (CentOS BuildSystem , 2015-03-26-23:17:42, worker1.bsys.centos.org)
May 04 14:06:49 localhost.localdomain libvirtd[2289]: Module /usr/lib64/libvirt/connection-driver/libvirt_driver_lxc.so not accessible
May 04 14:06:49 localhost.localdomain systemd[1]: Started Virtualization daemon.

The libvirtd service can be managed by the following tools:

  • virt-manager – This is a GUI that allows you to easily manage vms
  • virsh – short for virtualization shell. It let’s you manage vms using scripts. Really useful when managing multiple VMs.
  • virt-install -lets you create vms. It’s a cli alternative to virt-manager