Adverts

QEMU

QEMU is a fairly complete x86 emulator that lets you run one operating system under another. Currently it is best supported under Linux where it can host numerous other OSes. This guide looks are running Windows XP under QEMU on Debian Linux. Note: although Debian is free you must have a license for the copy of Windows XP you will be running.

Installing QEMU

the first thing to do is install QEMU. Simply use apt-get or any one of the other package managers around.

apt-get -u install qemu

Create a Virtual Hard Disk

QEMU uses a large file rather than a real partition to run the guest perating system. This means that it is very easy to create multiple guest systems on the same machine. I have chosen to install Windows XP under /var/qemu for two reasons. Firstly, my home directory is NFS shared off a server - QEMU is quite slow when performing disk access and the network delays would make this worse. Secondly, my home directory is backed up nightly and I don't want to place an undue load on the back up. Apart from these two reasons I would have created the file in my home directory.

The command below will create a file of around 3.5 GB which should be ample for XP + SP2 and a few applications. Note that you won't be working on XP under QEMU. While it's useable it is to slow to work on. I use this set up mainly to check websites in IE.

cd /var/qemu
dd of=xp.img bs=1024 seek=3500000 count=0
0+0 records in
0+0 records out
0 bytes transferred in 1*10-9 seconds (0 bytes/sec)

or

qemu-img xp.img 3.5G

I used the first version but a fair number of people claim the second is better. The main reason given is that dd will allocate the whole 3.5GB in one shot wasting space on the drive. This is actually not the case because of the use of the seek argument. I don't think there is any real difference betwen the two commands.

Install XP

Now that the virtual drive has been created it's time to install XP on it. The command below tells QEMU to boot from the "d" drive and use the /dev/cdrom device as the cdrom and the virtual drive as the first hard disk (hda). Place the XP install cd in /dev/cdrom and start QEMU. You should see a new window pop up and display the XP install sequence.

qemu -boot d -cdrom /dev/cdrom -hda xp.img
QEMU 0.6.0 monitor - type 'help' for more information

Wait...

Wait. Then wait some more while the XP install process takes place. For some reason it takes hours even on a very fast machine. Many people have pointed this out but no one seems to know why. After the install was complete my copy of XP hung on the first boot (no progress and no CPU useage). This has been reported by some people who have waited more than a day for the system to boot with no effect. I got fed up of waiting and shut the virtual machine down and restarted it. I have had this happen with real XP installs as well so I can only assume there is a bug.

Image Backups

Nows quite a good time to take a back up of the install. If something goes wrong you can then simply copy the backup over the dead version and have a fresh install.

cp xp.img clean-xp.img

Set up the Vitrual Network

In order to talk to the outside world you need to set up a virtual network card for QEMU. By default it will try and use tun. The tun device on Debian can't be accessed to by anyone but root by default which isn't very helpful so use the following commands to change that. The first two change permissions the last two load the tun module into the kernel so that tun actually works. Note that the group used here is staff. It might be users on your system.

chgrp staff /dev/net/tun 
chmod g+rw /dev/net/tun
modprobe tun
echo 'tun' >> /etc/modules

I found that the group setting on the tun device was reset after a reboot but the permissions weren't. To get round this I set the permissions to 666 (rw for everyone) on the run device. Your mileage may vary of course.

chmod 666 /dev/net/tun

QEMU tries to run the /etc/qemu-ifup script with uses /sbin/ifconfig when it starts a virtual machine. In order to run this you need to give the user running the script the ability to execute ifconfig. This is done using sudo. A very basic example sudo file is shown below.

# Cmnd alias specification
Cmnd_Alias QEMU=/sbin/ifconfig

# User privilege specification
root            ALL=(ALL) ALL
%staff          ALL=NOPASSWD: QEMU

Note that the default Debain install of QEMU puts the tun device on 172.20.0.1 which means XP should be put on 172.20.0.2 and use 172.20.0.1 as a gateway. If your network doesn't use this block of non-routable addresses it might be worth your time changing this so that the guest OS is in your locak network IP space. I quite like it like this as it makes the virtual machine easy to seperate out on the network.

Once the settings in XP are correct you should be able to ping back and forth between host and guest machine. Setting it up so that the guest can access the Internet is a little harder and I will come to that later. If the machines can't talk to each other make sure that there isn't a firewall blocking communication. XP with SP2 has the firewall switched on by default and my Linux box blocked all non-local traffic.

Boot XP

Now it's time to boot XP. The following command should do it.

qemu -hda xp.img -boot c

I hit a bit of a snag at this point. When I tried to log in I got a message about not being able to activate Windows. Reading around I found out that this is something to do with the virtual network device. The solution, which requires some sneakyness, is given below.

Error code 0x800703e6 on Product Activation - Installing Service Pack 2

Download Windows XP Service Pack 2 while this is a big download it does mean that you won't need to use the network to install it.

Create an iso image of the file with "mkisofs -o sp2.iso <name-of-sp2-file.exe>"

Mount the iso image as the cdrom under qemu by using the "-cdrom <path-to-iso>" argument.

Run Service Pack 2 from the virtual CD drive. I got an error message about an "Invalid Access to Memory Location" at one point during the install but it seemed to continue without a problem.

References

Other Virtual Machines

VMware

Plex86

Bochs

Adverts

Donate and Help

Please support this site and
Bandwidth doesn't grow on trees y' know :o)

Adverts

Get Adsense