Saturday, October 13, 2012

Quick Setup KVM aka Kernel-based Virtual Machine

Well, I thought this was something difficult, but trust me its not brain twister to setup the virtual machines using KVM.

Note: This tutorial assumes you understand the basics of linux and aware of the commands usage.

Ok here is how I setup the same.

1. Install CentOS 6  ( minimal Installation )
2. Turn of selinux

# vi /etc/selinux/config

make the following change.

SELINUX=disabled 
Now reboot your machine to have this applied.

3. Update the system using yum

4. Install packages for Virtualization to work.

# yum install -y openssh-server openssh-client qemu-kvm  libvirt bridge-utils virt-manager.x86_64  virt-top.x86_64 screen

5. Lets setup the network now. For the kvm to work, we will need to setup bridge network. The following is the configuration options.


[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="no"
ONBOOT=yes
HWADDR=00:01:6C:53:82:72
BRIDGE="br0"
[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0"
NM_CONTROLLED="no"
ONBOOT=yes
HWADDR=00:01:6C:53:82:72
TYPE=Bridge
IPADDR=192.168.1.10
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8


4. Save the settings and open a screen to restart the network.

# screen -S network
# /etc/init.d/network restart
5. Now you should see the bridge network up and running.

6. Start libvirtd

# /etc/init.d/libvirtd start

Oops. it did not start for me :D here's what was missing

#  yum -y install avahi

Now libvirtd will start..

7. Copy an ISO to your home directory so that we can use this for creating Virtual Machines, we will be using centos here.

8. Create your VMs now

# virt-install --name=server_name --ram=512 --arch=x86_64 --vcpus=2 --location=/home/packages/CentOS-6.0-x86_64-bin-DVD1.iso  --os-type=linux --os-variant=rhel6 --file /home/images/server.img  --nonsparse --nographics -s15 --extra-args='console=tty0 console=ttyS0,115200n8' --prompt
9. Use Man pages for exact options.

Hope this helps :)