Saturday, January 10, 2009

How to Install Windows Xp on QEMU

QEMU is an emulator, which can be setup on both windows and linux, installing it on linux is simple and straight forward, but little complex and tricky on windows and most of the times. So I prefer to use it on linux. QEMU can emulate an x86 machine, (i.e your PC), so it can be treated as a vitual pc, with an hard disc image you are ready to install any OS on that virtual machine. KQEMU is an accelerator which increases the speed of emulation to close to native speed when host and guest OS are running on the same machine, i.e Target machine is same as host machine, This is achived by emulating only the kernel, and running the user code directly on the machine, Recent machines also support Virtulization at the hardware level, but that is out of scope of this document, in that case you can get native speeds on guest OS also.

I assume that you have setup the QEMU and KQEMU on your Linux. To install these refer to Installing QEMU and KQEMU. Once you are done with the above step. Please follow the following steps.

Create a hard disk image for windows xp, be it be of size 3-4GB size. Create a folder somewhere for windows xp image, and then use 'dd' command to create an image of 4GB size.

$ mkdir winxp
$ cd winxp
$ dd of=xp.img bs=1024 seek=4000000 count=0

Now a Image file (xp.img) of size 4GB is created, which can be used as hard disk for installing windows xp on QEMU. Run the below command.

$ qemu -m 384 -boot d -cdrom /dev/cdrom -hda xp.img

This command says to run QEMU with 384MB of Ram, and to use xp.img as hard disk, and to boot from cdrom. I assume that you have inserted the windows-xp bootable disk into the cdrom. If you have bootable cd image of windows xp (cdimagefile.iso), then use the below command to use that image instead of CD.

$ qemu -m 384 -boot d -cdrom cdimagefile.iso -hda xp.img

After this step, its windows setup, on any other PC, just follow the instructions on screen and it will install windows on the hard disc image specified. Partition as per your requirement, but since you have only 4GB hard disc better to keep only one drive (C:\)

Many of then say that it gets hanged at the end of installation, seem to be a problem with windows xp itself, but it did not happen to me, it got installed without any issues.

Once installed you can use the below command, to boot from hard disk image xp.img instead of CD, which is meant only for setup windows-xp. Now you can enable kqemu also, which is an accelerator for qemu, which makes your guest OS run at close speed to the actula OS, which is achived, by emulating only kernel, and the user threads are run directly on the machine, as both host and guest OS are running on the same machine.

follow these steps to enable kqemu, you should have root permission to do this, or use sudo to achieve the same.

$ modprobe kqemu major=0
$ chmod 755 /dev/kqemu [optional - only if you want to run without root]
$ chown root:$prasad /dev/kqemu [optional - prasad is my user name]

Once all this is done run the below command, windows-xp should boot with out any issues, if you find any difficulty feel free to ask me, I will be there to help you out. I have documented this, as it might help some of you, or may be to myself after long time, if I had forgotton everything.

$ qemu -m 256 -boot c -hda xp.img -snapshot -kernel-kqemu -localtime

(-snapshot is optional if given your xp.image is not modified, it also implies you work is not saved. drop it if you want)
(
-localtime is to get the time from the host system - useful, so dont drop this)

Now your windows is setup, and you can shut down the machine, and make a copy of xp.img somewhere safe, so that when your windows crash just replace the hard disc image xp.img with the backup image. You are done, no need to reinstall windows. You are done with Windows installation, but networking is not setup, user mode network is setup automatically, but I dont think you can browse internet with that, so you need to setup TUN/TAP networking with Bridge utils. I will post how to do it in my next post.

References:
  1. xp-under-debian-with-qemu
  2. http://ubuntuforums.org/showthread.php?t=179472
  3. https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo

1 comment:

  1. hi,
    i am trying to access internet from winXp (SP2) but cudn't. any idea?

    ReplyDelete