This guide will discuss how to properly install qemu, set up windows under qemu emulation, and transfer data onto and off of the windows hard disk image -- all in a completely secure way. We don't want to open up the security vulnerablities of allowing windows unfettered access to the internet. Note that commands that begin with "su" are asking you to enter the root password for your system.
First we want to install qemu including the kqemu kernel module. The kqemu module allows you to run windows with only a marginal 1X to 2X slowdown vs. native. To install kqemu, we need to install from source. Don't be scared of this, it isn't too difficult. Note that kqemu is not released under a free (as in speech) software license. If the morality of this bothers you, do not install kqemu. It is however available at no cost.
Open up a shell/terminal and let's download the source code (about 2 MB)
Certain libraries are necessary to compile qemu. If you are using Debian or a Debian-based GNU/Linux distribution, execute the following command (typed exactly as below on a single line)
Code:
$ su -c "apt-get install libsdl1.2debian libsdl1.2-dev libx11-dev
zlib1g zlib1g-dev texi2html sharutils libgpmg1-dev
kernel-headers-$(uname -r)"
Note that if you are using the debian etch (testing) or sid (unstable) distributions, the word kernel should be replaced with the word linux in the above command. This will be about a 40 MB download (if none of the above packages are yet installed). If you do not have a Debian-based distribution, download and install the above-listed packages for your distribution or install an apt-get package and issue the command above.
Note that debian etch and sid are built using gcc 4.0, which is not yet supported by qemu (as of October 2005). So, if you have etch or sid, you need to download the older 3.4 version of gcc.
Code:
$ su -c "apt-get install gcc-3.4"
Now, we'll configure the source
Code:
$ ./configure --enable-adlib
Again, if you are using etch or sid, this is slightly different
Code:
$ ./configure --enable-adlib --cc=gcc-3.4 --host-cc=gcc-3.4
Make sure "SDL support" and "KQEMU Support" say "yes". Now, compile the code
Go grab a cold beer as this will take 10-15 minutes. When compilation completes, we will install the qemu binaries to proper locations. Log in as root and install the qemu binaries with
Code:
$ su
# make install
Remain as root because the following commands require root priviledges. We want to set up a mount point for the windows hard disk image
Code:
# mkdir /mnt/windows
We also want to set up the file system table to automate mounting. Execute
and add the following two lines at the bottom
Code:
/home/<user name>/images/win2k.img /mnt/windows vfat rw,user,loop,noauto,offset=32256 0 0
tmpfs /dev/shm tmpfs user,size=528M 0 0
where <user name> should be replaced by the name of the user that you generally use on your system. Close and save the file. Note that if you want to give windows access to more ram, you should increase the 528M (it should be 16M more than the amount of ram given to windows). You need to have more than 528M of physical ram to use this setting, otherwise you will need to use a smaller value. We now want to insert the pertinent modules into the Linux kernel (again, the kqemu kernel module is non-free and "taints" the kernel, so if you have moral objections, stop now)
Code:
# modprobe kqemu
# modprobe loop
We also want these modules loaded at every boot, so execute
Code:
# gedit /etc/modules
and add the following lines at the bottom
Close and save the file. The /dev/kqemu device is not correctly created at boot (a bug?), so we need to add this operation to a boot script
Code:
# gedit /etc/init.d/bootmisc.sh
and add the following two lines before the last line that says ": exit 0"
Code:
mknod /dev/kqemu c 250 0
chmod 666 /dev/kqemu
Note that If /etc/init.d/bootmisc.sh does not exist, you can edit /etc/rc.d/rc.local instead. Now, we can stop being root.
Remount the temporary file system so that the full amount of ram is available to qemu
Code:
umount /dev/shm
mount /dev/shm
Let's make a directory to store the qemu disk images
Ok, so now we want to install windows onto a disk image file. From my experience, windows 2000 runs quite well under qemu (winxp is usable also, but there is no easy way to deal with the product activation). Now, insert your windows installation cd into your cdrom drive and type
Code:
$ qemu-img create -f raw ~/images/win2k.img 8G
$ qemu -dummy-net -m 512 -enable-audio -localtime -cdrom /dev/cdrom -boot d ~/images/win2k.img
If you want to be able to read and write the data, you have to format your qemu windows install with the FAT file system. Make sure to select FAT as the file system format during installation. NTFS has read-only support under GNU/Linux.
The "-dummy-net" option blocks windows' access to the network. "/dev/cdrom" should be the file enumeration of your hardware cdrom, and "-m 512" gives the qemu guest OS 512M of ram. Your best bet for the install to complete without hanging is to turn off your screensaver and leave the mouse cursor in the qemu window at all times. Don't use CTRL-ALT to get the X cursor back -- asume that your system is going to be tied up. Go out for a walk, play with the kids, write a poem, write this article, etc. Wait like 4 hours for windows to install checking back periodically for dialogs to answer.
We should now be able to mount, view, manipulate, and unmount the windows disk image.
Code:
$ mount /mnt/windows
$ ls /mnt/windows
$ umount /mnt/windows
Never attempt to mount the windows hard disk image while qemu is running as this may cause unanticipated data corruption.
You can run windows using
Code:
$ qemu -dummy-net -m 512 -enable-audio -localtime ~/images/win2k.img
Note that if you upgrade the Linux kernel, you will need to recompile qemu (make sure to do a "make clean" first).
Well, I hope this gets you started running windows under qemu. Good luck.
-zero