Recently I remembered how I used to be able to boot Windows XP in a window using QEMU - A virtual machine emulator. I noticed that version 8 now supports network, but sadly it didn't work out of the box when I installed Windows XP to a 10GB image file. Luckily, after a few hours of research, I found a method that works. In this guide I will guide you through the steps needed so you can do the same.
A bit of background information first: A little thing to note before starting is that even with the KQEMU accellerator, don't expect it to be really speedy. Your guest OS will function, but at a slightly to greatly reduced speed depending on your guest OS's settings - For example in my installation of Windows XP I've disabled most visual themes, and run it at a 800x600 resolution and it runs pretty well. If I enable themes or run it at a 1024x768 resolution, I notice a quite large speed decrease.
Now, for guest and host OS. The guest OS is the OS you're going to run via QEMU; The host is the one naitively running QEMU. In other words, your host OS is Linux and your guest is whatever you're installing.
Next, images. QEMU will run your guest OS off a image - It simply appears as a regular file, but QEMU will fake it to be the guest system's hard drive space. So the bigger your image, the more space you'll have in your guest OS.
(1): Install QEMU, the KQEMU accellerator and bridge-utils
QEMU will be needed to emulate the machine, and KQEMU is a kernel module that GREATLY accellerates QEMU when executing naitive architectures. In other words, if you're running a i386 system and emulating a i386 system, the KQEMU module will make the speed of emulation near the same! bridge-utils is for networking. First, let's get QEMU installed:
yum install qemu bridge-utils
Unfortunately, the kernel module for KQEMU has only been build for the i386 architecture. Sorry if you're not i386 - You could compile it manually if you wanted, but RPM packaged install is only for i386 machines.
Anyways, browse to:
this web folder and download the appropriate kernel module to your home
Make sure you download the correct one for your kernel - the
kmod-kqemu-0.7.2-6.fc184.108.40.206_1.2111_FC5.i386.rpm module will not work on the 2.6.16_1.2007_FC5 kernel. To check your kernel version, type:.
If the module for your kernel doesn't exist, then please type:
yum update kernel
and then reboot to get a supported kernel.
(2): Creating the image for the guest OS
For best performance, you should install your guest OS to a image file. To create one, type:
qemu-img create filename size[ M | G ]
is going to be the name of your image, and size
is the size of your image with the suffix 'M' (MB) or 'G' (GB) right after the number, no spaces. So, for example, if I typed:
qemu-img create WindowsXP.img 10G
It would create a image file called 'WindowsXP.img' with size 10GB. There is no real recommended size for an image, it depends on the OS you're going to install into it, but I like 10GB as it's not too big, but provides nice room for growth in the guest OS. Remember, too the basic installs of Windows XP take about 2GB and Fedora about 1 to 2 GB.
(3): Configuring network for your guest OS
The next step is configuring network for the guest OS. It's a fairly simple process. Let's start by putting the following contents into /etc/qemu-ifup
# script to bring up the tun device in QEMU in bridged mode
# This script bridges eth0 and tap0. First take eth0 down, then bring it up with IP 0.0.0.0
/sbin/ifconfig eth0 0.0.0.0 up
# Bring up tap0 with IP 0.0.0.0, create bridge br0 and add interfaces eth0 and tap0
/sbin/ifconfig tap0 0.0.0.0 promisc up
/usr/sbin/brctl addbr br0
/usr/sbin/brctl addif br0 eth0
/usr/sbin/brctl addif br0 tap0
# As we have only a single bridge and loops are not possible, turn spanning tree protocol off
/usr/sbin/brctl stp br0 off
# Bring up the bridge with IP 192.168.1.2 and add the default route
/sbin/ifconfig br0 192.168.1.2 up
/sbin/route add default gw 192.168.1.1
/sbin/service firestarter stop
/sbin/service iptables stop
The bold values can be changed, and nothing else. Please change the IP's to show your setup - The first bold is a comment, so it doesn't really matter. The second bolded value is the IP identical to the one assigned to your computer (means you'll need static IPs so you can predict your IP) and the third and last is your gateway.
Now, put this into /etc/qemu-ifdown:
# Script to bring down and delete bridge br0 when QEMU exits
# Bring down eth0 and br0
/sbin/ifconfig br0 down
# Delete the bridge
/usr/sbin/brctl delbr br0
# bring up eth0 in "normal" mode
#start firewalls again
/sbin/service firestarter start
/sbin/service iptables start
Currently, I'm not sure why, but a firewall can't be activated while running QEMU or the internet will stop working. At least, with Firestarter it does. I'm not sure about iptables. Just incase, I disabled it in the scripts. I think it's because we switch from "eth0" device to the bridged "br0", but anyways... Let's make the scripts executable so QEMU can use them:
(4): Installing the guest OS
chmod +x /etc/qemu-if*
Now, it's time to install the guest OS. Pop in the installation CD, and type the following to start the installation:
qemu -boot d -hda image.img -localtime -net nic -net tap -m 192 -usb -soundhw sb16 -cdrom /dev/hdc;/etc/qemu-ifdown
was the name you gave to your image earlier. I'm also assuming /dev/cdrom is your CD drive - if it's not, then please change it to the correct device. After the install is complete, proceed to step 5.
(5): Making the run script & running at will
The last step is to create the QEMU start script and from there on you can run your guest OS at will. Create this file - called qemustart
- in the same directory as your image:
su -c "/sbin/modprobe tun;qemu -boot c -hda image.img -localtime -net nic -net tap -m 192 -usb -soundhw sb16;/etc/qemu-ifdown"
was the name you gave to your image earlier.
Last step - make the startup script executable:
chmod +x /path/to/qemustart
Congratulations. You can now run your vitrual machine at any time simply by running this command: