CentOS KVM Guide


Virtualisation, Kernel Virtual Machine (KVM) using libvirt in CentOS 7. Create and edit a virtual drive image. Create a Windows server guest and add a data drive when offline or running guest.


CPU: Intel(R) Xeon(R) 2 GHz and above
RAM: 32 GB and above


OS: CentOS Linux release 7.4.1708 (Core)


Check KVM capability

egrep '^flags.*(vmx|svm)' /proc/cpuinfo


CPU info

cat /proc/cpuinfo
virsh sys-info


Check for AMD-V extension

modprobe kvm-amd

Check free memory

virsh freecell

Check NUMA and CPU mappings

virsh capabilities


Check cpu mapping for running vm

virsh vcpuinfo <domain name>

Disk/Drive image

Disk image info

qemu-img info <image path>


Only a selected group of formats support consistency checks. These include qcow2, vdi, vhdx, vmdk, and qed.

qemu-img check [-f format] <image path>



Create drive image


Default drive format is Raw

System drives should be non-sparse, data drives can be sparse.

qemu-img create -f raw <image path> 5G


Create new drive (default sparse is ON, drive size will be minimum and will increase when used)

qemu-img create win2k12r2_disk1.raw 32G
qemu-img create win2k12r2_disk1.raw 32G -f raw
qemu-img create win2k12r2_disk1.raw -f raw -o size=32G


For non-sparse image of 10 GB

dd if=/dev/zero of=non-sparse_raw.img bs=1M count=10240


Get disk info

qemu-img info /path/to/disk/image


Convert image format


From raw (sparse) -> raw (non-spase)

cp --sparse=never source.img destination.img


From qcow2 or raw (non-sparse) -> raw (sparse)

qemu-img convert -O raw source.img destination.img


From raw (sparse, non-sparse) -> qcow2

qemu-img convert -O qcow2 source.img destination.img


Resize image


qemu-img resize raw.img +10GB


Add drive to vm (running)


for ide

virsh attach-disk win2012r2 /data/vm/win2012r2_disk1.raw --targetbus virtio --cache none


for virtio

virsh attach-disk win2012r2 /data/vm/win2012r2_disk1.raw --targetbus virtio --cache none


Add drive to vm (shutdown/offline)


Edit guest xml and add


For ide bus

<disk type='file' device='disk'>
  <driver name='qemu' type='raw' cache='none'/>
  <source file='/data/vm/win2012r2_disk1.raw'/>
  <target dev='hdb' bus='ide'/>


For virtio bus

<disk type='file' device='disk'>
  <driver name='qemu' type='raw' cache='none'/>
  <source file='/data/vm/win2012r2_disk1.raw'/>
  <target dev='vdb' bus='virtio'/>


Use the Fedora Virtio-Win repo to install vid, iso and drives 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

Create Guest: Windows Server 2012 R2


virt-install --help
virt install --option=?


Create guest virtual machine

virt-install \
 --name winserver-2012r2 \
 --memory 32768 \
 --disk path=/data/vm/winserver-2012r2/winserver-2012r2_disk0.img,format=raw,size=100,sparse=no,cache=none,bus=virtio \
 --controller scsi,model=virtio-scsi \
 --graphics vnc,password="ansura.net" \
 --vcpus 8,cpuset=auto \
 --cpu host \
 --cdrom /data/iso/win2012r2_oem.iso \
 --network bridge=br0,model=virtio \
 --disk path=/usr/share/virtio-win/virtio-win_servers_amd64.vfd,device=floppy \
 --os-variant win2k12r2 \
 --noautoconsole \



  1. For a NUMA system, use the cpuset=auto
  2. Use option –dry-run to check parameters
  3. Post install mount the virtio-win.iso file and install the balloon driver (its not there in vfd file).


Related Blogs

Posted by Sachin Ranadive | June 19, 2020
Email Server – Enable SpamAssassin site wide with add-ons Razor, Pyzor and DCC
Using SpamAssassin site-wide on a Linux server (CentOS 7.x) with Postfix as the email service. Configuration for advanced usage and add-ons. Effectively blocks 80% emails. Send message contents to spamassassin...
Posted by Sachin Ranadive | June 19, 2020
Windows Server RDS – User Restrictions
Edit Group Policy Computer Configuration\Administrative Templates\Windows Components\Remote Desktop Services\Terminal Server\Device and Resource Redirection   Windows 2012 R2 Computer Configuration\Administrative Templates\Windows Components > Remote Desktop Services >> Remote Desktop Sessions Host...
Posted by Sachin Ranadive | June 19, 2020
Windows Server RDS – User Auditing, login, logout, session disconnects
Get information on user sessions, in command prompt, run either of the following; quser query user query session To shadow/view any of these sessions, connect to the "session id" (/shadow:<session...