Skip to content

Disk Images

nepx edited this page Dec 29, 2020 · 5 revisions

Disk Images

The emulator supports loading images from two different sources -- raw disk images and compressed chunks. The disk image geometry and BIOS translation modes are automatically detected.

Compressed Chunks (async driver)

This mode was designed specifically for use with Emscripten, to decrease bandwidth use and make it easier to load sections of files on demand. Disk images are split into 256 KB chunks and then compressed with zlib. Not only does it save bandwidth, it also saves disk space: my 2 GB Windows XP disk image compresses down to 760 MB.

It's called an "asynchronous" driver because the chunks load asynchronously, via XHR. The native version also loads the chunks asynchronously by default.

tools/imgsplit.js takes a disk image, chunks it up, compresses it, and emits a little bit of metadata for the disk driver to consume. Running node tools/imgsplit.js os2.img will produce a directory called os2 which you can pass to Halfix:

[ata0-master]
inserted=1
type=hd
driver=async # This is not needed, the driver type is async by default
file=os2

To use them on Emscripten, pass the appropriate query parameter. For example, to set the first hard disk drive to os2, pass ?hda=os2. There are four drives:

  • hda: Primary ATA, master (ata0-master)
  • hdb: Primary ATA, slave (ata0-slave)
  • hdc: Secondary ATA, master (ata1-master)
  • hdd: Secondary ATA, slave (ata1-slave)

You can also change hd to cd (for instance, cdc for secondary ATA, master) to load a chunked CD-ROM image.

Raw images (sync driver)

Raw images are exactly what they sound like -- a large file containing the exact data that a physical hard drive or CD-ROM would contain. It's called a "sync" driver because accesses happen synchronously. Here's part of the configuration that I used to install Windows XP in Halfix:

# "xp.img" is a 2 GB disk image
[ata0-master]
inserted=1
type=hd
driver=sync # or driver=raw
file=xp.img
writeback=1

# "xp.iso" is an iso file produced from a Windows XP installation CD-ROM
[ata0-slave]
inserted=1
type=cd
driver=sync
file=xp.iso

This is the only format where disks larger than 4 GB are supported at the moment. The largest disk that I've ever tried using in Halfix is 10 GB, for Windows 10.

Loading raw disk images via XMLHttpRequest is not supported by the Emscripten version (not all HTTP servers support the Range header, which is needed for partial loads, and fewer support compression). They will need to be chunked up and passed through one of the hda/hdb/etc. options. You can, however, feed the emulator a raw disk image via a file upload. It's also possible to mix and match XHR and file upload: the boot disk can sit on a remote server and a CD-ROM full of games and apps loaded from your local system, for instance.

Modifying Disk Images

Disk images are not modified by default. All writes are cached in memory and are discarded when you exit. This is a good option when you don't want your image to be corrupted by a sudden power-off or emulator bugs. In certain cases, like operating system installs, you definitely want your disk image to be writable. Note that only raw disk images are writable.

By default, writing back to disk is disabled to prevent the image from being corrupted. In many cases, you may want to avoid writing to the image so that you can pull the metaphorical plug on the computer at any time (i.e. exiting the page) and avoid corrupting the disk image. In some instances, however, you may indeed want to modify the image, like if you're installing an operating system. Use writeback=1 to allow this.

This option will have no effect on drives configured as CD-ROMs, since they're read-only by design.

inserted vs type

type determines the type of drive attached to the IDE controller, either hard drive, CD-ROM, or nothing. Even if no media is inserted into the drive, the controller is still going to send responses back to the guest as if an (empty) drive was attached to the controller. If type is set to none, then the IDE controller will act as if there is no drive attached -- and all other options will be ignored.

inserted simply determines whether the media is present or not. It does not determine whether the drive is attached to the controller or what kind of drive it is, only whether emulated media is present in the drive. inserted=0 is like having an empty CD-ROM drive. 'inserted=1` is like inserting one into a drive.

On the browser version, set the value of the associated query parameter to none to simulate the behavior of inserted=0: i.e. ?cdb=none.

For instance, my installation of Windows NT expects a hard drive attached to ata0-master and a CD-ROM drive on ata0-slave or else it BSODs. Thus, my configuration file looks like this:

[ata0-master]
type=hd
inserted=1
file=disks/nt-chunks
[ata0-slave]
type=hd
inserted=0
# The following two lines are optional. You can leave them out if you want. 
driver=sync
file=disks/nt-install.iso
[ata1-master]
type=none
[ata1-slave]
type=none

This setup will simulate exactly two drives -- a hard drive and CD-ROM -- attached to ata0-master and ata0-slave. The CD-ROM drive is currently empty and has no media in it, but Windows NT can still detect that a CD-ROM drive is present.