Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Linux / Install and Configure KVM Hypervisor on CentOS/RHEL

May 10, 2023 CentOSKVMLinuxRHELVirtualization

Install and Configure KVM Hypervisor on CentOS/RHEL

In this article we’ll look on how to install and configure the KVM hypervisor on a server running Linux RHEL or CentOS. We will show how to create a virtual machine in KVM, change its settings and install a guest operation system. We will also describe some typical commands to manage a VM.

KVM (Kernel-based Virtual Machine) is a Linux hypervisor that uses Intel VT- or AMD SVM  hardware virtualization technologies. Using KVM, you can create isolated virtual machines with their own virtual hardware: network adapters, disks, graphic cards or other devices. You can install any guest OS on a virtual machine (not only Linux).

Contents:
  • How to Install KVM on CentOS/RHEL?
  • Create and Configure Bridge Networking for KVM
  • Creating Virtual Machines in KVM
  • How to Connect to a KVM VM Using VNC and Install an OS?

How to Install KVM on CentOS/RHEL?

When you configure KVM on your server, you should start with a CPU check. You must make sure if the CPU installed on your host supports hardware virtualization. Run the following command in your server console:

# cat /proc/cpuinfo | egrep "(vmx|svm)"

If your processor supports VT-x, you will see an output like this:

linux proc cpuinfo checking vtx virtualization suport

If the command has returned nothing, but you know that your CPU supports virtualization, make sure that this option is not disabled in the server BIOS. Look for Intel Virtualization Technology or SVM MODE options.

My server supports the VT-x and it is enabled, so we can install the necessary packages on CentOS/RHEL using yum/dnf:

# yum install libvirt libvirt-python libguestfs-tools qemu-kvm virt-install –y

  • qemu-kvm – the KVM hypervisor
  • libvirt – virtualization management libraries
  • virt-install – CLI tools to manage KVM virtual machines

A lot of packages will be installed on your Linux server. Make sure that no errors occur during the installation.

Then add the libvirtd service to startup and run it:

# systemctl enable libvirtd
# systemctl start libvirtd

run libvirtd kvm daemon on linux centos and rhel

Make sure that kvm_intel and kvm kernel modules have been loaded:

# lsmod | grep kvm

kvm_intel 188688 0
kvm 636931 1 kvm_intel
irqbypass 13503 1 kvm

If the command returns nothing, restart your host and check again.

Create and Configure Bridge Networking for KVM

Then create directories to store virtual machine disks and ISO images in:

# mkdir -p /vz/{disk,iso}

In order your virtual machines have the Internet access, you must configure network using bridge. To do it, you will need the bridge-utils. Make sure if it is installed on your Linux host using this command:

# rpm -qa | grep bridge-utils

Install it if needed:

# yum install bridge-utils -y

After installing the package, the virbr0 network interface appeared in the operating system:

# ip a

configuring bridge networking for kvm

To create a bridge, you must set up the configuration file of your server network interface:

# cp /etc/sysconfig/network-scripts/ifcfg-enp1s0f0 /etc/sysconfig/network-scripts/ifcfg-enp1s0f0_bak – back up the file
# nano /etc/sysconfig/network-scripts/ifcfg-enp1s0f0 — open it to edit

Delete the file contents and replace it with the following:

DEVICE="enp1s0f0"
ONBOOT="yes"
BRIDGE=br0

In your case, the interface name may be different (get it using the ip a command).

Then create a file:

# nano /etc/sysconfig/network-scripts/ifcfg-br0
containing the following config:

DEVICE="br0"
TYPE=BRIDGE
ONBOOT=yes
BOOTPROTO=static
IPADDR="IP_address_of_the_server"
NETMASK="255.255.255.0"
GATEWAY="Default_gateway"
DNS1="8.8.8.8"
DNS2="8.8.4.4"

You must specify your server IP address and default gateway. After you have edited the network interface configuration file, restart the network:

# service network restart

If after network restart you cannot access your server, try to restart the host as well. Sometimes it is necessary to configure bridge correctly.

To view the bridge state, use this command:

# brctl show

bridge name bridge id STP enabled interfaces
br0 8000.ac1f6b654321 no enp1s0f0
virbr0 8000.525400abcdef1 yes virbr0-nic

On the last step, configure the network traffic forwarding:

# echo -e "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && sysctl -p

Then restart libvirtd:

# service libvirtd restart

The basic KVM network configuration is over, and you can create a virtual machine.

Creating Virtual Machines in KVM

Prior to creating a virtual machine, I have downloaded a CentOS 8 image from an official mirror to /vz/iso:

# cd /vz/iso && wget http://mirror.imt-systems.com/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-dvd1.iso

To create a new KVM virtual machine, run the following:

virt-install -n test-centosvm \
--noautoconsole \
--network=bridge:br0 \
--ram 2048 --arch=x86_64 \
--vcpus=4 --cpu host --check-cpu \
--disk path=/vz/disk/test-centosvm.img,size=32 \
--cdrom /vz/iso/CentOS-8.3.2011-x86_64-dvd1.iso \
--graphics vnc,listen=IP,password=p@sswdr0w1 \
--os-type linux --os-variant=rhel7 --boot cdrom,hd,menu=on

  • test-centosvm — a VM name
  • noautoconsole – after creating a VM, you won’t connect to the VM console automatically
  • network – a network type (bridge, in my case);
  • ram — the amount of RAM in the VM;
  • vcpus – the number of CPU cores (vCPU configuration for a VM)
  • disk – a virtual disk, path – a path to the disk, size – the size of the disk (you can extend/shrink it later)
  • cdrom – a virtual CDROM, an ISO image to install a gust OS is mounted to;
  • graphics — parameters to connect to a virtual machine using the graphic console. We will use VNC to connect to it, so for listen specify the IP address of the KVM server, on which you have created the VM, and the password to connect to the virtual machine console

To make the VM boot automatically, run:

# virsh autostart test-centosvm

How to Connect to a KVM VM Using VNC and Install an OS?

To connect to a KVM virtual machine using VNC, you need to find out the port it is running on:
# virsh vncdisplay test-centovms

IP:0

0 means that the port number to connect using VNC is 5900. If you get a different value, just add the number the command has returned to 5900.

To connect to servers using VNC, I am using TightVNC. Run it and specify the IP address of your server and the VNC port we got earlier (with a double colon as a separator).

TightVNC connect to KVM VM using VNC protocolo

Click Connect and enter the password you set when creating your KVM VM. If you have done it correctly, the server console appears, in which CentOS installation (or another guest OS, which image you have mounted) is running.

install guest os on kvm virtual machine

If a firewall is enabled on your server, open ports 5900-5910 for VNC in firewalld/iptables (ten ports will be enough). After installation of a guest OS on a virtual machine, start the VM from the server console:

virsh tool - manage kvm VMs

To shut down a KVM virtual machine, use this command:

# virsh shutdown test-centosvm

To display a list of all registered KVM virtual machines:

# virsh list --all

Learn more about managing KVM virtual machines from the server console using virsh (how to add RAM, CPUs, disks or network interfaces). If you prefer a graphical interface, you can use the virt-manager KVM GUI.

Basic KVM host configuration is over, and a virtual machine has been created. You can create any number of virtual machines in KVM, it depends only on your server resources and your needs.

0 comment
1
Facebook Twitter Google + Pinterest
previous post
How to Cleanup, Truncate or Move Log Files in Exchange Server 2013/2016/2019?
next post
Using Windows File Recovery Tool (WINFR) on Windows 10

Related Reading

Reset Root Password in VMware ESXi

October 12, 2023

How to Increase Size of Disk Partition in...

October 5, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

Fixing ‘The Network Path Was Not Found’ 0x80070035...

August 30, 2023

How to Install and Configure Ansible on Linux

August 27, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • How to Configure MariaDB Master-Master/Slave Replication?
  • How to Mount Google Drive or OneDrive in Linux?
  • KVM: How to Expand or Shrink a Virtual Machine Disk Size?
  • Adding VLAN Interface in CentOS/Fedora/RHEL
  • Install and Configure SNMP on RHEL/CentOS/Fedor
  • Configuring High Performance NGINX and PHP-FPM Web Server
  • How to Install and Configure Squid Proxy Server on Linux
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top