Sunday, August 30, 2009

Virtual machines

I finally tried to give kvm a try on a core 2 duo laptop. And what great fun it is. :D
Following the instruction from the great arch linux wiki, I installed the qemu package. Once I've done that I added myself to the kvm group:

# gpasswd -a abdza kvm

And then I loaded the kvm & kvm-intel module:

# modprobe kvm
# modprobe kvm-intel

To change the new kvm devices to the kvm group I modified the udev rules (had to create the file) at /etc/udev/rules.d/65-kvm.rules:

KERNEL=="kvm", NAME="%k", GROUP="kvm", MODE="0660"

I downloaded some cd iso's to boot install into the "virtual machines". First I tried ubuntu. Once the iso has been downloaded I had to create a virtual machine image with:

# qemu-img create -f qcow2 ubuntu 4194304

Not sure yet what all of that option is for but that basically would create an image named ubuntu with hard disk size of around 4GB. So I had to 'boot' that image with a cd (the iso image downloaded earlier):

# qemu-system-x86_64 --enable-kvm -hda ubuntu -m 512 -cdrom ~/Downloads/ubuntu-9.04-desktop-i386.iso -boot d -vga std -net nic,vlan=1 -net user,vlan=1

That would boot the machine with the cd "inside" it. It would run the live cd and allow you to install ubuntu on it and everthing. Then once it's already installed you can boot it without the cd with:

# qemu-system-x86_64 --enable-kvm -hda ubuntu -m 512 -boot c -vga std -net nic,vlan=1 -net user,vlan=1

Notice that the boot flag has changed to c. Now with the current `-net nic,vlan=1 -net user,vlan1` you will already get normal internet access from inside the virtual machine. But that virtual machine would not be able to access any other machines on your network and no other machines on your network can access your virtual machine neither. Reason being is that it is actually on it's own virtual network provided by qemu. I've read that you need to set up bridge and tun/tap to be able to make it appear on your normal network. Haven't tried it out yet. That would be for the next part.

Just a little side note. Whenever you click inside the virtual machine display, the mouse would be 'captured' by that machine. To release it like normal press ctrl+alt. That would release the mouse. Sometimes you might even like to view the machine full screen, to toggle that just use ctrl+alt+f.

Another small note, 4GB isn't enough to install Fedora 11. For that I created an 8GB virtual machine.

Another small note (my.. getting lots of small notes nowadays.. :P). To use sound in the 'virtual machine', add:

-soundhw all

to the options. Can even view and listen to youtube from a 'virtual' ubuntu.. :P

2 comments:

KageSenshi said...

just what ure trying to install in that fedora to the point that 4GB is not enough ???

i can install fine with less than 2GB disk ..

btw, u may want to look at virt-manager in Fedora :P.

Abdullah Zainul Abidin said...

most probably I didn't do something right when installing fedora because I can't partition the hard disk manually and so just choose use all. But then it would say that it cannot install to a hard disk with less than 3GB (which is strange because it detected it's 4GB). anyhow, using 8GB works.. :D

Haiya ala Solah