Running Windows On Linux Using QEMU

This procedure was produced in the following environment:

  1. The computer came with Windows pre-installed, without Windows installation CD.
  2. My goal was: whatever I do, I must still be able to boot into Windows. The computer may have to be given to someone else who may not know how to use Linux. I may have to use the pre-installed Windows on a rainy day when I totally mess everything up, and still need to get something done. This means that I must leave the Master Boot Record untouched, and I must not destroy the Windows installation.
  3. Re-partition the hard drive, using KNOPPIX, XENOPPIX, etc (resize the Windows partition, and create a new partition for Linux)
  4. Download Fedora 7 installation DVD, and install it onto the new partition that I just created (I did not install grub onto the master boot record)
  5. Made a grub bootable CD.
  6. Use the grub bootable CD to boot into Fedora 7.

Later version of Fedora may have better support for QEMU, so you may not have to install these RPMs.

Download and

rpm -i kqemu-1.3.0-2.fc7.i386.rpm kqemu-kmdl-2.6.21-1.3194.fc7-1.3.0-2.fc7.i686.rpm

modprobe kqemu major=0

// Create a blank image
qemu-img create -f cow rewriter.fc4.qemu.img 10G

// Install an operating system onto the image (if you have installation CD in the CDROM drive)
qemu -cdrom /dev/cdrom -hda rewriter.fc4.qemu.img -m 256 -boot d

// Install an operating system onto the image (if you have an installation image)
qemu -cdrom installation.iso -hda rewriter.fc4.qemu.img -m 256 -boot d

// Boot using the brand new image
qemu -hda rewriter.fc4.qemu.img -m 256


# Script to bring up the tun device in QEMU in bridged mode
# This script bridge eth0 and tap0.  First take eth0 down, then bring it up with IP
modprobe ne irq=9 io=0x300
modprobe tun

/sbin/ifdown eth0
/sbin/ifdown br0
/sbin/ifconfig br0 down
/usr/sbin/brctl delbr br0

/sbin/ifconfig eth0 up

# Bring up tap0 with IP, create bridge br0 and add interface eth0 and tap0
/sbin/ifconfig tap0 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 not possible, turn spanning tree protocol off
/usr/sbin/brctl stp br0 off

# Bring up the bridge with IP and add the default route
/sbin/ifconfig br0 up
/sbin/route add default gw


# Script to bring down and delete bridge br0 when QEMU exits
/sbin/ifdown eth0
/sbin/ifdown br0
/sbin/ifconfig br0 down
/usr/sbin/brctl delbr br0
/sbin/ifup eth0

qemu -hda /home/rewriter.fc4.qemu.img -M isapc -m 512 -net nic,vlan=0 -net tap,vlan=0

Making an image of existing installation of Windows XP
The manufacturer installed Windows XP on the hard drive. We somehow manage to re-size / re-partition the hard drive, and install Fedora Core 7. Here is the output of fdisk:

fdisk -lu /dev/sda
Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    15727634     7863786    b  W95 FAT32
/dev/sda2   *    15727635    63938699    24105532+   7  HPFS/NTFS
/dev/sda3        63938700   486335744   211198522+  83  Linux
/dev/sda4       486335745   488392064     1028160    5  Extended
/dev/sda5       486335808   488375999     1020096   82  Linux swap / Solaris

Next, make a blank disk image:

dd if=/dev/zero of=blank.img bs=512 count=63938700

Partition the blank image:

losetup /dev/loop0 blank.img
fdisk -u /dev/loop0
losetup -d /dev/loop0

Copy the FAT32 partition data onto the image:

losetup -o32256 /dev/loop0 blank.img
dd if=/dev/sda1 of=/dev/loop0 conv=notrunc bs=512
losetup -d /dev/loop0

63 * 512 = 32256

Copy the NTFS partition data onto the image:

losetup -o8052549120 /dev/loop0 blank.img
dd if=/dev/sda2 of=/dev/loop0 conv=notrunc bs=512
losetup -d /dev/loop0

15727635 * 512 = 8052549120

Copy the MBR onto the image:

losetup /dev/loop0 blank.img
dd if=/dev/sda of=/dev/loop0 conv=notrunc bs=446 count=1
losetup -d /dev/loop0

losetup will not work with qcow images. You will need to use raw images if you want to be able to use losetup. fdisk (and cfdisk and sfdisk) have the same restriction.

How to make a Bochs disk image
Search for "Windows XP rescue disk"

Search for WinPE

Maybe Qemu does not support image with multiple partitions. Lets see if we can get the FAT partition. We may need to have a Windows XP rescue disk ready so that we can mount the NTFS partition and edit the boot.ini
BartPE rescue disc
Back up blank.img, and see if we can boot from the first partition
Re-make another blank.img
Windows live CD
QEMU multi(0)disk(0)rdisk(0)partition(2)\WINDOWS\System32\Drivers
ReactOS, CentOS, FreeBSD

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License