QEMU and Ubuntu
From CLUG Wiki
This method should work for both Breezy and Dapper.
Contents |
About QEMU
QEMU is free and one of the better ways to host other operating systems on linux without breaking the bank.
Emulation is slow, there are 2 workarounds:
- kvm for those with recent hardware (SVM or VT extensions)
- Kqemu, the accelerator for executing x86 code on x86. It makes QEMU 3-10 times faster and is thus highly recommended. However it isn't in ubuntu <= feisty+1, so you need to compile from source.
KVM
To tell if you can use kvm, run:
egrep '^flags.*(vmx|svm)' /proc/cpuinfo
If you can, then just
aptitude install kvm
and use kvm instead of qemu.
Compile kqemu
kqemu is now open source. If your ubuntu kernel still doesn't have it installed, simply download and compile it:
- Download kqemu from the Qemu download page
- Extract it somewhere
- Make sure you have linux-headers installed
-
./configure -
make -
sudo make install -
sudo modprobe kqemu -
sudo chown root.admin /dev/kqemu
Now users in the admin group can use kqemu. Unfortunatly you'll have to re-chown it after every reboot & modprobe kqemu.
Old Debian Package method
We are going to build a real debian packages of this.
Make a temporary directory - i.e. /tmp/qemu-build and go there.
Download the dsc, orig.tar.gz, and diff.gz files (these links may be broken, find the latest ones on the bottom of the latest Ubuntu qemu page:
$ mkdir /tmp/qemu; cd /tmp/qemu $ wget -c <insert addresses here>
Install linux headers: (replace amd64-k8 with the linux image type you are using).
# apt-get install linux-headers-amd64-k8
Install the build-dependency packages:
# apt-get install build-essential dpkg-dev devscripts debhelper binutils nasm gcc-3.4 libx11-dev libsdl1.2-dev zlib1g-dev texi2html sharutils libgpmg1-dev fakeroot
on Breezy, also:
# apt-get install cdbs
Extract the sources:
$ dpkg-source -x *.dsc
Move the source files out of the way (important, otherwise dpkg-buildpackage will complain later)
$ mkdir tarballs $ mv qemu_* tarballs
Download kqemu:
$ wget -c <insert kqemu tarball address here>
Change to the qemu-build dir:
$ cd qemu-0.8.0
Extract kqemu:
$ tar -xvzf ../kqemu-1.3.0pre7.tar.gz $ mv kqemu-1.3.0pre7 kqemu
Patch kqemu to make a nice deb
$ cat > debian/patches/99-sr-kqemu-install.patch << EOF #DPATCHLEVEL=1 diff -Naur -x .svn -x CVS qemu-0.7.2.orig/qemu-doc.texi qemu-0.7.2/qemu-doc.texi --- qemu-0.8.0/kqemu/install.sh 2005-02-12 16:36:28.000000000 +0200 +++ qemu-0.8.0-sr/kqemu/install.sh 2006-01-30 21:05:32.000000000 +0200 @@ -15,10 +15,11 @@ mkdir -p "\$kernel_path/misc" cp "\$module" "\$kernel_path/misc" -/sbin/depmod -a +#/sbin/depmod -a # Create the kqemu device. No special priviledge is needed to use kqemu. device="/dev/kqemu" -rm -f \$device +#rm -f \$device +mkdir /dev mknod \$device c 250 0 chmod 666 \$device EOF
Mark the version as being your own:
$ debchange -n
Add a quick description, and change the version number by adding '-yourname1' (note the number at the end) to the version number. i.e.
qemu (0.8.0-1ubuntu1-sr-kqemu1) dapper; urgency=low * Non-maintainer upload. * kqemu edition -- Stefano Rivera <stefanor@lizst.owlsbarn.rivera.za.net> Mon, 30 Jan 2006 21:51:55 +0200 qemu (0.8.0-1ubuntu1) dapper; urgency=low * Resynchronise with Debian etc.
Build the package (unsigned)
$ fakeroot dpkg-buildpackage -uc -us
Wait..... Look out for (about 2 screenfulls into the compile):
Install prefix /usr BIOS directory /usr/share/qemu binary directory /usr/bin Manual directory /usr/share/man ELF interp prefix /usr/gnemul/qemu-%M Source path /tmp/qemu/qemu-0.8.0-3ubuntu1.1-sr C compiler gcc-3.4 Host C compiler gcc make make host CPU x86_64 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 arm-softmmu gprof enabled no static build no SDL support yes SDL static link yes mingw32 support no Adlib support no CoreAudio support no ALSA support no DSound support no FMOD support no kqemu support yes
Install your new qemu: (your filename will probably differ)
# dpkg -i ../qemu_0.8.0-1ubuntu1-kqemu-sr1_amd64.deb
Post Install
This should all be incorporated in the package, but I'm too lazy :-)
Add this to a boot init script:
modprobe kqemu mknod /dev/kqemu c 250 0 chmod 666 /dev/kqemu
Make sure that a normal Ubuntu qemu never installs:
# echo "qemu hold" | dpkg --set-selections
Note that if the kernel version changes, you will need to recompile kqemu.
Old Source Method
When installing from source, one of the dependancies is the SDL library. Ensure that you do install libsdl-dev (apt-get install libsdl-dev), but this is still not correctly probed for by the ./configure script on Ubuntu Breezy. To get it to work, simply comment out the line:
if $cc -o $TMPE `$sdl_config --cflags 2> /dev/null` $TMPC `$sdl_config --libs 2> /dev/null` 2> /dev/null ; then
and the fi that follows a few lines below that.
If you compile with the proprietary kqemu accelerator module, you will need a few additional steps. The other dependencies are zlib1g-dev and of course the kernel headers. You need to edit the configure script and enter the path to your kernel sources. Look for the kernel_path variable and change it to read 'kernel_path="/usr/src/linux-headers-2.6.15-20-686"', where '2.6.15-20-686' in this example is substituted with the output of your 'uname -r' command. On newer distributions, your default compiler may be gcc4 - at the time of writing, qemu had problems with gcc4. If configure fails on that (it will tell you so) then change the cc varilable in configure to read 'cc="gcc-3.4"'
Now run ./configure and make sure you see 'kqemu support yes' in the output.
I had messed around with win4linpro as well prior to using qemu (which incidentally worked much more easily than the commercially available product!). However, I had a kqemu module still lying around which was interfering with my qemu. I was getting the message Could not open '/dev/kqemu' - QEMU acceleration layer not activated even though I had previously typed managed to "modprobe kqemu" without any problems I needed to "rmmod kqemu" and then "insmod /lib/modules/2.6.12-8-386/misc/kqemu.ko" to remove this message.
Installing Win 2k
For your reference this is the command that I used for installing windows 2000 into my QEMU virtual disk:- Make disk image with
qemu-img create myimage.img 1000M
(which gives you a miserly 1GB image) Install win2k with
qemu -hda /path_to_diskimage/myimage.img -cdrom /path_to_iso/windows_2000_pro.iso -win2k-hack -boot d -nics 1 -user-net -m 64 -localtime
(the 64 means the VM will use 64MB of RAM)
Links
Check out http://oui.com.br/n/content.php?article.21 for some more useful information
