This guide looks at installing Windows XP using QEMU on a Linux host. (All host references are linux!) See QEMU Getting Started tutorial before starting this tutorial.
Note: although Linux is free you must have a license for the copy of Windows XP you will be running.
CREATE A VIRTUAL HARD DISK (i.e. a 3.5GB file!)
The linux command below will create a file of around 3.5 GB which should be ample for XP + SP2 and a few applications. Note that while winxp via QEMU is functional it is too slow for any real work. e.g. It's useful 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 create winxp.img 3500M
A fair number of people claim the second method 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 WINDOWS 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 Virtual 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. One workaround is to I set the permissions to 666 (rw for everyone) on the run device.
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
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.
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
Mount the iso image as the cdrom under qemu by using the "-cdrom
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 Running Microsoft Windows inside Debian: qemu QEMU - Debian - Linux - TUN/TAP - Network Bridge SP2 Reference