What is KVM?
KVM is an open source Kernel-based Virtualization Machine that is offering virtualization for Linux operating systems that enables Linux to function as a hypervisor for running multiple virtual machines (VMs).
KVM has been directly integrated into the Linux kernel as of 2007’s 2.6.20 Linux kernel release. KVM is the basis for both IBM’s and Red Hat’s Linux virtualization technologies, and it’s also the most widely used virtualization technology in the OpenStack cloud.
KVM is type-1 hypervisor that can be added to a most Linux operating systems including Ubuntu, SUSE, and Red Hat Enterprise Linux.
You must determine whether your system’s processor and/or hypervisor support hardware acceleration for virtual machines.
Run the following command:
# egrep -c ‘(vmx|svm)’ /proc/cpuinfo
If this command returns a value of one or greater, your system supports hardware acceleration which typically requires no additional configuration.
If this command returns a value of zero, your system does not support hardware acceleration and you can configure libvirt to use QEMU instead of KVM.
qemu-kvm: Core KVM package for managing VM’s through /dev/kvm file for interacting with direct hardware. This package contains KVM, libvirt-bin etc.
libvirt*: This proves us useful command line tool called virsh which is text-based tool to manage virtual machines.
Always use FQDN Domain Name
Configure FQDN (fully qualified domain name) for your host. Otherwise, you may get warnings while launching libvirtd daemon such as “getaddrinfo failed for ‘myhost’: Name or service not known”.
To configure FQDN, edit the following configuration file:
# vi /etc/sysconfig/network
Before installing KVM, be aware that there are several SELinux booleans that can affect the behavior of KVM and libvirt.
To disable SELinux on CentOS:
Reboot the machine for the change to take effect.
How to install KVM in CentOS
Use the below steps to install KVM hypervisor in Centos and other modules.
#yum install kvm libvirt python-virtinst qemu-kvm
Start libvirtd daemon, and set it to auto-start:
# service libvirtd start
# chkconfig libvirtd on
Check if KVM has successfully been installed. You can list all the virtual machines with no error as follows.
#virsh list –all
Id Name State
Setup Linux Bridge for VMs Networking
Installing KVM alone does not allow VMs to communicate with each other or access external networks. You need to configure VM networking separately. use the blow tutorial to setup linux bridge on centos.
How to install VirtManager
The virt-manager application is a desktop user interface for managing virtual machines through libvirt. It primarily targets KVM VMs, but also manages Xen and LXC (linux containers). It presents a summary view of running domains, their live performance & resource utilization statistics. Use the following command to install it.
#yum install virt-manager libvirt qemu-system-x86 openssh-askpass libcanberra-devel
Once the installation completed. You can launch the VirtManager locally using CentOS desktop machine.
If you are using CentOS server without desktop UI, follow these steps to launch VirtManager.
Enable X11 forwarding on SSH server:
#yum install xauth
#service sshd restart
Create a following executable “wrapper” script for virt-manager.
xauth list | while read line; do
sudo -i xauth add $line
sudo -i virt-manager
#chmod 755 /usr/bin/vm
Thats all.. Connect to your CentOS server from a separate desktop machine, and run the wrapper script vm to launch VirtManager remotely.
#ssh -X [email protected]
1. If you see the following error when attempting to launch VirtManager remotely, make sure that you use the wrapper script (vm) to launch it, as described above.
X11 connection rejected because of wrong authentication.
Traceback (most recent call last):
File “/usr/share/virt-manager/virt-manager.py”, line 383, in
File “/usr/share/virt-manager/virt-manager.py”, line 286, in main
RuntimeError: could not open display
2. If you see the following D-Bus error:
D-Bus library appears to be incorrectly set up; failed to read machine
uuid: UUID file ‘/var/lib/dbus/machine-id’
Then run the command below and reboot the host machine.
# sh -c ‘dbus-uuidgen > /var/lib/dbus/machine-id’
3. If you have font issue while running VirtManager, install the following font, and relaunch it.
#yum install dejavu-lgc-sans-fonts