Qemu is a fast cpu emulator using dynamic translation to achieve good emulation speed. Unlike VMWARE and Win4Lin, it emulates the cpu instead of only virtualizing the computer. This means that it is considerably slower, but on the other hand it is much more portable, stable and secure. Plus it is opensource. It is great solution if you want to run some simple Windows applications like MS Office on a fast PC and you want to ensure maximum compatibility. It is also a great tool for operating system development. This HOWTO describes how to set up the emulator and install Windows 9x/2000 under it.
Qemu has the homepage at http://fabrice.bellard.free.fr/qemu/.
- 1 Choosing Qemu version
- 2 Choosing Windows version
- 3 Installing QEMU
- 4 Creating the hard disk image
- 5 Preparing the installation media
- 6 Installing the operating system
- 7 Running the system
- 8 Moving data between host and guest OS
- 9 Optimizing Windows 9x CPU usage
- 10 Using the QEmu Accelerator Module
Choosing Qemu version
The current qemu version is 0.7.1. However, you should consider installing a cvs version of qemu if the emulated machine is supposed to run under Windows 2000 (or previous NT versions). It is also advised to apply a patch which can be found at http://www.dad-answers.com/qemu/patches/win2k-diskfull-fix/ - otherwise you'll have problems during OS installation. The patch is not needed in the CVS version of qemu (as of 18th April 2006), if you want to use that instead. The CVS version does also give you the benefits of the latest kqemu module, which improves performance a lot.
Choosing Windows version
Qemu can run any version of Windows. However, 98, Me and XP will run at quite a low speed. You should choose either Windows 95 or Windows 2000. Suprisingly, 2000 seems to run faster than 98. The fastest one is 95, which can from time to time make you forget that you are running an emulator :)
If you own both Win95 and win98/winme, then 98lite (from http://www.litepc.com) might be worth trying. It decouples Internet Explorer from operating system and replaces it with original Windows 95 Explorer. It also enables you to do a minimal Windows installion, without all the bloat you normally cannot disable. This might be the best option, because you get the smallest, fastest and most stable Windows this way.
QEMU is a [community] package in the AUR: http://aur.archlinux.org/packages.php?do_Details=1&ID=742. To install it, add the community repo to /etc/pacman.conf, and do
pacman -Sy qemu.
You can also install the optional kernel accelerator module kqemu. This is built from source - full details in the AUR here: http://aur.archlinux.org/packages.php?do_Details=1&ID=1011.
Creating the hard disk image
To run qemu you will probably need a hard disk image. This is a file which stores the contents of the emulated hard disk.
Use the command:
qemu-img create -f qcow win.qcow 4G
to create the image file named "win.qcow". The "4G" parameter specifies the size of the disk - in this case 4 GB. You can use suffix M for megabytes (for example "256M"). You shouldn't worry too much about the size of the disk - the qcow format compresses the image so that the empty space doesn't add up to the size of the file.
Preparing the installation media
The installation CD-ROM/floppy shouldn't be mounted, because Qemu accesses the media directly. It is a good idea to dump CD-ROM and/or floppy to a file, because it both improves performance and doesn't require you to have direct access to the devices (that is, you can run Qemu as a regular user). For example, if the CD-ROM device node is named \"/dev/cdrom\", you can dump it to a file with the command:
dd if=/dev/cdrom of=win98icd.iso
Installing the operating system
This is the first time you will need to start the emulator. One thing to keep in mind: when you click inside qemu window, the mouse pointer is grabbed. To release it press Ctrl+Alt.
If you need to use a bootable floppy, run Qemu with:
qemu -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]
If your CD-ROM is bootable, run Qemu with:
qemu -cdrom [[cdrom''image]] -boot d [[hd''image]]
Now partition the virtual hard disk, format the partitions and install the OS.
A few hints:
- If you are using Windows 95 boot floppy, then choosing SAMSUNG as the type of CD-ROM seems to work
- There are problems when installing Windows 2000. Windows setup will generate a lot of edb*.log files, one after the other containing nothing but blank spaces in C:\WINNT\SECURITY which quickly fill the virtual harddisk. A workaround is to open a Windows command prompt as early as possible during setup (by pressing Shift-F10) which will allow you to remove these log files as they appear by typing :
Running the system
To run the system simply type:
A good idea is to use overlay images. This way you can create hard disk image once and tell Qemu to store changes in external file. You get rid of all the instability, because it is so easy to revert to previous system state :)
To create an overlay image, type:
qemu-img create -b [[base''image]] -f qcow [[overlay''image]]
Substitute the hard disk image for base_image (in our case win.qcow). After that you can run qemu with:
and the original image will be left untouched.
Moving data between host and guest OS
If you have servers on your host OS they will be accessible with the ip-address 10.0.2.2 without any further configuration. So you could just FTP or SSH, etc to 10.0.2.2 from windows to share data, or if you would like to use samba:
Qemu supports SAMBA which allows you to mount host directories during the emulation. It seems that there is an incompatibility with SAMBA 3.x. and some versions of qemu. But at least with a current snapshot of qemu it should be working.
First, you need to have a working samba installation. Then add the following section to your smb.conf:
[qemu] comment = Temporary file space path = /tmp read only = no public = yes
Now start qemu with:
qemu [hd_image] -smb qemu
Then you should be able to access your host's smb-server with the ip-address 10.0.2.2. If you're running Win9x as guest OS, you may need to add
Mounting the hard disk image
Fortunately there is a way to mount the hard disk image with a loopback device. Login as root, make a temporary directory and mount the image with the command:
mount -o loop,offset=32256 [[hd''image]] [[tmp''dir]]
Now you can copy data in both directions. When you are done, umount with:
The drawback of this solution is that you cannot use it with qcow images (including overlay images). So you need to create you images without \"-f qcow\" option. Tip: create a second, raw hardrive image. This way you'll be able to transfer data easily and use qcow overlay images for the primary drive.
REMEMBER: never run qemu when the image is mounted!
Optimizing Windows 9x CPU usage
Windows 9x doesn't use hlt instruction, so the emulator always eats up 100% CPU even if no computation is being done. Grab the file http://www.user.cityline.ru/~maxamn/amnhltm.zip, unpack it, copy it to the image and run the .bat file.
Using the QEmu Accelerator Module
The developers of qemu have created an optional kernel module to accelerate qemu to sometimes near native levels. This should be loaded with the option
to automate the creation of the required /dev/kqemu device. The following command
echo "install kqemu modprobe -i kqemu major=0" >> /etc/modprobe.conf
will amend modprobe.conf to ensure that the module option is added every time the module is loaded.