WindowsXPUnderQemuHowTo

Revision 3 as of 2005-07-28 10:26:38

Clear message

Introduction

Ubuntu. We love it. But how many people have completely rid their computer of Windows? If you are a gamer, that's probably impractical for you. If, like me, you are happy with Frozen Bubble but have a few Windows apps you can't live without and which crash under WINE then this HOWTO is for you. It runs through the steps needed to install a working copy of Windows XP Professional using QEMU.

[http://fabrice.bellard.free.fr/qemu/ QEMU] is a PC emulator, like Bochs or VMware. Like Bochs, and unlike VMware, QEMU is Free Software. However, there exists an acceleration kernel module for QEMU - KQEMU - which is currently closed source and proprietory. KQEMU is not required for emulation but does make an extremely significant speed improvement to the emulation. It is a matter of individual preference and conscience whether or not you choose to use this closed module.

This HOWTO can be adapted to install any guest operating system. I have chosen XP Professional because that's what I had a copy of, but QEMU can be used for emulating other operating systems - including, in a "Russian Doll" way, Ubuntu ["Installation/QemuEmulator"]. In many ways, XP is not the best choice, as it is slower than either Windows 9x or Windows 2000 under emulation. But for many of us, it will be what we have lying around There is nothing in this HOWTO that is XP specific. I hesitate, however, to title this HOWTO anything more general as I have not had the opportunity to test other Windows versions under QEMU. There may well be specific issues for non-XP versions of Windows.

Licensing

Your XP licence only allows one install of XP at a time. Installing XP on a virtual machine while simultaneously having the same copy on another partition or machine will break that license. Jack-booted goons will haul you away in the middle of the night to a re-education camp. The next time your friends and family see you, you will be a gibbering mass of madness railing against Linus Torvalds and his communist plot to destroy Capitalism. Small children will avoid you in the street and neighbours will point at you and whisper. You have been warned.

Obtaining QEMU

You can apt-get QEMU as a binary package, but this won't allow you to use KQEMU. I am going to assume that you want to compile QEMU from CVS source. The CVS source is much more likely to be up-to-date (which can, of course, mean buggy).

Installing QEMU and Windows XP Step-by-Step

You will need CVS, the SDL development packages, and texi2html. You will, at the very least, also need the kernel headers that match the kernel on which you are going to install QEMU. If you have the full kernel tree you will also be fine but you will need to compile the kernel at least once - you don't need to install it, just compile it. If you follow this HOWTO and get a stream of errors relating to /usr/src/linux then that is a sign that you need to compile the kernel. Just switch to /usr/src/linux and do a

make oldconfig

The packages you need are thus cvs, libsdl1.2-dev, texi2html and at least the kernel headers to match the running kernel. Use your favourite apt tool to get these if you don't have them already. You will also need to set up a symbolic link to the kernel source/headers as follows (I will use kernel 2.6.10 as an example, change it to match your kernel):

cd /usr/src
sudo ln -s linux-2.6.10 linux

Step 2 - Get the source to QEMU and (optionally) KQEMU

Currently, the source to QEMU is not in any repository. You will need to use CVS to obtain it. To do this, open up a terminal and cd to the directory where you want the source to reside. Then issue the following commands:

export CVS_RSH="ssh"
cvs -z3 -d:ext:anoncvs@savannah.gnu.org:/cvsroot/qemu co qemu

If prompted answer 'yes' and the source to QEMU will be downloaded to the 'qemu' directory under the directory from which you entered the cvs commands.

OPTIONAL - Install KQEMU

Now, if you want KQEMU you will need to download it from here. At the time of writing, the latest version is 0.6.2-1

Once again, KQEMU is not free software. If you choose to install it, Richard Stallman will haunt your dreams and sing the [http://www.gnu.org/music/free-software-song.html Free Software Song] at you. Download the gzipped KQEMU to the qemu directory you created a moment ago through CVS and unzip it there. This will create a kqemu directory under the qemu directory:

cd qemu
tar zxvf kqemu-0.6.2-1.tar.gz

Step 3 - Compile and install QEMU

Type

./configure --help

This will list the available options you can pass to the configure script. The one of interest here is the "--target-list=" parameter. This sets the system architecture. For must of us, this will be "i386-softmmu".

Type

./configure --target-list=YOUR ARCHITECTURE (e.g. i386-softmmu)

Check the output of the script to make sure that SDL and the kernel headers have been identified. If you installed these through apt, all should be well. Then issue the following:

make
sudo make install

This will compile and install QEMU

If you chose to use it, the KQEMU module will also have been created. You can load this through:

sudo modprobe kqemu

You may also need to create the /dev/kqemu device. I found that this was done automatically after the first compile but for subsequent uses of QEMU, I had to do do myself. The commands are:

sudo mknod /dev/kqemu c 250 0 
sudo chmod 666 /dev/kqemu

Step 4 - Creating a virtual hard drive

OK. That was fun but so what? To install XP you will need to create a virtual drive to store it on. This is easy. Change to the directory that you wish to keep your virtual drive on (for example, mine is in '/mnt/storage/win') and issue the following:

qemu-img create -f qcow winxp.img 2G

This creates a two gigabyte virtual drive called winxp.img in the location where you ran the command. Obviously, you can make a larger or smaller drive (though I think XP requires at least about 1.5 Gb) and call it whatever you like. This size, by the way, is the maximum size - the drive will start out smaller and grow as you install software to the XP installation. This is because of the compressed qcow format that is used. Note that if you use this format, you will not be able to mount the image within Ubuntu. You can omit '-f qcow' and create a mountable raw image, but this will mean that the size of the virtual drive will be fixed and larger. At the end of the HOWTO I will show you how to convert a raw drive to a qcow drive, if you start with raw and change your mind.

Step 5 - Install Windows XP

Now the fun bit. If you have an XP installation CDROM then issue the following command:

qemu -localtime -hda winxp.img -cdrom /dev/hdc -m 196 -boot d

This tells qemu to use the system time on your linux box as the time for windows (-localtime), to use the virtual disk as the harddisk (-hda winxp.img), which drive to use as the CDROM (-cdrom /dev/hdc) and to allocate 196M of memory for the virtual pc (-m 196). Careful with the last parameter - too much memory to qemu may leave your Ubuntu crawling and too little to Windows will grind XP to a halt. If you leave off the memory parameter, then 128M is used.

If you have made a cdrom image of XP or have an image of a live CD for a GNU/Linux distribution then you can use that as a CDROM. In this case, the command would be:

qemu -localtime -hda winxp.img -cdrom /your/cd/image/file.iso -m 196 -boot d

In either case, QEMU will boot up, and you will be in the XP install. This is identical to any other installation of XP.

Follow the standard XP installation and after a few reboots of QEMU and about 40 minutes, you will have a copy of XP installed on your virtual drive.

You will likely need to interact with the install. Just click on the QEMU window and interact away.When you need your mouse, press CTRL+ALT and your mouse is free.

Step 6 - Starting Up Windows XP After Install

When you have finished playing with the installation, you will eventually want to shut it down - which you do via the start menu as for any other XP installation. To "turn off your computer", just close the QEMU window.

To run QEMU again, you will need to issue the following commands:

sudo modprobe kqemu
sudo mknod /dev/kqemu c 250 0 
sudo chmod 666 /dev/kqemu
qemu /your/xp/hd_image/file -enable-audio -user-net -localtime

'-user-net' sets up a firewalled network for XP (see below). The first three lines are only necessary if you have rebooted Ubuntu since you compiled QEMU (and if you are using KQEMU).

There's a lot you can do to automate this process. You could load KQEMU at boot or write a script to create /dev/kqemu at boot time. Or you could just put the above commands in a bash script and run the script when you want to load XP.

Sharing Files With XP and Networking

It's not much use having an XP installation if you can't transfer files between Ubuntu and XP. Fortunately, QEMU sets up a virtual LAN and DHCP server for you. You can transfer files to and from XP just as if it was on a real LAN. You can also browse the net and download files and do all the network stuff you would do on a real networked XP box. For me, for instance, web browsing worked 'out of the box'

Samba

QEMU supports samba, if you have that configured on the host system. Getting samba up and running is out of the scope of this document, but there is a good HOWTO here [SettingUpSamba]. For the following, I will assume that you have samba operational and have a share called 'qemu_share' that you want to use to transfer files between Ubuntu and XP.

To set this up, you need to start QEMU with the following command:

qemu /your/xp/hd_image/file -enable-audio -user-net -localtime -smb qemu_share

Once inside XP, you can access the shared drive with the following command from a DOS prompt:

net use e: \\10.0.2.2\qemu_share

Here, you are mapping windows drive 'e' to the share. The IP address of Ubuntu will always be 10.0.2.2 If you have running servers on your Ubuntu box, they can also be accessed at this IP address (e.g. ftp 10.0.2.2)

Mounting A Virtual Drive

You can also mount the virtual harddrive you created just like any other drive provided that the drive was not created in the qcow format.

Make sure you are NOT running QEMU when you do this.

To mount the drive, imagine you have created a directory '/mnt/qemu_image' and wish to mount your XP image here. Your XP image is at '/home/bilbo/win_xp/xp.img'. You would type the following:

sudo mount -o loop,offset=32256 /home/bilbo/win_xp/xp.img /mnt/qemu_image

That being said, I personally prefer Samba as a means of interacting with QEMU.

Other Cool Stuff

Forget system restore and backup under XP. QEMU uses a concept called 'overlay images'. Once you have done your initial install, you can create an overlay image and run QEMU off this. The overlay image is very much smaller that the original image and will only contain changes made since the original install. If you trash your XP installation, you can simply delete the overlay image and create a new one from the original image. If you have had a bad day, don't kick the cat, just trash a Windows XP install! It will make you feel better, trust me.

To create an overlay image, use the qemu-image program which is installed with QEMU. To create an image winxp.ovl from winxp.img, issue the following:

qemu-img create -b winxp.img -f qcow winxp.ovl

To run XP, you would now use:

qemu winxp.ovl -enable-audio -user-net -localtime -smb qemu_share

If the winxp.ovl installation is ruined, you can delete it, and start QEMU using the winxp.img file. But you will lose changes made since the original install.

QEMU also accepts commands from the shell while it is running. To do this, though, you need to press CTRL+ALT+2 with the QEMU window active. This brings up the QEMU Monitor. From here, you can swap CDs, send keypresses to the emulator, suspend to disk and so on. See the [http://fabrice.bellard.free.fr/qemu/qemu-doc.html documentation] for full details. To exit the QEMU monitor press CTRL+ALT+1

Miscellaneous

Converting a raw drive to qcow format

This is achieved using the qemu-img program. To convert your raw 'winxp.img' file to a qcow formatted 'winxp.qcow' you would do:

qemu-img convert winxp.img -O qcow winxp.qcow

* [http://fabrice.bellard.free.fr/qemu/ QEMU Homepage]

CategoryDocumentation CategoryCleanup