Jump to content

QEMU/Windows XP

From Wikibooks, open books for an open world

Why run Windows in QEMU

[edit | edit source]

GNU/Linux, OSX and FreeBSD are fine operating systems, but sometimes you just need to run Windows programs. This can be achieved in several different ways, for example:

  • Wine will run some Windows programs directly in Linux/OSX/*BSD
  • rdesktop gives you a remote desktop from a Windows computer running on Linux/OSX/*BSD
  • Dual booting allows you to select which OS to run when you start your computer
  • QEMU lets you run Windows as just another program running under Linux/OSX/*BSD

The first three options have some major advantages, especially performance, but are not always practical. Some Windows programs won't run in Wine, or at least not properly; rdesktop requires you to have access to Windows running on another computer; dual booting means you can't run your operating system's native programs while you're running Windows.

If you have a legitimate, licensed copy of Windows XP Pro, you can create a QEMU image and run Windows on your Linux/OSX/*BSD computer. NB: you might not be able to use an OEM copy of Windows XP, as it might be locked to the hardware it came with (not the hardware that QEMU is emulating).

Added by another reader: There really isn't much of a difference between OEM windows and retail windows. The difference may surprise some users, but in your setup.ini file that is in the directory folder 386 is a pid. That pid can be changed to turn a retail copy to an OEM or vice versa. OEM is not coded to any hardware, but the keys for OEM are different. I have two legal OEM keys and no disc. This is how I found out; a lot of users run into this problem because discs are not always given out with a machine, but often copied to a directory and users tend to lose them to hard drive malfunctions or forget it's there then borrow or download an ISO image of Windows XP to find out they can't use their key. Well you can by changing the pid. So I believe that you could use your OEM Windows XP as well as the retail version with QEMU. Since only a few numbers and letters in the ini file is the difference.

Reader Footnote: Please be aware that some OEM branded Windows included product branding and some even had very limited driver sets. It is less locked to the hardware than lacking wide support. Usually drivers can be found from manufacturer sites.

Creating an image

[edit | edit source]

The basic setup instructions work well for creating a basic Windows XP image for QEMU. To make things a little easier, copy the Windows XP disc to an ISO image so that you can easily hook it back into the system (e.g. to install additional networking components such as IIS web server.)

Be aware that 3 GB might not be enough, depending on what software you will be installing under Windows, and it isn't easy expanding an NTFS partition with software installed on it. A better base size would be 10 GB, however, with a little tweaking of virtual memory and hibernation settings a basic Windows XP will run on 3 GB. Storing data files on Linux/Unix and accessing them via SAMBA also helps reduce the requirements for larger QEMU image files.

Optimising the image

[edit | edit source]
System Properties video performance settings

Even with the KVM kernel module, running Windows under QEMU can be aggravatingly slow. While straight code runs quickly, system calls that need to be emulated (especially to the video card) can make things seem very slow and sluggish. This can be easily improved by turning off some of the GUI bling that Windows XP introduced. Open the System Properties applet from the Control Panel, select the Advanced tab, and open the Performance settings. See the image at right for some examples of settings that you can turn off to improve performance, or just turn them all off by selecting "Adjust for best performance". NB: if you connect to your Windows XP image using RDP (remote desktop), these settings will be picked for you by default anyway; RDP is probably the fastest way to get a Windows XP desktop visible in other operating systems, but requires some networking configuration (see below).

While you've got the System Properties applet up, you might as well also turn off System Restore. This chews up some more resources, and you can probably do without it if you keep backup copies of your images (always a good idea!)

Another thing you probably don't need is Windows Update. You can always activate an update when you are good and ready, so why let Windows initiate one while you're trying to get something done in Windows under QEMU? NB: If you will be doing any Internet browsing from within the Windows XP image, especially with Internet Explorer, it is highly dangerous to disable Windows Update completely. It may be safer to schedule updates for a fixed time, or to use the "Download updates for me, but let me choose when to install them" option.

Unless you want to test hibernating / restoring the system with some custom software, you will probably want to turn off hibernation. This will free up some disc space, as much space as the RAM you allocate QEMU (so probably 256 MB or more). When working on space-constrained images, that can be very welcome space to get back.

If you have a few different QEMU images of Windows XP, e.g. to test different versions of software or support different development environments, you can shift the Windows pagefile to another disc image and share it. NB: you can only share a pagefile if you only have one QEMU instance running at once! Create a simple pagefile image with raw format using qemu-img, format it to NTFS from Windows XP in QEMU, and move your pagefile across to the new drive in the System Properties applet.

You might want to run a virus scanner on your Windows XP image (and you probably should!) If you do, remember to turn off automatic updates to improve the startup time. Just also remember to run the update sometimes! NB: As with Windows Update, completely disabling the automatic update feature of a virus scanner is highly dangerous if you will be doing any Internet browsing from within the Windows XP image. If your software offers a scheduled update feature, it would be safer to set the schedule to a non-interrupting time, rather than rely on memory for this task.

Networking

[edit | edit source]

If you are only going to use network resources external to your Windows XP guest OS, then you probably don't need to do anything special to get networking up and running. QEMU will provide user mode networking by default, giving the guest OS access to TCP and UDP based networking that your Linux/unix host has access to. By default, Windows XP will turn on DHCP and thus automatically be assigned an IP address by QEMU's virtual DHCP server (with an address starting at 10.0.2.15)

This setup will allow you to access the Internet from your guest OS, and let you map Windows drives to SAMBA shares on your real-world network or the virtual SAMBA server in QEMU (10.0.2.4). If you need to test web pages in Internet Explorer, for example, you will be able to browse to them on the Internet, or by typing in the network IP address of your Linux/Unix host if you have them hosted locally. To access the network resources by name named only in host files, edit the local host file in Windows:

notepad \windows\system32\drivers\etc\hosts

If you need to access network resources on your Windows XP guest OS from your Linux/Unix host, you will need to do a little more work. User mode networking shows how to configure QEMU to forward ports to the guest OS for Windows file sharing and serving web pages. If you want to keep maintaining some ASP websites, but don't want to leave the comfort of your Linux/Unix desktop and its tools, you can use this technique to allow you to mount a Windows file share on your QEMU guest OS under your host OS. Just share the folder C:\inetpub\wwwroot\ with the appropriate permissions, and you should be good to go.

If you need a more complex network setup with all ports available without port forwarding, you'll need to get into TAP interfaces or sockets.