RapidFX

KVM on CentOS

4/4/2010



Check if your CPU supports hardware virtualization

COMMAND:
egrep '(vmx|svm)' --color=always /proc/cpuinfo

If you see nothing, then your system does not support KVM.

You want to see output such as:

# egrep '(vmx|svm)' /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat

Install KVM and various utilities

COMMAND:
yum install kvm kmod-kvm qemu libvirt python-virtinst

Reboot the system to enable KVM

Make sure KVM kernel module is loaded after reboot

COMMAND:
lsmod | grep kvm

You want to see:

# lsmod | grep kvm
kvm_intel 86248 0
kvm 223520 2 ksm,kvm_intel

Make sure KVM has been installed

COMMAND:
virsh -c qemu:///system list

You want to see:

# virsh -c qemu:///system list
Id Name    State

You should not see anything in the list, but if Name and State do not show, there is a problem.

Install network bridge apps

COMMAND:
yum install bridge-utils

Create bridge
vi /etc/sysconfig/network-scripts/ifcfg-br0
which should be a new file if no bridging has been setup.
take the info from
vi /etc/sysconfig/network-scripts/ifcfg-eth0
and set ifcfg-br0 as follows:

# Intel Corporation 82574L Gigabit Network Connection
DEVICE=br0
TYPE=Bridge
HWADDR=00:40:38:BB:AC:C5
ONBOOT=yes
IPADDR=xxx.xxx.19.121
GATEWAY=xxx.xxx.19.1
BROADCAST=xxx.xxx.19.255


save and exit.

run: vi /etc/sysconfig/network-scripts/ifcfg-eth0
and set ifcfg-eth0 as follows:

# Intel Corporation 82574L Gigabit Network Connection
DEVICE=eth0
HWADDR=00:40:38:BB:AC:C5
ONBOOT=yes
#IPADDR=xxx.xxx.19.121
#GATEWAY=xxx.xxx.19.1
#BROADCAST=xxx.xxx.19.255
BRIDGE=br0

Save and exit, then restart network

COMMAND:
/etc/init.d/network restart

Check network settings

COMMAND:
ifconfig

You should see br0 at this point.
Make sure the IP and such are what you want.

-------------
Setup iptables rules on host:

COMMAND:
iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
service iptables save
service iptables restart
-------------

Install virt-manager

COMMAND:
yum install virt-manager

KVM BASIC SETUP IS NOW DONE
---------------------------------------

INSTALL GUEST OS
This will install the guest OS from /tmp on the host, and use a .iso
If you install as root, the VM will be located in /root/fbsd8.qcow2
To see what the commands and switches do run: man virt-install

virt-install --connect qemu:///system -n fbsd8 -r 1024 --vcpus=2 -f ~/fbsd8.qcow2 -s 12 -c /tmp/FreeBSD-8.0-RELEASE-i386-disc1.iso --vnc --noautoconsole --os-type=unix --accelerate --network=bridge:br0 --hvm


---------------------------------------------

Manage commands:

---------------------------------------------

check for all running VM:
	virsh -c qemu:///system list

---------------------------------------------

check a specific VM by name:

	virsh domstate winxpsp3
	shut off

	virsh domstate fbsd8
	running

---------------------------------------------

start a VM:

	virsh start fbsd8
	Domain fbsd8 started

---------------------------------------------

stop a VM:

	virsh shutdown fbsd8
	Domain fbsd8 is being shutdown

---------------------------------------------
	
launch VM control panel via ssh -X session to the HOST:
	virt-manager

---------------------------------------------

pause a VM:

	virsh suspend fbsd8

---------------------------------------------

resume a paused VM:

	virsh resume fbsd8

---------------------------------------------