Cent 7 - KVM

Install Cent 7 minimal as virtualised host with all options, enable EPEL repo and then update:

yum install epel-release
yum update

Install extras and start/enable required daemons:

yum install wget vim qemu-kvm libvirt libvirt-python libguestfs-tools virt-install policycoreutils-python
systemctl enable libvirtd && systemctl start libvirtd

Add the fedora virtIO RPM for paravirtualisation with Windows and auto download latest iso to /usr/share/virtio-win:

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

Change hostname:

vim /etc/hostname

Get list of partitions:

fdisk -l

Delete the default home partition cent makes:

umount /dev/mapper/[ HOME PART NAME ]
lvremove /dev/mapper/[ HOME PART NAME ]
lvextend -l +100%FREE -r /dev/mapper/[ ROOT PART NAME ]

Remove the following entry in /etc/fstab:

/dev/mapper/[ HOME PART NAME ] /home xfs defaults 0 0

Create a bridge named ‘br0’:

vim /etc/sysconfig/network-scripts/ifcfg-br0

Find out name of current ethernet adapter eg ‘enp3s0’:

ip addr

Add the bridge to the bottom line of the ethernet adapter file and optionally set IP:

vim /etc/sysconfig/network-scripts/ifcfg-[NAME OF ETH]

Enable network forwarding:

vim /etc/sysctl.conf
net.ipv4.ip_forward = 1

Read the above file to modify kernel parameters used at boot time:

sysctl -p /etc/sysctl.conf

Restart NetworkManager so the bridge gets an IP address:

systemctl restart NetworkManager

Open ports ready for VNC or SPICE:

firewall-cmd --zone=public --permanent --add-port=5900/tcp
firewall-cmd --reload

Create directory:

mkdir /vmi

Add a custom rule to global SELinux policy:

semanage fcontext --add -t virt_image_t '/vmi(/.*)?'  

Check it’s been added to global policy correctly:

semanage fcontext -l | grep virt_image_t

Apply the context required to the VM directory, it’s read from the custom rule we added to the global policy:

restorecon -R -v /vmi

Verify policy applied correctly:

ls -lashZ /

Virsh commands:

virsh list --all List all VMs
virsh edit [ ] Edit XML
virsh start [ ] Start
virsh shutdown [ ] Shutdown
virsh destroy [ ] Force shutdown
virsh undefine [ ] Delete
virsh pool-list --all List all (storage) pools
virsh pool-destroy [ ] Delete pool
virsh create /vmi/template.XML Create VM from template XML

An example config:

virt-install \
–name=win7 \
–cpu Nehalem \
–vcpus sockets=2,cores=1,threads=1, \
–ram=2048 \
–os-type=windows \
–os-variant=win7 \
–connect qemu:///system \a
–graphics spice,listen=,password=1 \
–video qxl \
–disk path=/win7u64.iso,device=cdrom \
–disk path=/usr/share/virtio-win/virtio-win.iso,device=cdrom \
–disk path=/vmi/win7.qcow2,size=35,format=qcow2,bus=virtio,cache=writeback \
–network=bridge:br0,model=virtio \
–autostart \

To enable two monitors using QXL in conjunction with a SPICE viewer:

   <model type='qxl'>
   <model type='qxl'>