CentOS 7 – Setting up KVM for full virtualization on CentOS 7

How to configure WordPress multisite with NGINX

KVM can only support hardware-assisted full virtualization. And there is still work going on in supporting paravirtualization. KVM is a kernel module that only works with the default Linux kernel (we should not install it on the Xen one). KVM creates virtual machines using a personalized version of Qemu for KVM called

Source: http://www.virtualopensystems.com

KVM has many useful features and advantages supported by its hypervisor:

  • Thin provisioning: This is the capacity to allocate flexible storage and manage the available space for the virtual machines
  • Overcommitting: This is the capacity to allocate more CPU and memory power more that the available resource on the physical machine
  • Automatic NUMA balancing: This is an improvement to the application running on the NUMA hardware
  • Disk I/O throttling: This is the capacity to manage limits of the physical system disk input and output requests sent by the virtual machines
  • Virtual CPU hot add capability: This is the capacity to adjust the processing power of the virtual machines without any downtime

Before starting the KVM installation, we need to check some pre-installation steps. First, we check whether the machine CPU can handle the virtualization technology:

$ sudo grep -e '(vmx|svm)' /proc/cpuinfo

To know whether that’s true, we need to see the vmx or svm word highlighted in the command output:

Then, we make sure that the system packages are all updated:

$ sudo yum update

Next, we change the working mode of SELinux to permissive to make sure that it won’t bother the execution of KVM:

$ sudo nano /etc/sysconfig/selinux

Then, consider this line:


Change it to the following:


We can now start the installation. First, we will install the Qemu package to provide a user level for KVM and its disk image manager:

$ sudo yum install qemu-img qemu-kvm 

Then, we need to install the GUI for the virtual machine’s administration, the command-line tools to administrate the virtual environment, the tool that helps create virtual machines from the CLI, and the hypervisor library:

$ sudo yum install virt-manager libvirt libvirt-python libvirt-client xauth dejavu-lgc-sans-fonts

Finally, for CentOS 7, we add the virtualization client, virtualization platform, and virtualization tools:

$ sudo yum groupinstall virtualization-client virtualization-tools virtualization-platform 

With this step done, we can say that we have finished installing the required tools and packages. Now, we go to the configuration part. First, we need to restart the virtualization daemon to make sure that the entire configuration is well set:

$ sudo systemctl restart libvirtd

Then, we check whether it is running well or not:

$ sudo systemctl status libvirtd

We should see this as the output:

Now, we move on to the network configuration. We need to create a bridge interface to allow the guest system to access an external network. To do so, we must enable IP forwarding:

$ sudo echo "net.ipv4.ip_forward = 1"|sudo tee /etc/sysctl.d/99-ipforward.conf

Then, we check whether it is well set:

$ sudo sysctl -p /etc/sysctl.d/99-ipforward.conf

After that, we need to change the network configuration by keeping the original interface as it is, but we will assign its IP address to the bridge:

$ sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0

Next, we add the following line to the end of the file and save it:


Then, we create the bridge interface configuration file:

$ sudo nano /etc/sysconfig/network-scripts/ifcfg-brid0

After that, we put the following code inside the file we just opened for editing, and save it:


After rebooting the system, we can say that the network configuration is well set.

After we complete the KVM installation and configuration, it’s time to start using the host. The first thing we need to do is create a new domain or virtual machine. To do so, using the CLI, we will make use of the virt-install command. First, we need to see the list of templates known to our KVM installation:

$ sudo virt-install --os-variant=list

We need an ISO of the Linux OS to use it for the installation. Then, we can start the setup of a new virtual machine:

$ sudo virt-install  --name=CentOS7guest  --ram=1024  --vcpus=2  --cdrom=./CentOS-7.1-x86_64-minimal.iso --os-type=linux --os-variant=rhel7  --network bridge=brid0 --graphics=spice  --disk path=/var/lib/libvirt/images/CentOS7.dsk,size=10

The options written in the preceding command are as follows:

  • name: This is the name of the virtual machine
  • ram: This is the memory size in MB
  • vcpus: This is the number of virtual CPUs
  • cdrom: This is the location of the ISO image
  • os-type: This is the OS type, such as Linux, Windows, or Unix
  • os-variant: This is the OS variant, such as rhel 6 or Solaris
  • network: This is the network interface and connectivity
  • graphics: This is the guest display settings
  • disk path: This is the location of the disk with a size of 10 GB

Once we have issued the preceding command, virt-install will create a virtual machine and start the virt viewer console for the OS installation.


There is always a graphical mode perform the previous treatment. The graphical tools is called virt-manager found a the system tools.

The following commands are meant for better management of the KVM virtual machines after being deployed:

  • To list the virtual machines running on KVM:
    $ sudo virsh --connect qemu:///system list
  • To get more information about a virtual machine:
    $ sudo virsh dominfo CentOS7guest
  • To stop a running guest machine:
    $ sudo virsh --connect qemu:///system shutdown CentOS7guest
  • To start a virtual machine:
    $ sudo virsh --connect qemu:///system start CentOS7guest
  • To delete a guest machine:
    $ sudo virsh --connect qemu:///system destroy CentOS7guest
    $ sudo virsh --connect qemu:///system undefineCentOS7guest
    $ sudo rm -f /var/lib/libvirt/images/CentOS7guest.img
  • Finally, the code used to automatically start a virtual machine with the host system startup:
    $ sudo virsh --connect qemu:///system autostart CentOS7guest
    $ sudo virsh --connect qemu:///system dominfo CentOS7guest | grep Auto

Source: https://virt-manager.org/

Comments are closed.