Thursday, February 15, 2018

Install KVM (QEMU) on CentOS 7 / RHEL 7

KVM stands for Kernel-Based Virtual Machine, is a virtualization software which provides an ability to run a multiple guest operating systems with the help of hardware virtualization extensions. It supports a wide variety of guest operating system’s such as Linux, Windows, Solaris, Haiku, REACT OS and much more.
KVM can be managed using a command line or available graphical tools. Virt-Manager (Virtual Machine Manager)  is the most widely used application for managing KVM based virtual machines. It supports creating, editing, starting, and stopping KVM-based virtual machines, as well as the live or cold migration of guest machines between hosts.


As said earlier, KVM will work only if the CPU has the support of hardware virtualization, either Intel VT or AMD-V.
To find whether your CPU supports VT features, run the following command.
egrep '(vmx|svm)' /proc/cpuinfo

CentOS 7 - Intel VT Support
CentOS 7 – Intel VT Support
If the above command returns with output showing VMX or SVM, then your hardware supports VT else it does not.
Create a network bridge so that virtual machines can communicate with the external network.
READ: How to configure Network bridge on CentOS 7 / RHEL 7

Install KVM on CentOS 7

Issue the following command to install latest qemu package and also virt-manager which provides a graphical interface to manage virtual machines.
yum install -y qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer
  • qemu-kvm =  QEMU emulator
  • qemu-img = QEMU disk image manager
  • virt-install =  Command line tool to create virtual machines.
  • libvirt = Provides libvirtd daemon that manages virtual machines and controls hypervisor.
  • libvirt-client  = provides client-side API for accessing servers and also provides the virsh utility which provides command line tool to manage virtual machines.
  • virt-viewer – Graphical console

Create Virtual Machine

Once you have installed KVM and other tools, it is all set to start creating virtual machines. We will look be looking at creating virtual machines both in command-line and graphical mode.

Command Line Mode

virt-install is used to create virtual machines using the command line mode, and this command needs multiple inputs from us to create a virtual machine such as CPU, Memory, disk, network, installation media location, OS variant and more.
virt-install  --name=itzgeekguest  --ram=1024  --vcpus=1  --cdrom=/tmp/CentOS-6.5-x86_64-minimal.iso --os-type=linux --os-variant=rhel6  --network bridge=br0 --graphics=spice  --disk path=/var/lib/libvirt/images/itzgeekguest.dsk,size=4
Note: The above command uses bridged networking “br0” for allowing virtual machines to communicate with outside network, you can find a tutorial on creating bridged networking with Virt Manager.
–name  –  Name of the Virtual machine
–ram – Memory size in MB
–vcpus – Virtual CPU’s in numbers
–cdrom – Location of the ISO image
–os-type – OS types like Linux, Windows, etc.
–os-variant  – OS variant like RHEL 6, Solaris
–network – Networking
–graphics – Guest display settings
–disk path –  Location of the disk with size of 4 GB
Once you’ve issued the above command, virt-install will create a virtual machine and starts virt viewer console for OS installation.

Graphical Mode

Type the following command in the terminal in GUI mode.
Application >> System Tools >> Virtual Machine Manager.
You may be asked to enter a password if you don’t have root access.
Once it is opened, right-click on localhost(QEMU) and Click on New. Virtual Machine Manager will start a new wizard for creating a virtual machine. You will find no difficulty in using this graphical mode.