Install KVM Hypervisor on CentOS 7.x and RHEL 7.x

KVM is an open source hardware virtualization software through which we can create and run multiple Linux based and windows based virtual machines simultaneously. KVM is known as Kernel based Virtual Machine because when we install KVM package then KVM module is loaded into the current kernel and turns our Linux machine into a hypervisor.

In this post first we will demonstrate how we can install KVM hypervisor on CentOS 7.x and RHEL 7.x and then we will try to install virtual machines.

Before proceeding KVM installation, let’s check whether your system’s CPU supports Hardware Virtualization.

Run the beneath command from the console.

[[email protected] ~]# grep -E '(vmx|svm)' /proc/cpuinfo

We should get the word either vmx or svm in the output, otherwise CPU doesn’t support virtualization.

Step:1 Install KVM and its associate packages

Run the following yum command to install KVM and its associated packages.

[[email protected] ~]# yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils

Start and enable the libvirtd service

[[email protected] ~]# systemctl start libvirtd
[[email protected] ~]# systemctl enable libvirtd

Run the beneath command to check whether KVM module is loaded or not

[[email protected] ~]# lsmod | grep kvm
kvm_intel             162153  0
kvm                   525409  1 kvm_intel
[[email protected] ~]#

In Case you have Minimal CentOS 7 and RHEL 7 installation , then virt-manger will not start for that you need to install x-window package.

[[email protected] ~]# yum install "@X Window System" xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils -y

Reboot the Server and then try to start virt manager.

Step:2 Start the Virt Manager

Virt Manager is a graphical tool through which we can install and manage virtual machines. To start the virt manager type the ‘virt-manager‘ command from the terminal.

[[email protected] ~]# virt-manager


Step:3 Configure Bridge Interface

Before Start creating VMs , let’s first create the bridge interface. Bridge interface is required if you want to access virtual machines from outside of your hypervisor network.

[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-eno49 ifcfg-br0
[[email protected] network-scripts]#

In cp command replace the interface name that suits to your system and then edit the Interface file and set followings:

[[email protected] network-scripts]# vi ifcfg-eno49

Edit the Bridge file (ifcfg-br0) and set the followings:

[[email protected] network-scripts]# vi ifcfg-br0

Replace the IP address and DNS server details as per your setup.

Restart the network Manager Service to enable the bridge interface.

[[email protected] ~]# systemctl restart NetworkManager
[[email protected] ~]#

Note: By default, in CentOS 7 / RHEL 7 Network Manager service is enabled and if have made changes in network files then we must restart Network Manager service to make the changes into the effect. In Case network Manager service is disabled and stopped then we can use network service (systemctl restart network)

Check the Bridge interface using below command :

[[email protected] ~]# ip addr show br0

Step:4 Start Creating Virtual Machines.

Now Create Virtual Machine either from the command line using ‘virt-install‘ command or from GUI (virt-manager )

Let’s Create a virtual machine of “Windows Server 2012 R2” using virt-manager.

Start the “virt-manager”

Go to the File Option, click on “New Virtual Machine”


We will be using ISO file as installation media. In the next step Specify the path of ISO file.


Click on Forward.

Specify the Compute Resources : RAM and CPU as per your setup.


Click on Forward to proceed further.

Specify the storage Size of Virtual Machine, In my case I am using 25G.


In the Next step Specify the Name of Virtual Machine and select network as ‘ Bridge bro’


Click on Finish to start the installation.


Follow the screen instructions and complete the installation.

Creating a virtual Machine from Command Line:

Virtual Machines can be created from the console as well using ‘virt-install’ command. In the following example i going to virtual machine of Ubuntu 16.04 LTS.

[[email protected] ~]# virt-install --name=Ubuntu-16-04 --file=/var/lib/libvirt/images/ubuntu16-04.dsk --file-size=20 --nonsparse --graphics spice --vcpus=2 --ram=2048 --cdrom=ubuntu-16.04-server-amd64.iso --network bridge=br0 --os-type=linux --os-variant=generic
Starting install...
Allocating 'ubuntu16-04.dsk'               | 20 GB 00:00:00
Creating domain...


Follow the instruction now and complete the installation.

In the above ‘virt-install’ command we have used following options :

  • –name = <Name of the Virtual Machine>
  • –file = <Location where our virtual machine disk file will be stored >
  • –file-size = < Size of the Virtual Machine, in my case it is 20GB >
  • –nonsparse = < Allocate the whole storage while creating>
  • –graphics = < Specify the graphical tool for interactive installation, in above example I am using spice >
  • –vcpu = < Number of virtual CPU for the Machine >
  • –ram = < RAM size for the virtual Machine >
  • –cdrom = < Virtual CD ROM which specify the installation media like ISO file >
  • –network = < it is used to specify which network we will use for the virtual machine, in this example I am bridge interface>
  • –os-type = < Operating system type like linux and window>
  • –os-variant= <KVM maintains the OS variants like ‘fedora18′, ‘rhel6’ and ‘winxp’ , this option is optional and if you not sure about OS variant you can mentioned it as generic>

Once the Installation is completed we can access the Virtual Machine console from ‘virt-manager‘ as shown below.


That’s it, basic installation and configuration of KVM hypervisor is completed.

29 Responses

  1. Julian says:

    Hey, who did this tutorial? Awesome!

  2. Makis says:

    congrats! Very helpful tutorial.
    On the first step you can also add below of : lsmod | grep kvm. That if this command returns nothing execute those commands:
    modprobe kvm
    modprobe kvm-intel or kvm-amd(depends on your cpu)
    In order to load the module.

  3. joe glassy says:

    Thanks for this tutorial! On CentOS 7 I believe it’s quite a similar process, however, I think that the default /etc/qemu.conf has to be edited, e.g. un-comment out (enable) user=root and group=root, or substitute other desired accounts. Then restart libvirtd, run status on it, and it will look much better.

  4. S.R.PrasannaKumar says:

    Excellent One.

  5. joe says:

    virt-manager failed to start with “can not open display”

  6. Brad Goodman says:

    This is awesome. I have been using it as my “gold standard” guide for getting VMs running on a CentOS 7 host. In fact, I don’t even use the GUI to get stuff going – I use the “Creating from a Command Line” as described above, then I do a “virsh console” to get the text console of the VM (as it boots from the install media), and do a “text” install (add “text” to the kernel/boot command line). No GUI ever used (just the way God intended Unix to be)!

    The only part that I thought was a bit confusing was the network and bridge setup. The way it works is – the address info all gets set in the BRIDGE device – all your “real” device does is kind of “point” to the bridge.

  7. Mohamed says:

    I am runing centos on virtualbox VM on windows
    I have configured paravirtualization on virtualbox but always I have null putput on running this

    [[email protected] ~]# grep -E ‘(vmx|svm)’ /proc/cpuinfo

  8. Hi Mohamed,

    You need to enable nested virtualization in your virtualBox

  9. JuanJo says:

    Thanks for the tutorial, very well explained

  10. Steven says:

    What is best backup software to backup virtual machine reside inside the KVM hypervisor online (not offline)?

    Eg. Veeam is best for vmware and hyperV, but do not support KVM.

  11. Randy MacFarland says:

    I don’t get X running when entering the command above. When I reboot I get a license prompt which I except but then it just fails to the shell

  12. Roger Gardner says:

    Hello, I have RHEL 7.3 installed and can not attach a CD/DVD or boot from one. I keep getting: Driver ‘host:cdrom’ is not whitelisted.
    I have found that alot of People have this Problem, but never found a solution. Can anyone here help.

  13. Ming says:

    Hi , it’s a very good introduction. But I don’t understand why it’s necessary to manually setup a bridge in step2.
    This bridge is used as a physical network interface. I still have to create a ‘virtual network bridge. eg. virbr1’ with or without this one, and attached to the physical interface.

  14. Prasad says:

    Superb Document

  15. Gilus says:

    Hi, i follow the instruction you give in the tuto, but i have error when i launch my VM.
    g-invoke-error-quark: Could not locate spice_gtk_session_get: ‘spice_gtk_session_get’: /lib64/ undefined symbol: spice_gtk_session_get (1)
    After search on google, i saw this, but if i try to install gir1.2-spice-client-gtk-3.0, it tell me no packets available.
    I’m on Centos 7

  16. Tom says:

    How about libguestfs-tools?

    yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils libguestfs-tools

  17. BazzieB says:

    Hi There

    Awesome guide. I just have a slight problem when I create the bridge adapter. I do everything as you have it but when I systmectl restart network i loose connectivity to my server. I cant even ping it afterwards. I have to go to the server and delete the bridge adapter and then reboot. Any suggestions?

    Kind Regards

  18. Don Cross says:

    I was able to create everything per your instruction but I realized I can’t ssh into the host machine. Upon checking the ip address, the was no IP for the host adapter but IP for the bridge. Now the question is if I want to ssh into the host server what do I do. Thanks

  19. Jake S says:

    I’m doing something stupid, I know it. Everything works up to the last frame – “centos_01 login:” I have no login, how do I create a root user and/or a regular user?

  20. adinovic says:

    when running virt-manager, in case of : ImportError: No module named ‘requests.packages.urllib3’ , i did the following :
    pip uninstall requests
    pip uninstall urllib3
    yum remove python-urllib3
    yum remove python-requests

    and then reinstall virt-manager
    yum install virt-manager virt-install virt-viewer

  21. Thiago Queiroz says:

    This tutorial no longer works, I tried to follow the steps religiously 2 times, and had to format my server because I lost remote SSH access when setting up the bridged network.

    • Pradeep Kumar says:

      Hi Thiago,

      Reason for losing the connectivity might be of network manager. It seems like Network Manager service was enabled on your system and to make network changes into the effect you might have restarted the network service. So to avoid these conditions either use Network Manager or stop and disable the Network Manager service and then restart network service.

      I have modified the article as well.

  22. shakti says:

    A loopback is generating when I am configuring bridge

  23. Hemant says:

    This is a superb tutorial. Love it.

  24. dz says:

    Hi.. i didn’t use default virbr0(NAT)… but i create bridge br0 that mapping with enp0s3 interface and VM host able to access internet and lan. When I create guest VM and attach to br0, the vm can only ping to host VM and physical host but not able to ping gw router and cannot access internet. What could be wrong here. Please advise. Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest