Homepage: webng.com/linuxhelp (May 23, 2009)


 Compiling the Kernel Virtual Machine/QEMU 


This appears to be a big improvement over kvm-71. I recommend the upgrade.

A earlier version of this page (for kvm-71) can be found here. Thankfully, the compilation process is now straightforward. Previously, the whole process had been (deliberately) made much more difficult than it need be, so that most would give up and decide that compiling source code was far too hard for them. Of course, there are still no instructions in the source, but doing the usual things, works, which is a huge improvement.

I used a 2.6.28 kernel, but any recent kernel should be fine. Go to your kernel source, run menuconfig:

 cd /usr/src/linux-2.6.28/
 make menuconfig

and check that you have the Virtualization section marked as follows:

[*] Virtualization --->
    --- Virtualization --->
       <M> Kernel-based Virtual Machine (KVM) support
       <M> KVM for Intel processors support
       <M> KVM for AMD processors support
       <M> PCI driver for virtio devices (EXPERIMENTAL)
       <M> Virtio balloon driver (EXPERIMENTAL)


If you need to compile a new kernel, there are instructions here.

Download kvm-86.tar.gz from kvm.qumranet.com.

Move the tar archive to /src and unpack it:

 mv kvm-86.tar.gz /src
 cd /src
 tar -xf kvm-86.tar.gz

To get the code to compile on my Debian 5 Linux system, I needed to install the following development packages (development packages are packages of header files and static libraries): libpci-dev, libsdl1.2-dev, libasound2-dev and a host of other packages dragged in by these three. Now, change to the source directory, run configure, make, and make install, and you are finished.

 cd /src/kvm-86
 ./configure --enable-mixemu \
 ./configure --audio-drv-list=oss,alsa,sdl \
 ./configure --audio-card-list=ac97,es1370,sb16,adlib,cs4231a,gus
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /src/kvm-86
C compiler        gcc
Host C compiler   gcc
ARCH_CFLAGS       -m64
make              make
install           install
host CPU          x86_64
host big endian   no
target list       x86_64-softmmu
tcg debug enabled no
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
-Werror enabled   no
SDL support       yes
SDL static link   yes
curses support    yes
mingw32 support   no
Audio drivers     oss alsa sdl
Extra audio cards ac97 es1370 sb16 adlib cs4231a gus
Mixer emulation   yes
VNC TLS support   no
VNC SASL support  no
kqemu support     no
xen support       no
CPU emulation     yes
brlapi support    no
Documentation     yes
NPTL support      yes
vde support       no
AIO support       yes
IO thread         no
Install blobs     yes
KVM support       yes
fdt support       no
preadv support    no

 make
 make install

The full list of audio drivers is --audio-drv-list=oss,alsa,sdl,esd,pa,fmod but since I did not have the necessary libraries and headers for esd, pa and fmod, I just left them out.

Here are some links to information on the sound systems. The necessary development packages (for a Debian 5 system) have been included in brackets.

ALSA (libasound2-dev)
OSS (see the oss-compat package)
SDL (libsdl1.2-dev)
Open Sound Control (libl0o-dev)
Pulseaudio (libpulse-dev)
ESD (libesd0-dev)
FMOD
CoreAudio

The oss-compat package makes sure that various kernel modules, necessary for ALSA to use OSS, are loaded.

The file /lib/oss-compat/linux which achieves this, reads:

install snd-pcm modprobe --ignore-install snd-pcm $CMDLINE_OPTS \
   && { modprobe --quiet snd-pcm-oss ; : ; }
install snd-mixer modprobe --ignore-install snd-mixer $CMDLINE_OPTS \
   && { modprobe --quiet snd-mixer-oss ; : ; }
install snd-seq modprobe --ignore-install snd-seq $CMDLINE_OPTS \
   && { modprobe --quiet snd-seq-midi ; modprobe --quiet snd-seq-oss ; : ; }

The Debian package information states: This package ensures that OSS support is provided in some way. On Linux, it enables the ALSA compatibility modules. On other kernels where OSS is the default interface, no action is taken. The purpose of this package is for applications that only support OSS to depend on it, hence preventing common "/dev/dsp not found" errors that would confuse unexperienced users.

Although the documentation says otherwise, Qemu has compiled with gcc 4.x for some time now. And KVM has always compiled with gcc 4.x.

To use KVM/QEMU you need to:

1) Load one of the kvm kernel modules:

 /sbin/modprobe kvm-amd   (AMD CPUS)
 /sbin/modprobe kvm-intel   (Intel CPUS)

If you get the error message:

open /dev/kvm: No such file or directory
Could not initialize KVM, will disable KVM support

then you have forgotten to load one of the just mentioned kernel modules.

2) Create an image file:

 qemu-img create vista.img 10G

3) Install the guest operating system (in this case, from an installation CD/DVD):

 qemu-system-x86_64 -boot d vista.img -cdrom /dev/cdrom

4) Run it with the command:

 qemu-system-x86_64 -localtime -soundhw es1370 -usb -usbdevice tablet vista.img

If this command results in the error message:

open /dev/kvm: Permission denied
Could not initialize KVM, will disable KVM support

then you need to make sure that you have a group called kvm, that you are a member of this group, and that the udev files are setup correctly.

 groupadd --system kvm  (adds the group kvm)
 gpasswd -a your_user_name kvm  (adds your_user_name to the group kvm)

For udev to work correctly, you need the line:

KERNEL=="kvm",MODE="0660",GROUP="kvm"

somewhere in the file /etc/udev/rules.d/91-permissions.rules. Note, that various distributions use different numbers in the name of this file. You may need to open a new terminal window, in which to start kvm (so that the changes you have made, are updated).

A quick (insecure & transient) fix, is  chmod 666 /dev/kvm  or, alternatively, just run KVM as root.

You can find more information about QEMU and KVM here:

Qemu/KVM and Vista.
http://fabrice.bellard.free.fr/qemu/
http://kvm.qumranet.com/kvmwiki