Centos 7 and KVM

on Feb. 12, 2015, 11:12 a.m.

So recently, I have started redoing my homelab in Centos 7. First step was to redo my hypervisor in Centos 7 with KVM.

First, install the necessary packages.
yum -y install kvm virt-manager libvirt virt-install qemu-kvm xauth dejavu-lgc-sans-fonts bridge-utils policycoreutils-python

Enable the kernel to do IP forwarding
echo "net.ipv4.ip_forward = 1"|sudo tee /etc/sysctl.d/99-ipforward.conf

Apply the new kernel settings
sysctl -p /etc/sysctl.d/99-ipforward.conf

Start libvirt and set it to start on boot
systemctl start libvirtd
systemctl enable libvirtd

Create a network bridge for the VM's to share
vi /etc/sysconfig/network-scripts/ifcfg-br0


DEVICE="br0"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO="dhcp"
STP="on"
DELAY="0.0"

Tell your network interface to be a slave to the bridge
vi /etc/sysconfig/network-scripts/ifcfg-enp6s0f0


DEVICE="enp3s0"
ONBOOT="yes"
BRIDGE="br0"

Make sure to set your hostname
vi /etc/hostname


hypervisor01.example.com

Start networking to make sure the changes take effect
systemctl restart network

Make the directory to be your VM image folder
mkdir /data

Set the selinux policy on that new folder
semanage fcontext -a -t virt_image_t "/data(/.*)?"
restorecon -R /data

Tell libvirt you want to use the above folder for VMs
virsh pool-destroy default
virsh pool-undefine default
virsh pool-define-as --name default --type dir --target /data
virsh pool-autostart default
virsh pool-build default
virsh pool-start default