introduction
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.
prerequisites
A system running CentOS 7
- or 8
- An account with sudo privileges
- Command line/terminal access
- 8 and CentOS 7
Steps to install KVM on CentOS The steps listed in this tutorial work with CentOS
.
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 resemble the following:
In the output, review the list of indicators. If you find vmx (for Intel processors) or svm (for AMD), your system supports hardware virtualization.
Note: If you have problems installing KVM on an HV-compatible system, check the BIOS to see if HV is enabled. To enable HV, see the host BIOS documentation.
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 the necessary tools for
KVM management: $ sudo yum -y install virt-top libguestfs-tools
Step 3: Verify your
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
the bridge interface
A bridge interface is required to access virtual machines from outside the hypervisor network. To create a bridge interface, first identify the network interfaces connected to your machine
: $ sudo nmcli connection show
The output shows all available network interfaces:
Note the name of the ethernet interface (in this case, it is enp0s3). Delete the connection by typing the following command (replacing the UUID with its value):
$ sudo nmcli connection delete UUID
The system will confirm the removal
of the connection:
Next, make sure you have the necessary information handy:
BRIDGE NAME – Name of
- your new bridge (e.g. “br1”)
- DEVICE NAME – Name of the network device that will serve as the bridge slave (for example, “enp0s3”)
- ADDRESS/SUBNET – IP address and subnet
- 192.168.122.1″)DNS1 and DNS2 – DNS addresses (for example, “8.8.8.8” and “8.8.4.4”
IP
for the connection (for example, “192.168.122.1/24”)GATEWAY – Default gateway address (for example, “
)Now,
using your own values, create a new interface
bridge: $ sudo nmcli connection add type bridge autoconnect yes conname 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 IPV4.ADDRESSES BRIDGE NAME IPV4.ADDRESSES IP/SUBNET ADDRESS ipv4.method manual $ sudo nmcli connection modify BRIDGE NAME ipv4.gateway GATEWAY $ sudo nmcli connection modify BRIDGE NAME ipv4.dns DNS1 +ipv4.dns DNS2
Commands with populated values 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 The output of 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 virtual machine via the command line
on CentOS 8, use the virt-install command
. The following example
shows how to install an Ubuntu 20.04
LTS virtual machine:
The preceding example uses the following command-line arguments, that are required to configure a virtual machine with your preferences:
-name=-file=-
Create virtual machine
through the graphical user
interface If the Linux terminal seems too intimidating, use the virt-manager GUI to create a virtual machine 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 the installation media and proceed to the next step.
4. Specify the path to the ISO or CDROM with the operating system you want to install. The system recognizes the selected operating system.
5. Click Forward to proceed to the next step.
6. In the next step, allocate RAM and CPU resources. When finished, continue.
7. Specify the size of the virtual hard disk and proceed to the next step.
8. In the last step, confirm your options and press Finish to configure the virtual machine.
Conclusion
This article explains the process of setting up KVM on CentOS 8. It provided instructions for installing KVM, configuring a bridge interface, and configuring virtual machines using the GUI or Linux terminal.