KVM (short for Kernel-based Virtual Machine) is a Linux virtualization application that gives users the ability to turn their machine into a hypervisor and run multiple virtual machines in isolated environments.
In this tutorial you will learn how to install KVM on CentOS 8.
Note: A popular alternative is VirtualBox. If you are interested, see how to install VirtualBox on CentOS.
- A system running CentOS 7 or 8
- An account with sudo privileges
- Access to the command line/terminal
Steps to Install KVM on CentOS
The steps listed in this tutorial work with CentOS 8 and CentOS 7.
Step 1: Check if Your System Supports Hardware Virtualization
To see if your system is capable of hardware virtualization (HV), run the following:
$ cat /proc/cpuinfo | egrep "vmx|svm"
The output will look similar to this:
In the output, review the list of flags. If you find either
vmx (for Intel processors) or
svm (for AMD), the system supports hardware virtualization.
Note: If you encounter issues with installing KVM on a system which supports HV, check your BIOS to see if HV is enabled. To enable HV, refer to the documentation for your host’s BIOS.
Step 2: Install KVM
Use the following commands to install KVM on CentOS:
$ sudo yum update
$ sudo yum install @virt
Next, start and enable the libvirtd service:
$ sudo systemctl enable --now libvirtd
Install tools required for KVM management:
$ sudo yum -y install virt-top libguestfs-tools
Step 3: Verify KVM Installation
To confirm that the KVM module is loaded, run:
$ lsmod | grep kvm
The output will contain a list of loaded KVM modules:
Step 4: Configure Bridge Interface
A bridge interface is necessary for accessing VMs from outside of the hypervisor network. To create a bridge interface, first identify the network interfaces attached to your machine:
$ sudo nmcli connection show
The output shows all available network interfaces:
Make note of the name of the ethernet interface (in this case, it is enp0s3). Delete the connection by typing the following command (replacing the UUID with your value):
$ sudo nmcli connection delete UUID
The system will confirm the deletion of the connection:
Next, make sure you have the necessary info at hand:
- BRIDGE NAME – Name for your new bridge (e.g. “br1”)
- DEVICE NAME – Name of the network device which will serve as the bridge slave (e.g. “enp0s3”)
- IP ADDRESS/SUBNET – IP address and subnet for the connection (e.g. “192.168.122.1/24”)
- GATEWAY – Default gateway address (e.g. “192.168.122.1”)
- DNS1 and DNS2 – DNS addresses (e.g. “22.214.171.124” and “126.96.36.199”)
Now, using your own values, create a new bridge interface:
$ sudo nmcli connection add type bridge autoconnect yes con-name BRIDGE NAME ifname BRIDGE NAME
The output confirms the successful addition of the bridge connection:
Make the necessary modifications to the IP address, Gateway and DNS:
$ sudo nmcli connection modify BRIDGE NAME ipv4.addresses IP ADDRESS/SUBNET ipv4.method manual
$ sudo nmcli connection modify BRIDGE NAME ipv4.gateway GATEWAY
$ sudo nmcli connection modify BRIDGE NAME ipv4.dns DNS1 +ipv4.dns DNS2
The commands with values filled in look like this:
Add a bridge slave:
$ sudo nmcli connection add type bridge-slave autoconnect yes con-name DEVICE NAME ifname DEVICE NAME master BRIDGE NAME
nmcli connection show should now look like this:
Activate the bridge with the following command:
$ sudo nmcli connection up BRIDGE NAME
Create Virtual Machine via Command Line
To create a VM via command line in CentOS 8 use the
The following example shows how to install an Ubuntu 20.04 LTS virtual machine:
The above example uses the following command line arguments, which are necessary to set up a virtual machine with your preferences:
|Custom name of the VM|
|Disk file location of the VM|
|Allocated file size of the VM|
|The command which allocates the entire disk|
|Specifies which tool would be used for GUI installation (e.g. spice)|
|Number of virtual CPUs that will be used|
|Amount of RAM allocated|
|Network used for the VM|
|Type of the operating system|
|If you are not sure about the OS variant, type “generic”|
Create Virtual Machine via GUI
If the Linux terminal seems too intimidating, use the virt-manager GUI to create a VM with KVM.
1. First, install virt-manager:
$ sudo yum -y install virt-manager
2. Start virt-manager from the console:
$ sudo virt-manager
3. Open the File menu and select New Virtual Machine. Choose your installation media and proceed to the next step.
4. Specify the path to the ISO or CDROM with the OS you wish to install. The system recognizes the OS you selected.
5. Click Forward to proceed to the next step.
6. In the next step, allocate RAM and CPU resources. When you finish, proceed further.
7. Specify the size of the virtual hard disk and proceed to the next step.
8. In the last step, confirm your choices and press Finish to set up the virtual machine.
This article explained the process of setting up KVM on CentOS 8. It provided instructions for installing KVM, configuring a bridge interface, and setting up virtual machines using the GUI or Linux terminal.