How to Install KVM on RHEL 7

Feb 10, 2020

Install required packages

# yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install bridge-utils

Enable the KVM service

# systemctl enable libvirtd && systemctl start libvirtd

Check if your processor supports full virtualization

[root@localhost ~]# lscpu | grep Virtualization
Virtualization:        VT-x

or

# egrep '(vmx|svm)' --color=always /proc/cpuinfo

If so, make sure that KVM modules are loaded (if not check BIOS)

[root@localhost ~]# lsmod | grep kvm
kvm_intel             188688  3
kvm                   636931  1 kvm_intel
irqbypass              13503  5 kvm

Validate the configuration

# virt-host-validate

Configure network

# systemctl stop NetworkManager && systemctl disable NetworkManager
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
TTPE="Ethernet"
BOOTPRO="static"
ONBOOT="yes"
BRIDGE="br0"
# vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0"
TYPE="Bridge"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="192.168.1.35"
PREFIX="24"
GATEWAY="192.168.1.1"
DNS1="192.168.1.1"
# systemctl restart network

Disable firewall

# systemctl disable firewalld && systemctl stop firewalld

Disable selinux

# vi /etc/sysconfig/selinux
SELINUX=disabled

Enable routing

# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
# sysctl -p

Create the filesystem for the pool

# lvcreate -n lv_kvm -L 100G rhel
# mkfs.xfs /dev/rhel/lv_kvm
# mkdir /kvm-pool
# vi /etc/fstab
/dev/mapper/rhel-lv_kvm   /kvm-pool            xfs     defaults        0 0
# mount /kvm-pool

Delete and recreate the pool

# virsh pool-list
# virsh pool-destroy default
# virsh pool-undefine default
# virsh pool-define-as --name default --type dir --target /kvm-pool
# virsh pool-autostart default
# virsh pool-start default
# virsh pool-list
virtualizationlinuxkvmredhat

How to create and install a KVM guest

KVM Cheatsheet

comments powered by Disqus