Posted by Steve on Sun 7 Nov 2004 at 22:51
There are many legitimate reasons for a Debian GNU/Linux user to wish to run Microsoft Windows applications. One approach involves using the wine program to run a single Windows executable in a fake Windows environment. An alternative is to run an entire Windows operating system within a Debian host. Qemu is a procesor emulator and virtualization program which allows you to do just that.
Qemu is available for Debian's unstable distribution, and can be installed from the source code available on its homepage for Woody. It is comparible to the commercial software VMWare albeit with a few features missing and a lower performance.
On the plus side it is evolving fast, and doesnt require complicated setup or kernel patching. It is also free - although if you wish to run an installation of Windows you will need a valid license to do so.
Qemu is a complete CPU and peripheral emulator which can be used to run entire operating systems as a user process, supported operating systems include Linux distributions such as Debian, RedHat, SuSE, varieties of Microsoft Windows such as Windows 98, Windows 2000, and Windows XP and BSD based operating systems. There are some disk images available from the Free OS Zoo website.
Whilst it's not as fast as running an operating system directly on the same hardware because of the overhead of virtualising running as a guest operating system is suprisingly responsive on my AMD XP 2800+ machine, once the slow installation is achieved.
This brief guide will walk you through installing Windows 2000 as a guest operating system on your Debian box.
First of all you need to install qemu, by running as root:
apt-get install qemu
Once this is done we're ready to start the installation process.
As qemu is a virtualization program it doesnt touch your real discs, instead you give it a big file and tell the system to use that for it's C:.
As a simple start we'll set aside a blank 2Gb file for Windows to install into, we can create that easily enough:
skx@undecided:~$ dd of=hd.img bs=1024 seek=2000000 count=0 0+0 records in 0+0 records out 0 bytes transferred in 0.000493 seconds (0 bytes/sec)
That's given us a file called hd.img which is 2000000 bytes long, close enough to 2Gb for us to proceed.
The next thing we need to do is have a Windows 2000 CD-ROM handy, we have two choices here either place it in your CD-ROM drive, or use an ISO image.
We'll go with the former.
We want to tell the system that it's first hard drive should be the big empty file we have just created, that the CD-ROM drive should be read from the drive we have - and that it should boot from CD-ROM.
skx@undecided:~$ qemu -boot d -cdrom /dev/cdrom -hda hd.img QEMU 0.6.0 monitor - type 'help' for more information
The '-boot d' flag tells the system to boot from the CD-ROM drive we've specified, the '-hda hd.img' tells the system that the first hard drive should be the contents of the file hd.img which we created previously.
This should bring up a window upon your desktop within which you'll see Windows boot. You can click in the window to give it focus, and when you wish to return the mouse to your desktop press "Ctrl + Shift". Pressing Ctrl + Shift + f will toggle you between fullscreen and windowed mode.
Now you can sit back and install Windows as you normally would. Some parts will be very slow, other parts such as formatting the drive will be lightening fast!
Whilst using the guest operating system is acceptably responsive for me the actual installation took a couple of hours. Most of this is waiting for the thing to finish, but it's something to be aware of.
I found that when I installed Windows 2000 it seemed to go faster if I ran it fullscreen and shut down as many open programs as I could.
When it came to networking I found that Debian doesn't allow non-root users to write to the tun driver by default, as root run:
chgrp users /dev/net/tun chmod g+w /dev/net/tun
(If you don't have that device file you will need to run these commands, this assumes you're running Kernel 2.6.x)
mkdir -p /dev/net mknod /dev/net/tun c 10 200
Finally we add in the module to enable the device :
modprobe tun echo 'tun' >> /etc/modules
Now that you're installed the operating system you can create a backup of the image by simply copying the 'hd.img' file which is being used as the disk drive:
skx@undecided:~$ cp hd.img pristine.img
Any time you wish to restore back simply overwrite the hd.img with the pristine one - you'll never have to reinstall again!
Now that we've done the installation we can start the system for real with:
skx@undecided:~$ qemu -hda hd.img -boot c
From bootup to login prompt takes me 39 seconds, which is pretty impressive.
Networking should be setup properly for you in the sense that on the host machine you will have the interface tun0 setup.
Once that's done you need to setup some way for the emulated machine to talk to the world, or it's host at least.
I chose to give the host machine an IP address on it's own network. We do this by first setting up an address on the host, then on the guest.
I use 10.0.0.1 for the host, and 10.0.0.2 for the Windows system.
On the host run:
root@undecided:~# ifconfig tun0 10.0.0.1 up
Then on the host adjust the networking so that the Windows operating system has the ip address 10.0.0.2, with the gateway set to point to 10.0.0.1.
This should allow you to ping both the guest from the host, and vice versa.
If you wish the host to be able to talk to the internet generally run the following on the host:
root@undecided:~# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE root@undecided:~# echo "1" >/proc/sys/net/ipv4/ip_forward