This guide was produced using Ubuntu Hoary 5.04 and Ubuntu Breezy 5.10, and Ubuntu Dapper 6.06. It's also therefore applicable to Debian. Although most of the commands should work generically across different distributions.
Qemu packages are available in the Debian and Ubunutu repositories for version 0.6.1 or 0.7.0 (and 0.8.0 in Ubuntu Dapper 6.06), depending on what distribution and version you are using. Qemu also has an optional kernel module called KQemu, previously this was not redistributable (it now is) therefore packages for any Linux distribution may not include this module. The advantage of KQemu is much improved emulation performance, the Qemu website states "near native" perfromance, and a better compatibility for guest operating systems (particularly Microsoft WIndows 2000, XP and 2003).
The rest of this page explains how to get Windows XP running under Qemu, but it assumes that you have access to Qemu 0.7.2 or better. Qemu 0.6.1 can run Windows 98 reliably but not Windows 2000 or upward.
If you don't want to build from source then just...
$ sudo apt-get update && sudo apt-get install qemu
...and skip to the Installing Windows XP section.
Building from source with KQemu
If you want the advantages of KQemu then you need to build Qemu from source. These steps were completed with Ubuntu Hoary. First of all remove Qemu if you have previously installed it...
$ sudo apt-get remove qemu
Getting the source
You can either get the current stable version of QEMU from the project home page or you can check it out from the CVS repository. This section deals with compiling the version found on the authors home page rather than CVS simply because it's clearly less likely to change and thus would be more likely to compile first (or 51st) go. Compiling from CVS may be less reliable, however I (AlanPope) have not noticed this myself.
Get the source for Qemu and KQemu.
Note that QEMU was recently updated to 0.9.0, and kqemu has been updated recently, but the version numbers don't match, so the version number below is correct.
$ wget http://fabrice.bellard.free.fr/qemu/qemu-0.9.0.tar.gz $ wget http://fabrice.bellard.free.fr/qemu/kqemu-1.3.0pre11.tar.gz
Extract the Qemu source and merge in KQemu.
$ tar zxvf qemu-0.9.0.tar.gz $ cd qemu-0.9.0 $ tar zxvf ../kqemu-1.3.0pre11.tar.gz
You will need to have available the kernel headers for your running kernel and the same compiler version as was used to compile it. If you compiled your kernel from source, then you will have the headers available, if not might need to install a package that contains them. If you do not know which compiler was used to compile your kernel then the following command will tell you:
This will give you output similar to the following:
Linux version 18.104.22.168 (tony@davros) (gcc version 3.3.6 (Debian 1:3.3.6-7)) #1 Wed Oct 5 23:09:53 BST 2005
In the above example GCC v3.3.6 was used to compile the kernel.
Ensure that you install the linux-headers package that matches both the version and target CPU of your running kernel. The uname -m command will help you determine the version you are currently running. Note also, that under some flavours of Debian (including Debian itself) the exact name of this package will have the kernel version appended.
$ sudo apt-get install build-essential linux-headers-386 libsdl1.2-dev zlib1g-dev checkinstall fakeroot
Note: Some distros such as Ubuntu will (as a result of the above command) supply the linux headers in the form of a .bz2 file in /usr/src. In order for the compile process below to find them you will need uncompress the headers.
$ cd /usr/src tar jxvf linux-headers-$(uname -r)
(You do not need to be root to do this -- see /NonRootBuildEnvironment for more information about that.)
Ubuntu Breezy 5.10 and Debian Sid come with GCC 4.0 by default, but Qemu 0.72 will not compile with GCC 4.0 so we need to install GCC 3.4
$ sudo apt-get install gcc-3.4 g++-3.4
Run the configure script. These steps are slightly different for Hoary and Breezy. For Ubuntu Hoary 5.04, simply run:
If successful that will result in something like this:
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 /home/alan/src/qemu-0.9.0 C compiler gcc Host C compiler gcc make make install install host CPU i386 host big endian no target list i386-user arm-user armeb-user sparc-user ppc-user mips-user mipsel-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu mipsel-softmmu arm-softmmu gprof enabled no profiler no static build no SDL support yes SDL static link no mingw32 support no Adlib support no [[CoreAudio]] support no ALSA support no DSound support no FMOD support no kqemu support yes Documentation yes
For Ubuntu Breezy 5.10 and above (or other GCC4 based systems) where you have the full kernel sources available, run:
$ export CPP=g++-3.4 $ export CC=gcc-3.4
If you have only the kernel headers package, skip down a little to the next configure line. If you have the full kernel source installed in /usr/src..
$ ./configure --prefix=/usr/local --cc=gcc-3.4 --host-cc=gcc-3.4 --kernel-path=/usr/src/linux-source-$(uname -r)/
If successful that will result in something like this:
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 /home/alan/src/qemu-0.9.0 C compiler gcc-3.4 Host C compiler gcc-3.4 make make install install host CPU i386 host big endian no target list i386-user arm-user armeb-user sparc-user ppc-user mips-user mipsel-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu mipsel-softmmu arm-softmmu gprof enabled no profiler no static build no SDL support yes SDL static link no mingw32 support no Adlib support no [[CoreAudio]] support no ALSA support no DSound support no FMOD support no kqemu support yes Documentation yes
If you only have the kernel headers (the package now called linux-headers) you need to tell configure where to find them with:
$ ./configure --prefix=/usr/local --cc=gcc-3.4 --host-cc=gcc-3.4 --kernel-path=/usr/src/linux-headers-$(uname -r)/
Now do the build:
Making a package
Now make the package. Using checkinstall is a great way to install applications because it makes '.deb' packages. This means Qemu will be installed as if it were installed via apt-get or Synaptic. :If anyone knows of a better way to build .deb packages please educate me (MartinWimpress) because package building is something I am still new to.
$ echo "QEMU is a generic processor emulator" > description-pak $ cat /dev/null > kqemu/install.sh
The reason for overwriting install.sh so it is empty is to ensure the package made with checkinstall can install cleanly.
Then we just created the package, and install the resulting .deb file that's produced:
$ sudo checkinstall -y --pkgname=qemu --pkgversion=0.9.0 --pkgrelease=1 --pkglicense=Restricted --pkggroup="Miscellaneous - Text Based" --pkgsource=http://qemu.org/qemu-0.9.0.tar.gz --exclude=kqemu/install.sh
Since this is also a package we ourselves have created, we now have to put the package on "hold" to prevent the other qemu package from being installed, which might conflict with the one we've just created. The /DebianTips page explains how to do this in more detail, but the following should suffice:
$ echo "qemu hold" | sudo dpkg --set-selections
Installing the package
If everything went ok, you can now load the KQemu kernel module with...
$ sudo depmod -a $ sudo modprobe kqemu $ sudo mknod /dev/kqemu c 250 0 $ sudo chmod 666 /dev/kqemu
If modprobe is unable to find the kqemu module, run the following as root:
# mkdir -p /lib/modules/$(uname -r)/misc && cp ~/qemu-0.9.0/kqemu/kqemu.ko /lib/modules/$(uname -r)/misc && depmod -a
before trying modprobe again. This assumes that you have followed the above instructions and installed the source code for qemu in ~/qemu-0.8.0. Please adjust as necessary if not.
Booting and KQemu
You might want to get KQemu loading at boot time too, however some operating systems don't run very well with the KQemu module loaded so you equally may not want to load it automatically, but on demand. Debian systems can use, at boot time, a separate directory that we can place scripts into, that get run at the end of the init sequence (see the /DebianTips page), essentially:
$ sudo mkdir /etc/rc.boot
And create a new file called startqem.sh into the new directory just created. Save it, and run: chmod 755 /etc/rc.boot/startqem.sh
1. Start Qemu with KQemu accelerator /sbin/modprobe kqemu mknod /dev/kqemu c 250 0 # Create the KQEMU device chmod 666 /dev/kqemu # Make it accessible to all users
Alternatively you could add the module "kqemu" to /etc/modules. If you're using a static /dev tree, then the device nodes will persist across reboots anyway. If you're using a dynamic devfs (such as udev) then adding those nodes to the appropriate file will suffice.