maandag 29 oktober 2007

KVM, KQEMU on Debian (Lenny)

On my arch linux I had a virtual machine for using Windows (I use Windows at work).
So I wanted this also on Debian.

I have to say it took me some time to get it done. But in the end it seemed a ./configure misconfigure.

NOTICE that your hardware should support the vanderpool extensions (intel; dont know for amd).
Check this by doing:
cat /proc/cpuinfo | grep vmx

And also be sure that it is enabled in your BIOS!
DO CORRECT all values according to your kernel version etc.


We need kvm and kqemu(kvm enables the virtualization of your hardware).

First we need the kernel sources:
- search the correct package name with:
apt-cache search linux-source
Then, in the results I see the exact package name. Install:
apt-get install linux-source-2.6.22
We also need the sources for kqemu:
apt-cache search kqemu
Install:
apt-get install kqemu-common kqemu-source kvm
Despite what is on the qemu website, I've found that the kqemu accelerator does not compile if you have not at least compiled a kernel in the kernel source directory.
==> http://blog.unixlore.net/2006/03/using-qemu-and-kqemu-under-debian-or.html

Compiling it is enough, you dont need to install it.
cd /usr/src
tar xjf kernel-source-*.bz2
ln -s kernel-source-* linux
cp /boot/config-2.6.22-2 /usr/src/linux/.config
cd /usr/src/linux && make oldconfig && make bzImage

Now we can configure, compile and install kqemu (dont use the symlink "linux" because it points to the kernel headers):
NOTE: In later versions --kernel-path is changed to --kernel-dir
./configure --kernel-path=/usr/src/linux-source-2.6.22

If you don't specify the kernel path you will get this while compiling (make):
ld -r -o ../kqemu-mod-x86_64.o kernel.o x86_64/kernel_asm.o
make[1]: Leaving directory `/usr/src/modules/kqemu/common'
make -C /lib/modules/2.6.22-2-amd64/build M=`pwd` modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.22-2-amd64'
Makefile:275: /usr/src/linux-headers-2.6.22-2-amd64/scripts/Kbuild.include: No such file or directory
make[1]: *** No rule to make target `/usr/src/linux-headers-2.6.22-2-amd64/scripts/Kbuild.include'. Stop.
make[1]: Leaving directory `/usr/src/linux-headers-2.6.22-2-amd64'
make: *** [kqemu.ko] Error 2
Do this to clean and start the correct way to solve this:
make clean
Compile and install:
make
make install # as root user

Now you should be able to load the module:
modprobe kqemu
Also load kvm for your CPU:
modprobe kvm-intel # for Intel CPUs
modprobe kvm-amd # for AMD CPUs
You will need this:
apt-get install libsdl1.2-dev
Do this for auto loading the necessary modules:

cat >> /etc/modules
kqemu
tun
^D

NOTE ^D is CTRL-D

Let's create our virtual disk(a dedicated disk will provide far better performance; also be sure you have alot of memory):
qemu-img create disk.img 10G


Start the Virtual Machine:
qemu-system-x86_64 -m 384 disk.img -cdrom cdimg.img -localtime


-m tells qemu how much memory should be reserved for the VM.
-cdrom determines what your cdrom drive is in the virtual machine.
You could also use /dev/cdrom here but sometimes this gives some problems.
-localtime gives the time on your hostmachine as the time for your VM.


I will later talk about howto setup networking for your virtual machine.

Geen opmerkingen: