Installing and configuring a KVM
This recipe covers the installing of virtualization tools and packages on RHEL 7.
By default, a RHEL 7 system doesn't come with a KVM or libvirt preinstalled. This can be installed in three ways:
- Through the graphical setup during the system's setup
- Via a kickstart installation
- Through a manual installation from the command line
For this recipe, you should know how to install packages using yum, and your system should be configured to have access to the default RHEL 7 repository (refer to Chapter 8, Yum and Repositories, for more information), which is required for the packages that we will use.
Alternatively, you could install packages from the installation media using rpm
, but you'll need to figure out the dependencies yourself.
Check the dependencies of an rpm
using the following command:
~]# rpm -qpR <rpm file>
This will output a list of binaries, libraries, and files that you need installed prior to installing this package.
Check which package contains these files through this command:
~]# rpm -qlp <rpm package>
As you can imagine, this is a tedious job and can take quite some time as you need to figure out every dependency for every package that you want to install in this way.
Getting ready
To install a KVM, you will require at least 6 GB of free disk space, 2 GB of RAM, and an additional core or thread per guest.
Check whether your CPU supports a virtualization flag (such as SVM or VMX). Some hardware vendors disable this in the BIOS, so you may want to check your BIOS as well. Run the following command:
~]# grep -E 'svm|vmx' /proc/cpuinfo flags : ... vmx ...
Alternatively, you can run the following command:
~]# grep -E 'svm|vmx' /proc/cpuinfo flags : ... svm ...
Check whether the hardware virtualization modules (such as kvm_intel
and kvm
) are loaded in the kernel using the following command:
~]# lsmod | grep kvm kvm_intel 155648 0 kvm 495616 1 kvm_intel
How to do it…
We'll look at the three ways of installing a KVM onto your system.
Manual installation
This way of installing a KVM is generally done once the base system is installed by some other means. You need to perform the following steps:
- Install the software needed to provide an environment to host virtualized guests with the following command:
~]# yum -y install qemu-kvm qemu-img libvirt
The installation of these packages will include quite a lot of dependencies.
- Install additional utilities required to configure
libvirt
and install virtual machines by running this command:~]# yum -y install virt-install libvirt-python python-virthost libvirt-client
- By default, the
libvirt
daemon is marked toautostart
on each boot. Check whether it is enabled by executing the following command:~]# systemctl status libvirtd libvirtd.service - Virtualization daemon Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled) Active: inactive Docs: man:libvirtd(8) http://libvirt.org
- If for some reason this is not the case, mark it for autostart by executing the following:
~]# systemctl enable libvirtd
- To manually stop/start/restart the
libvirt
daemon, this is what you'll need to execute:~]# systemctl stop libvirtd ~]# systemctl start libvirtd ~]# systemctl restart libvirtd
Kickstart installation
Installing a KVM during kickstart offers you an easy way to automate the installation of KVM instances. Perform the following steps:
- Add the following package groups to your kickstarted file in the
%packages
section:@virtualization-hypervisor @virtualization-client @virtualization-platform @virtualization-tools
- Start the installation of your host with this kickstart file.
Graphical setup during the system's setup
This is probably the least common way of installing a KVM. The only time I used this was during the course of writing this recipe. Here's how you can do this:
- Boot from the RHEL 7 Installation media.
- Complete all steps besides the Software selection step.
- Go to Software Selection to complete the KVM software selection.
- Select the Virtualization host radio button in Base Environment, and check the Virtualization Platform checkbox in Add-Ons for Selected Environment:
- Finalize the installation.
- On the Installation Summary screen, complete any other steps and click on Begin Installation.
See also
To set up your repositories, check out Chapter 8, Yum and Repositories.
To deploy a system using kickstart, refer to Chapter 2, Deploying RHEL "En Masse".
For more in-depth information about using libvirt, go to http://www.libvirt.org/.
RHEL 7 has certain support limits, which are listed at these locations: