Installing KVM in Centos, Redhat or Fedora

KVM is available in RHEL 5.4. I finally managed to find the time to play around it over the weekend. I don’t think it is as matured as xen but having said that, I do agree with the approach – Kernel virtualisation. Redhat is promoting kvm very hard and you can see it from their website and mailing list. If you are using redhat systems, better upgrade to kvm as xen might be phased out soon.

Unlike xen, I found installing kvm abit of pain…. I am willing to share what I know and this is what this blog is for.

Check your cpu before you start because kvm only supports full virtualisation, ie your /proc/cpuinfo must have either the vmx (intel) or the svm (amd) tag.

Next, I suggest you do a minimal clean centos/rhel/fedora installation. After rebooting, log in as root and add packages as needed. We will start with the kvm package.

yum groupinstall kvm

I didnt install the virtualisation package because it will bring in the xen hypervisor and stuffs – don’t want it for now.

The pain with kvm is that it doesnt come with a network bridge (xen wins!). we will need to add one if you want your virtual machine be in the same network as your physical machine. Assuming my network card is eth1:

cd /etc/sysconfig/network-scripts/
vim ifcfg-eth1

my eth1 config looks like this

# D-Link System Inc RTL8139 Ethernet
DEVICE=eth1
ONBOOT=yes
HWADDR=00:13:46:3a:14:55
BRIDGE=kvmbr0

now we need to create the kvm bridge

vim ifcfg-kvmbr0

my ifcfg-kvmbr0 looks like this:

DEVICE=kvmbr0
TYPE=Bridge
BOOTPROTO=static
GATEWAY=10.1.1.254
IPADDR=10.1.1.201
NETMASK=255.255.255.0
ONBOOT=yes

Its now time to restart the network

service network restart

my routing information looks like this

[root@home network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.1.1.0        0.0.0.0         255.255.255.0   U     0      0        0 kvmbr0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 kvmbr0
0.0.0.0         10.1.1.254      0.0.0.0         UG    0      0        0 kvmbr0

If you have firewall turned on, turn them off for the bridge. In /etc/sysctl.conf, add

net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

reload sysctl and libvirtd and we are ready to go

sysctl -p /etc/sysctl.conf
chkconfig libvirtd on
service libvirtd restart

start the virt-manager gui

virt-manager &

I am lazy to post screen shots. Redhat has done a good job already. Just follow the steps in the
redhat kvm guide. Start from Step 3.

If you have selinux running, remember to read the security guide

If you are using lvm as disk, you need to fix the fcontext. My volume group is named as “vm”. So my selinux command is:

semanage fcontext -a -t virt_image_t "/dev/mapper/vm(.*)?"

That’s it for now. Merry Christmas!!

Like it.? Share it:

Comments are closed.