This guide explains how you can install and use KVM for creating and running virtual machines on a CentOS 6.0 server. I will show how to create image-based virtual machines . KVM is short for Kernel-based Virtual Machine and makes use of hardware virtualization, i.e., you need a CPU that supports hardware virtualization, e.g. Intel VT or AMD-V.


I’m using a CentOS 6.0 server with the hostname and the IP address here as my KVM host.

I had SELinux disabled on my CentOS 6.0 system. I didn’t test with SELinux on; it might work, but if not, you better switch off SELinux as well:

#vi /etc/selinux/config



Installing KVM

First check if your CPU supports hardware virtualization – if this is the case, the command

#egrep ‘(vmx|svm)’ –color=always /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge 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 extapic cr8_legacy misalignsse
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge 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 extapic cr8_legacy misalignsse

If nothing is displayed, then your processor doesn’t support hardware virtualization, and you must stop here.

Now we import the GPG keys for software packages:

#rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY*

To install KVM and virtinst (a tool to create virtual machines), we run

#yum  groupinstall ‘Virtualization’ #yum install kvm libvirt  python-virtinst   qemu-kvm  virt-manager  virt-viewer


#/etc/init.d/libvirtd start
#/etc/init.d/messagebus start
#/etc/init.d/avahi-daemon start
#chkconfig libvirtd on
#chkconfig messagebus on
#chkconfig  avahi-daemon on

To check if KVM has successfully been installed, run

#virsh -c qemu:///system list
Id Name                 State

If it displays an error instead, then something went wrong.

Next we need to set up a network bridge on our server so that our virtual machines can be accessed from other hosts as if they were physical systems in the network.

To do this, we install the package bridge-utils

#yum install bridge-utils

#vi /etc/sysconfig/network-scripts/ifcfg-br0

NAME=”System br0″

Modify /etc/sysconfig/network-scripts/ifcfg-eth0 as follows (comment out BOOTPROTO, IPADDR, PREFIX, GATEWAY, DNS1, and DNS2 and add BRIDGE=br0):

#vi /etc/sysconfig/network-scripts/ifcfg-eth0

NAME=”System eth0″



2 3

Restart the network

#/etc/init.d/network restart

br0       Link encap:Ethernet  HWaddr 44:37:E6:26:E6:4F
inet addr:  Bcast:  Mask:
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
RX packets:103 errors:0 dropped:0 overruns:0 frame:0
TX packets:79 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7434 (7.2 KiB)  TX bytes:21398 (20.8 KiB)

eth0      Link encap:Ethernet  HWaddr 44:37:E6:26:E6:47
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
RX packets:19511 errors:0 dropped:0 overruns:0 frame:0
TX packets:11592 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25980124 (24.7 MiB)  TX bytes:1104371 (1.0 MiB)
Interrupt:28 Base address:0x6000

lo        Link encap:Local Loopback
inet addr:  Mask:
inet6 addr: ::1/128 Scope:Host
RX packets:7 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3608 (3.5 KiB)  TX bytes:3608 (3.5 KiB)

virbr0    Link encap:Ethernet  HWaddr 6A:12:69:18:2B:05
inet addr:  Bcast:  Mask:
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Virtual systems can easily be configured using either the virt-install command-line tool, or the virt-manager GUI tool. For the purposes of this chapter we will use the virt-manager tool.

Begin by launching virt-manager either by selecting the Applications->System Tools->Virtual Machine Manager or from the command-line in a terminal window by running virt-manager. Once loaded, the virtual manager will prompt for the root password prior to displaying the following screen


The main virt-manager screen lists the current virtual machines running on the system. At this point there should only be one, the host system. By default the manager should be connected to the host. If it is not, connect to the host system by right clicking on the entry in the list and selecting Connect from the popup menu. The Status field for this VM should now change to Active, and the New button at the bottom of the dialog should be enabled.

To create a new virtual system, click on the New button to display the first configuration screen. Click the Forward button to proceed to the Naming screen and enter a name for the virtual system which can be any name you choose. On this screen, also select the location of the media from which the guest operating system will be installed. This can either be a CD or DVD drive, an ISO image file accessible to the local host or a network install using HTTP, FTP, NFS or PXE:


Clicking Forward once more will display a screen seeking additional information about the installation process. The screen displayed and information required will depend on selection made in the preceding screen

Once these settings are complete, click Forward to configure CPU and memory settings. The optimal settings will depend on the number of CPUs and amount of physical memory present in the host and the requirements of other applications and virtual machines that will run in parallel with the new virtual machine:


The last item to configure before creating the virtual machine is the storage space for the guest operating system and corresponding user data. This takes the form of a virtual disk drive. A virtual disk drive is essentially an image file hosted on the file system of the host computer which is seen by the virtual machine as a physical disk drive.


Options are available to create an image disk of a specified size, select a pre-existing volume or to create a storage volume of a specified format (raw, vmdk, iso etc). Unless you have a specific need to use a particular format (for example you might need to use vmdk to migrate to a VMware based virtualization environment at a later date) or need to use a dedicated disk or partition, it is generally safe to simply specify a size on this screen. The option is also available to pre-allocate the space now. If you choose not to pre-allocate the space, space will be allocated up to the specified maximum only as it is needed by the guest operating system. This has the advantage that space on the host file system is not used until it is needed. Downsides are that performance may degrade as space is allocated in real-time and allocation will fail if another process uses up the free space on the host file system before it can be assigned to the virtual machine:

8 9 10 11

Once these settings are configured, click the Forward key once more. The final screen displays a summary of the configuration. Review the information displayed. Advanced options are also available to configure bridged networking (where the virtual machine has direct access to a host network adapter) and to configure a specific MAC address if required: