KVM on CentOS 8

A basic introduction to virtualization on CentOS 8

About 4 years ago, I published a video about using KVM on CentOS 7. Well, CentOS 8 has been out for quite some time, so that video has been updated:

The notes for following along with the video are below.

Desktop Virtualization with KVM

See: https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-virtualization/index.html

Installing KVM Packages

Fedora 22+, probably works on earlier releases

sudo dnf group install @virtualization

CentOS 7

sudo yum group install "Virtualization Host"
sudo yum install virt-manager

CentOS 8

sudo dnf install libvirt virt-manager

Ubuntu 19.10 (Maybe older?)

sudo apt update
sudo apt install libvirt-daemon libvirt-clients

Start/enable the services (may not be necessary):

sudo systemctl enable libvirtd
sudo systemctl start libvirtd

Granting regular (non-root) user access to KVM

The following allows a non-root user access to manage KVM guests

For systems with a libvirt group

This works on at least Ubuntu 19.10, and CentOS 8. Not been tested on other systems.

sudo usermod -aG libvirt $USER

Log out and log back in

For systems w/out a libvirt group:

See: http://www.linuxsysadmintutorials.com/configure-polkit-to-run-virsh-as-a-normal-user/

sudo groupadd virt
sudo usermod -aG virt $USER
sudo mkdir -p /etc/polkit-1/localauthority/50-local.d/

Create file /etc/polkit-1/localauthority/50-local.d/50-org.example.libvirt-access.pkla with contents:

[libvirt Admin Access]

Log out and log back in

GUI Management

Use the app virt-manager to manage your KVM installation through the GUI.

CLI Management

The environment variable LIBVIRT_DEFAULT_URI can be used to specify the default libvirt instance to connect to.

export LIBVIRT_DEFAULT_URI=qemu:///system

Use virt-install to install VMs, use virsh to manage them. I almost never use virt-install but very frequently use virsh.

man virt-install
# List all guests/domains on system, including those that are powered off
virsh list --all
# Turn on a guest
virsh start <domain>
# Shutdown the guest
virsh shutdown <domain>
# Pull the plug
virsh destroy <domain>
# Configure a guest to run on startup
virsh autostart <domain>
man virsh

VirtIO for Windows

In general, the virtio devices (NIC, Storage) provide best performance. The Linux kernel usually has these drivers included. Windows guests won’t.

You’ll need to mount an ISO containing the virtio drivers during Windows guest installation. See: https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html (This also includes the memory balloon drivers).

sudo wget https://fedorapeople.org/groups/virt/virtio-win/virtio-win.repo -O /etc/yum.repos.d/virtio-win.repo
sudo dnf install virtio-win
# or
sudo yum install virtio-win

During installation, mount the iso /usr/share/virtio-win/virtio-win.iso and load the viostor, netkvm, and balloon drivers.