Installing KVM Virtualization on CentOS

Revision as of 14:36, 5 May 2016 by Neil (Talk | contribs) (Text replacement - "<table border="0" cellspacing="0" width="100%">" to "<table border="0" cellspacing="0">")

Revision as of 14:36, 5 May 2016 by Neil (Talk | contribs) (Text replacement - "<table border="0" cellspacing="0" width="100%">" to "<table border="0" cellspacing="0">")

PreviousTable of ContentsNext
Managing Xen on CentOS using the xm and virsh Command-line ToolsCreating a CentOS KVM Networked Bridge Interface


You are reading a sample chapter from the CentOS 5 Essentials Essentials book.

Purchase a copy of the fully updated CentOS 8 edition in eBook ($24.99) or Print ($36.99) format

CentOS 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 260 pages. Learn more...

Buy Print Preview Book

As discussed in previous chapters of this book, virtualization is the ability to run multiple operating systems simultaneously on a single computer system, and a number of different commercial and open source solutions are available. In the preceding chapters we looked in detail at configuring and maintaining Xen based virtualization on CentOS 5. In this and subsequent chapters we will look at KVM based virtualization hosted on a CentOS system.

KVM Hardware Requirements

Before proceeding with this chapter we need to take a moment to discuss the hardware requirements for running virtual machines within a KVM environment. Firstly, KVM virtualization is only available on certain processor types. These processors include either Intel-VT or AMD-V technology.

To check for Intel-VT support, run the following command in a terminal window to check for the presence of vmx:

# grep vmx /proc/cpuinfo 
flags           : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush dts 
acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm

To check for AMD-V support, run the following command which checks for the presence of svm:

# grep svm /proc/cpuinfo
flags           : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush mmx fxsr sse sse2 ht 
syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8_legacy

Note that while the above commands only report whether the processor supports the respective feature, it does not indicate whether the feature is currently enabled in the BIOS. In practice virtualization support is typically disabled in the BIOS of most systems. It is recommended, therefore, that you check your BIOS settings to ensure the appropriate virtualization technology is enabled before proceeding with this tutorial.

If your processor does not have Intel-VT or AMD-V support you will still be able to install guest operating systems though this will be implemented using the QEMU environment instead of KVM virtualization. QEMU uses emulation to run guest operating systems and as such results in slower performance than the hardware assisted virtualization offered by KVM.

Unlike a dual booting environment a virtualized environment involves the running of two or more complete operating systems concurrently on a single computer system. This means that the system must have enough physical memory, disk space and CPU processing power to comfortably accommodate all these systems in parallel. Before beginning the configuration and installation process check on the minimum system requirements for both CentOS and your chosen guest operating systems and verify that your system has sufficient resources to handle the requirements of both systems.

32-bit Support for KVM on CentOS 5

Whilst previous versions of CentOS supported KVM on both 32-bit and 64-bit systems, as of CentOS 5.4 support for KVM virtualization is only available for 64-bit (x86_64 architecture) versions of the operating system.


Preparing CentOS for KVM Virtualization

Unlike Xen, it is not necessary to run a special version of the kernel in order to support KVM. As a result KVM support is already available for use with the standard kernel via the installation of a KVM kernel module, thereby negating the need to install and boot from a special kernel.

To avoid conflicts, however, if a Xen enabled kernel is currently running on the system, reboot the system and select a non-Xen kernel from the boot menu before proceeding with the remainder of this chapter. The tools required to setup and maintain a KVM based virtualized system are not installed by default unless specifically selected during the CentOS operating system installation process. To install KVM from the command prompt, execute the following command in a terminal window with root privileges:

yum install kvm virt-manager

Alternatively, launch the Package Manager by selecting the Applications -> Add/Remove Software menu from the desktop menu system. Enter the root password if prompted to do so and scroll down the list of categories, selecting Virtualization when it becomes visible.

In the right hand column make sure that Virtualization is not selected. If it is selected, deselect it and click on the Apply button. Once these packages have been removed, select KVM and click on Apply once again to install the KVM package and any additional dependencies. If the installation fails with a message similar to the following then it is likely that you are attempting to install KVM on a 32-bit system, or a 64-bit system running a 32-bit version of CentOS 5:

Error: libvirt conflicts with kvm

Once the installation of KVM is complete, close any applications that are running and reboot the system.

Verifying the KVM Installation

Once the system has restarted after the reboot it is worthwhile checking that the installation worked correctly before moving forward. When KVM is installed and running two modules will have been loaded into the kernel. The presence or otherwise of these modules can be verified in a terminal window by running the following command:

su -
lsmod | grep kvm 

Assuming that the installation was successful the above command should generate output similar to the following:

lsmod | grep kvm
kvm_intel              86920  1
kvm                   226208  2 ksm,kvm_intel

Note that if the system contains an AMD processor the kvm module will likely read kvm_amd rather than kvm_intel.

The installation process should also have configured the libvirtd daemon to run in the background. Once again using a terminal window with super user privileges, run the following command to ensure libvirtd is running:

/sbin/service libvirtd status
libvirtd (pid  2958) is running...

If the process is not running, it may be started as follows:

/sbin/service libvirtd start

Finally, run the virt-manager tool by selecting the Applications -> System Tools -> Virtual Machine Manager menu. When loaded, the manager should appear as illustrated in the following figure:


The virt-manager on a KVM enabled CentOS system


If Xen virtualization was previously installed on the system, an error message may appear stating that virt-manager is “unable to open a connection to Xen hypervisor/daemon”. If this occurs, dismiss the error dialog, select the xen entry from the main virt-manager screen and click on the Delete button to remove it from the database.

If, on the other hand, the QEMU entry is not listed, select the File -> Add Connection menu option and in the resulting dialog select the QEMU hypervisor before clicking on the Connect button:

If the manager is not currently connected to the virtualization processes, right click on the entry listed and select Connect from the popup menu.

In theory the system is now ready to create virtual machines into which guest operating systems may be installed and run. Before taking that step, it is worth spending some time in the next chapter talking about virtual networks and network bridges.


You are reading a sample chapter from the CentOS 5 Essentials Essentials book.

Purchase a copy of the fully updated CentOS 8 edition in eBook ($24.99) or Print ($36.99) format

CentOS 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 260 pages. Learn more...

Buy Print Preview Book


PreviousTable of ContentsNext
Managing Xen on CentOS using the xm and virsh Command-line ToolsCreating a CentOS KVM Networked Bridge Interface