How to setup KVM host and manage guest operation systems

This note provides steps how to install KVM and manage Guest OS with virsh.

Install KVM

yum -y install qemu-kvm libvirt virt-install bridge-utils bind-utils virt-manager wget net-tools virt-viewer genisoimage epel-release

Install Guest OS from installer iso image
virt-install --name VM-1 --ram 4096 --disk path=/testvm/VM-1.qcow2,size=40 --vcpus 2 --os-type linux --os-variant rhel6 --network bridge=br0 --graphics none --console pty,target_type=serial --cdrom /iso/CentOS-6.8-x86_64-bin-DVD1.iso --force
Default directory for intalled VM
Dump VM config into xml
virsh dumpxml VM-1 > VM-1.xml

Useful operation commands

Create and start VM
virsh define VM-1.xml
virsh start VM-1
Shutdown VM
virsh shutdown VM-1
Poweroff VM
virsh destroy VM-1
Remove from VM list
virsh undefine VM-1
Resize VM disk size
qemu-img resize VM-1.img +60GB