Saturday, March 21, 2009

install KVM using QEMU

Insert kvm.ko && (kvm-amd.ko || kvm-intel.ko)

Install qemu-kvm

Creating a vdisk
qemu-img create -f qcow2 vdisk.img 10G

Booting from ISO
qemu-system-x86_64 -hda vdisk.img -cdrom /vmroot/ftp/ubuntu-9.04-desktop-amd64.iso -boot d -m 384 -usbdevice tablet -vnc :1

where -boot [a|c|d|n] boot from floppy (a), hard disk (c), CD-ROM (d), or network (n)
-m is RAM size in MBs

Follow the normal OS installation procedure.

To get the network working
#in file /etc/network/interfaces

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
address 10.128.0.20
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

Creating a qtap device and adding it to the bridge

sudo modprobe tun
sudo tunctl -b -u root -t qtap0
sudo brctl addif br0 qtap0
sudo ifconfig qtap0 up 0.0.0.0 promisc

Now we will have network ready by configuring /etc/network/interfaces in the guest.

Booting up the VM (We will call the first machine as source and the machine where we are going to migrate the VM as destination)
Make sure you have vncserver installed on both source and destination machines.
qemu-system-x86_64 -hda vdisk.img -net nic,macaddr=52:54:00:39:81:49 -net tap,ifname=qtap0,script=no,downscript=no -vnc :1 -usbdevice tablet (On source machine)
vncviewer :5901 (On your desktop)

To migrate the VM
On target side execute following command to start the blank window.
qemu-system-x86_64 -hda vdisk.img -net nic,macaddr=52:54:00:39:81:49 -net tap,ifname=qtap0,script=no,downscript=no -incoming tcp:0:4444 -vnc :1 -usbdevice tablet

press Ctrl+Alt+2 to switch to qemu console and execute following command to migrate the VM.
migrate -d tcp::

After the migration we can connect to 5901 port of the destination host through vncviewer by executing following command on your desktop machine.
vncviewer :5901

No comments:

Post a Comment