How to Install KVM on RHEL 7

Install required packages

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

Enable the KVM service

1
# systemctl enable libvirtd && systemctl start libvirtd

Check if your processor supports full virtualization

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

or

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

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

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

Validate the configuration

1
# virt-host-validate

Configure network

1
# systemctl stop NetworkManager && systemctl disable NetworkManager
1
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
1
2
3
4
5
DEVICE="eth0"
TTPE="Ethernet"
BOOTPRO="static"
ONBOOT="yes"
BRIDGE="br0"
1
# vi /etc/sysconfig/network-scripts/ifcfg-br0
1
2
3
4
5
6
7
8
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"
1
# systemctl restart network

Disable firewall

1
# systemctl disable firewalld && systemctl stop firewalld

Disable selinux

1
# vi /etc/sysconfig/selinux
1
SELINUX=disabled

Enable routing

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

Create the filesystem for the pool

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

Delete and recreate the pool

1
2
3
4
5
6
7
# 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