Thursday, September 3, 2009

Windows XP on Ubuntu with qemu

If you were reading this blog for a long time you already know that I ditched Windows and moved to linux years ago. I have been using Linux for about 3 years now and I never regretted moving to it. However, annoyingly enough, there is one tiny thing that I cannot do on linux but I can do on Windows. In the Hebrew University, in order to get the exercises you need to download them from the university site. Most of the site works just fine in Firefox, but for some reason it is impossible to download the exercise with it. It is only possible to do so in IE.

The students have been asking the university to fix the site for the last two years, but without much success. It is of course possible to go to an university computer and to download everything there, but it is inconvenient. I tried installing IE using wine, but it didn't work. So in the end the only option I could think about was to install Windows using qemu. This post is a short how-to that shows how to install and then configure windows under qemu for it to work without doing problems.

The first step is obviously to obtain a windows cd or an iso file. The next is to install all the required packages:

sudo aptitude install qemu kqemu-common kqemu-source samba smbfs

This will install qemu and also samba for sharing files between Windows and Ubuntu. Next is to configure kqemu - it is an accelerator used by qemu:

sudo module-assistant prepare
sudo module-assistant auto-install kqemu
sudo addgroup --system kqemu
sudo adduser $USER kqemu
sudo modprobe kqemu

Now you need to log out for the changes to take effect. After logging in, the next step is to create a disk image. The minimum size is 4GB (because of the SP3 and other updates), but I used 10GB because I want to be able to install programs latter on without worrying about free space. The image will change it size dynamically, so don't worry about throwing away too much space. To create the image type:

qemu-img create -f qcow windows.img 10G

Now we can start the install process. If you have a CD insert it and type:

qemu -localtime -cdrom /dev/cdrom -m 512 -boot d windows.img

I set memory to 512MB but you can enter something else, preferably at least 384. If you want to install from an iso, put the iso in your home directory and type:

qemu -localtime -cdrom cdimagefile.iso -m 512 -boot d windows.img

After doing this, the install process will start. It worth to note that it will go on for longer than a regular install, so you will have to be patient. Once the install is done, you can start using Windows. To run windows you type:

qemu windows.img -localtime -m 512

Optionally you can create a launcher on the panel or the desktop. For this you will need an appropriate icon. I used this one:

As we all know, windows is much less safe than Linux. Luckily qemu has some options that allow us to protect the installation. The first such option is to create an overlay. This will allow you to use windows while saving all the changes in the overlay file and not in the original img file. If you do this and at some point at time Windows becomes corrupt you can just delete the overlay and create a new one without installing Windows from the beginning. To create an overlay type:

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

To use the overlay you will need to type:

qemu windows.ovl -localtime -m 512

For increased safety you can also use the snapshot mode. In this mode all the changes you make are written to a temporally file which is removed when you close qemu. To use this just add "-snapshot" to the end of the command.
The final step is to make it possible to share files between Windows and Ubuntu. To do this we can use samba. The first step is to create a shared folder. In my case I created a folder named AnatolySharedFiles in my home directory. Now we can setup samba to share this folder:

sudo addgroup samba
sudo adduser $USER samba
sudo aptitude install system-config-samba

Now you can go to System->Administration->Samba, and use it to add the folder you want to share and to add a user password for yourself. Now all that remains is to configure Windows. The first step is to go to My Computer->Properties->Computer name and enter the correct data. Then go to Network places to create the network. The next step is to mount the shared folder as a network drive (this seems to be the best option to me,buy you can access it from network places as well), this is done by clicking on My Computer->Map network drive.

After doing all this you hopefully have a working Windows and I have an easy way to get my math homework...

No comments: