from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Revision as of 23:51, 17 February 2006 by Woozle (talk | contribs) (→‎Some Quick Notes: accessing the img file from Linux)
Jump to navigation Jump to search

Computing: Emulators: Qemu

Qemu is an open source processor emulator. It emulates a variety of different CPUs and systems, and achieves good speed by using dynamic translation.




Creating the disk image

qemu-img create win98hd.img 2G
qemu -hda win98hd.img -cdrom win98.iso -boot d

Accessing the disk image from Linux

In general, assuming the image file was made with the default disk head/sector parameters:

sudo mount -o loop,offset=32256 /path/to/image /path/to/directory/

Specific example (Woozle's system):

sudo mount -o loop,offset=32256 /home/woozle/win98/c.img /mnt/qemu

The reason for the offset is that the image represents an entire disk; you can only mount a partition, not the entire disk. The offset is where the main partition starts. You can find out where partitions are in a disk image by using fdisk:

fdisk /path/to/image

Woozle example:

fdisk /home/woozle/win98/c.img

This takes you to a menu, where you type "p" to get a partition table:

Command (m for help): p

Disk c.img: 0 MB, 0 bytes
64 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 4032 * 512 = 2064384 bytes

Device Boot      Start         End      Blocks   Id  System
c.img1   *           1         520     1048288+   c  W95 FAT32 (LBA)

Based on what I worked out below (which you don't need to read unless that sort of thing interests you), you work this equation to find the correct offset:

[Start] x [bytes-per-sector] x [sectors/track]

...where [bytes-per-sector] is the number after the "*" in "cylinders of..."

(Working backwards from the knowledge that 32256 – which was a Magic Number found by Tenebram – is the correct number, and trying to figure out why it is correct: If we presume that "sectors/track" means the number of sectors per track for a single head, then 4032 (which is 64 x 63) must be the number of sectors per track for all heads, and 512 is probably the sector size in bytes. The offset to a given sector, then (waving a magic wand at all this so that it matches reality somehow) is [start] x [bytes-per-sector] x [sectors-per-track] – which leads us to deduce that the units for the [start] number must be "tracks".)


For linux host systems, there is a loadable kernel module (called kqemu) that will allow qemu to run at near native speeds. At the time of this writing, there aren't distributed packages available with the module built, so you'll need to download the source from the website and compile it locally.

First download the qemu source and untar it. Then download the kqemu source and untar it within the qemu source directory. Then run ./configure && make && sudo make install. You might also want to install the vgabios package from your package manager.

Editor's note: I had this -- "If you're wanting to run Windows 98 under qemu, this option is moot because kqemu and Win98 don't get along." written here, but I think that only applies to kqemu and maybe qemu-fast (I'm not clear on what the difference is between the two).