Qemu with kqemu kernel module support

From openSUSE


This HOWTO explains how to obtain and start kqemu.
The qemu is a processor emulator that is used to run an x86 Linux Kernel on x86 Linux.
The kqemu is kernel module that provides acceleration to qemu.


Contents


Why kqemu?

While qemu runs as stand alone application, it is rather slow. With acceleration module it is few times faster which brings speed in acceptable range.


Procedure openSUSE 10.3

Note: The kqemu since version 1.3.0pre10 it is under the GPL (version 2), and it is included in distribution now.

Setup

  • Install qemu and kqemu, using YaST or zypper.
  • Load acceleration module:
sudo modprobe kqemu

The sudo will ask you for a root password. Give it, and module will be loaded.

Troubleshooting

Mouse problem

If your mouse stay in a corner of the screen (window), run:

export SDL_VIDEO_X11_DGAMOUSE=0

before you start qemu.


Procedure for earlier versions

Note: The kqemu was not included in earlier versions of openSUSE/SUSE Linux.

openSUSE 10.2

The default version of GCC provided by openSUSE 10.2 compiles kqemu just fine. Just follow these steps:

Step 0:

  • Install the default version of QEMU from yast,smart,yum or however you manage your packages. Such as qemu-0.8.2-34.2.rpm

Step 1:

wget -c http://fabrice.bellard.free.fr/qemu/kqemu-1.3.0pre11.tar.gz
tar -zxvf kqemu-1.3.0pre11.tar.gz

Step 2:

cd kqemu-1.3.0pre11
./configure --prefix=/usr/local --enable-adlib \
--target-list="i386-user arm-user armeb-user sparc-user ppc-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu"

Step 3:

make
sudo make install

Step 4:

sudo /sbin/modprobe kqemu major=0

The biggest drawback to not having an rpm for KQEMU for openSUSE 10.2 is the fact that each kernel upgrade requires the recompilation of the module. The steps for recompilation are as follows:

Step 0:

cd kqemu-1.3.0pre11
make clean

Step 1:

 ./configure --prefix=/usr/local --enable-adlib \
--target-list="i386-user arm-user armeb-user sparc-user ppc-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu"

Step 2:

make
sudo make install

Step 3:

sudo /sbin/modprobe kqemu major=0

SUSE Linux 10.1

  • Just get the qemu rpm from one of your YaST repositories. This should work fine in most cases.
  • Alas, the QEMU Accelerator Module does not work from that. You will have to compile it yourself. Be sure it's version is compatible to that of your qemu rpm.
  • Firstly, get yourself the GCC-3.3.6 as described for SuSE Linux 10.0
  • Now commence with the QEMU Accelerator Module as described above for SuSE Linux 10.2
    make
    make install
  • You should be done now. Make sure that /dev/kqemu is set up.

SUSE Linux 10.0

The kqemu is not on the SUSE 10.0, distribution because of it's license.

GCC-3.3.6

Qemu doesn't compile with the default GCC provided by SUSE 10.0. You need to get gcc-3.3.6 and compile it.


This is true, but I do recommend to use the fixed version of qemu instead, which comes with SUSE Linux and got compiled with the official compiler. It can get downloaded here: http://download.opensuse.org/distribution/SL-10.0-OSS/inst-source/suse/i586/qemu-0.7.1-4.i586.rpm

AdrianSuSE 03:21, 25 Oct 2005 (MDT)

The fixed version of qemu that comes with SuSE Linux does not include the kqemu kernel module. It doesn't seem possible to use the kqemu sources with the source RPM provided by SuSE to build the module with the official compiler.

israelpattison 09:34, 08 Nov 2005 (EST)

Getting GCC-3.3.6

Get gcc-core from [1] or any other mirror from GCC Mirrors Page

Compiling GCC-3.3.6

Untar the source then configure with:
./configure --prefix=/opt/gcc33 --program-suffix=-3.3
WARNING: Do NOT configure it with the default prefix! It is recommended to compile it with this prefix else you can damage your system!
Now compile it with make bootstrap and after that install it with make install.

qemu and kqemu

Getting qemu and kqemu

Get qemu and kqemu from [2].

Compiling qemu and kqemu

Unpack qemu then change directory to the qemu directory. Here untar the kqemu archive. Now, let's configure it:
./configure --help will show you all options available.
Now let's discuss about what options we need. We need to specify which compiler to use and we will do this using --cc=/opt/gcc33/bin/gcc-3.3. We also need Adlib emulation: --enable-adlib. If you want full support you can configure it using the following command:
./configure --prefix=/usr/local --cc=/opt/gcc33/bin/gcc-3.3 --enable-adlib --target-list="i386-user arm-user armeb-user sparc-user ppc-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu"<

I have done as directed and 'make' is going along fine until it reaches module usb-linux.c of qemu-0.9.0. This module has an include for C header /usr/include/linux/usbdevice_fs.h. This header has syntax errors which cause the make to bomb out


Anybody know how to overcome this please?

Add the following line:

'#define __user'

to the file 'usb-linux.c' before the line

'#include <linux/usbdevice_fs.h>'


Thank You Very much - Peter Doyle

Installing qemu and kqemu

After qemu has been configured you need to run:
make
make install

Once qemu and kqemu finish installing you still need to load the kqemu module in order to use it. Enter:
modprobe kqemu major=0
To verify that kqemu is loaded enter:
lsmod | grep kqemu
You should get a response back.

Verify the existence of /dev/kqemu. Enter:
ls -l /dev/kqemu
. You should get
crw-rw---- 1 root root 10, 62 2006-01-26 15:23 /dev/kqemu

If you want to use kqemu as normal user you must set (as root) read-write permissions to /dev/kqemu. To do that :
1. Become root with the command su
2. Enter:chmod a+rw /dev/kqemu

Now if you enter ls -l /dev/kqemu you should get
crw-rw-rw- 1 root root 10, 62 2006-01-26 15:23 /dev/kqemu

Verifying kqemu acceleration

Once you have kqemu acceleration installed you may want to verify that qemu is actually using it. Using the instructions[3] to start using qemu. Inside the qemu window hold down Ctrl+Alt and press 2. In the terminal that is now visible type:
info kqemu
You should get the response kqemu is enabled
If you did not then kqemu acceleration is not working. To return back to the normal qemu screen simply hold down Ctrl+Alt and press 1.

Last words

If you feel there's something wrong in this article or there's more to say about qemu and kqemu feel free to make your additions/corrections.

Not working as easily as described

After checking the QEMU forums http://qemu.dad-answers.com/search.php?mode=results and online, it seems that there are many people having problems following these directions and getting KQEMU to work.

 Is it connected to 2.6.13+ kernels? 
 Is there a step people are missing with regards to the gcc3.3.6 download/installation?
 For me it worked as easily as described. Can someone give me some more details about what's not working?
 What version of SUSE are you using? What error do you get when you compile gcc? What about when 
 compiling qemu and kqemu? I didn't use it for a long time and after re-reading this I think I forgot 
 to mention that you need the kernel-sources package installed as well.

What has been people's success rates with getting KQEMU to work?


[1]ftp://gd.tuwien.ac.at/gnu/gcc/releases/gcc-3.3.6/gcc-core-3.3.6.tar.bz2
[2]http://fabrice.bellard.free.fr/qemu/download.html
[3] [1]


I have experienced problems during the described compilation of gcc-3.3.6 . So I have searched the Internet and found some pre-compiled packages of gcc 3.4 for SuSE. You can found them here: http://linux.mathematik.tu-darmstadt.de/pub/linux/distributions/suse/ftp.suse.com/people/kukuk/sles9/gcc34/sles9-x86_64/ (32-bit here: http://linux.mathematik.tu-darmstadt.de/pub/linux/distributions/suse/ftp.suse.com/people/kukuk/sles9/gcc34/sles9-i386/) I have installed only one package: gcc34-3.4.3_16-0.1.x86_64.rpm After you have installed it, you can proceed with the installation of qemu an kqemu as described above. One thing you must change is --cc=/usr/bin/gcc34 when running the configure script of qemu.

--Denys-S 04:24, 29 Jan 2006 (MST)


Installation of gcc-3.3.6 went smoothly as you described it. The only problem so far was with configure. The installation requested the SDL package.I had SDL installed but not SDL-devel. Then the installation ran without problems.

reige 21 Feb 2006

One trick I've found (and qemu will tell you about it), is that you may need to increase the amount of shared memory (/dev/shm) if you want to do something serious. Just follow the instructions you get in the error message. Not had a great (ie any) luck with the ppc target system. The x86 target on an x86 works well given the instructions above. I use gcc-3.4.6 instead of 3.3.6 and that works smoothly too.

-- StaffanTj 15:15, 29 July 2007 (PST)


I had to do the following additional steps to be succesful

cd /usr/src/linux
make cloneconfig
make modules_prepare
cp /boot/symvers-2.6.*-default.gz /usr/src/linux
mv symvers-2.6.*-default.gz Module.symvers.gz
gunzip /usr/src/linux/Module.symvers.gz
make modules_prepare
  • After installing qemu I also had to install kqemu:
cd kqemu* #(from the qemu-directory)
./configure
make
make install
  • "modprobe kqemu major=0" must be done from the kqemu-directory
  • By the way: Windows 95, 98 (and maybe Windows ME) is still not stable with kqemu (this is at least true at with all versions of kqemu younger than 22.03.06, cvs-versions included). So if you want to benefit from kqemu in order to run Windows you need Windows 2000 or newer.--Niwi-hh 11:13, 21 March 2006 (UTC)

Compiling qemu worked only after reinstalling default kernel:

Thanks for all your hints. I updated Suse 10.0 and compilation didn't work. After reinstalling default kernel and all those above mentioned packages everything worked fine. There seems to be a bug in qemu when then kernel version is searched. Before compiling again I also removed all old entries I found searching for qemu.

Mouse Cursor Not Working - try this solution

Bookiboo 23:20 06 August 2006 (UTC)

I had problems where the mouse would stick at the bottom right-hand corner, becoming unusable. A solution to this from http://wiki.clug.org.za/wiki/QEMU_mouse_not_working

is before you run qemu, type

export SDL_VIDEO_X11_DGAMOUSE=0

in a terminal.