Tuesday, February 9, 2010

KVM Installation Tutorial

If you want to install KVM on a linux machine,
first check whether KVM is hardware supported.
sudo egrep '(vmx|svm)'  /proc/cpuinfo
if nothing displays as result, then your machine don't support KVM.




The following is step by step tutorial on KVM installation.

------------------------------------------
On ubuntu:
------------------------------------------

sudo apt-get install kvm libvirt-bin virt-manager

sudo adduser $USERNAME libvirtd

'virt-manager' is a very helpful tool to create

new guests. But you need GUI access to the host

in order to use virt-manager.


Click 'new' and choose install media

from either CD or ISO file, (You can either

insert an installation CD or download an

ISO file from any websites like:

[[http://www.ubuntu.com/GetUbuntu/download]]

I am using 64bit machine, so I choosed
ubuntu-8.04.4-desktop-amd64.iso.

go step by step as instructed in virt-manager.


Note:

If you don't want to use whole

disk partition as the guest image, you can use dd to create

a guest image file.

suppose you want all your guest reside in a 8G img file.

sudo dd if=/dev/zero of=GUEST_NAME.img  bs=1024  count=8192000

and choose the img file during the interactive steps.


-------------------------------------------------------
Configuring Network:
-------------------------------------------------------
Suppose my machine is o22:

sudo vi /etc/network/interfaces

Edit lines as following:

auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 10.128.0.22
netmask 255.255.0.0
broadcast 10.128.255.255
gateway 10.128.0.1
bridge_ports eth0
bridge_fd 0
bridge_maxwait 0
bridge_stp off
sudo /etc/init.d/networking restart


Need to disable dhcdbd from starting on boot:
sudo /etc/init.d/dhcdbd stop
sudo update-rc.d -f dhcdbd remove

You can use virt-manager to start the guests.

For the first time users I will suggest you using

dhcp for the guests since you don't know

which subnet the VNET is in.

Suppose it is a Ubuntu guest:

sudo vi /etc/network/interfaces

Add lines:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
sudo /etc/init.d/networking restart

System allocated default ip address for the guests
is always like: 192.168.122.*



Alternatively you can use command line(virsh)
to manage the guests:

http://www.centos.org/docs/5/html/5.2/Virtualization/chap-Virtualization-Managing_guests_with_virsh.html



You can use '''virt-viewer''' application to connect to a virtual

machine's console. But it requires GUI with the virtual machine.
virt-viewer qemu:///system -c GUEST_NAME



---------------------------------------------------
Fedora
---------------------------------------------------
On Fedora installing KVM is quite similar to Ubuntu,

but much easier steps:

sudo yum groupinstall 'Virtualization'

and run 'virt-manager' click new,

use a install cd or install image(iso)

to install the guests.