CONFIGURING AND USING KVM-QEMU

2012-02-28

KVM Qemu

I was tired of Vmware Server's sloooooow web interface that only works half of the time.
I just couldn't take it anymore. So I started looking for other virtualization solutions. I found KVM.
KVM/QEmu is, by far, easier to use than VMWARE Server. The thing I like
about qemu is that there is no virtual machine files. You only create a virtual disk file but
the machine itself is built from the command line when invoking qemu. That means you have to "rebuild"
the machine every time you reload it. It looks painful but you just have to save your command in a script and invoke it.
So it comes down to say that what a shell script is to qemu what a VMX file is to vmware. Don't ask me why,
but this is a strong point for me.

Installing and preparing KVM Qemu

make network bridge script. will need to create a script that will need to be run after every reboot (put in rc.local):
#load tun driver and create a TAP interface
modprobe tun
tunctl -t tap0
# bring eth0 down, we will set it as promiscuous and it will be part of a bridge
ifconfig eth0 down
brctl addbr br0
ifconfig eth0 0.0.0.0 promisc up
ifconfig tap0 0.0.0.0 promisc up
# set the IP address of the bridge interface. This is the interface that we will use from now on. So use
# an IP address on your LAN. This is the address of the host computer, not the guest.
ifconfig br0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 up
# add tap0 and eth0 as members of the bridge and bring it up.
brctl stp br0 off
brctl setfd br0 1
brctl sethello br0 1
brctl addif br0 eth0
brctl addif br0 tap0
# setup default gateway.
route add default gw 192.168.1.1

Note that you will need to run that on every reboot. So you might want to save this is a boot script.

"-vnc :1" : The display will be on VNC port index number 1. Depending on your settings, if your base port is 5900, then the TCP port used in that case will be (5900 + 1).

So you can now use a VNC client to connect to port 5901 on your host to have access to the display. The VM will
boot from the OS install CD you have provided so you will be able to install the OS like you would on a real computer.

You should now have access to your VM through remote desktop or SSH or whatever you configured in that last step.

Managing the VM

You can telnet in the VM console to manage it. use the port you have setup with option "-monitor telnet". To exit
the monitor, use 'ctrl-]' and press 'q'. If you type 'q' without 'ctrl-]', you will kill the VM.

Change CD in cdrom

telnet in management console and: change ide1-cd0 /shared/newimg.iso

Changing specs

Of course, if you want to add more RAM or change other system specs, you can do it from the command line
when invoking qemu.