Bootable DOS USB stick

Many firmware loading programs on PCs require a DOS environment to function. Moreover, most computers no longer have floppy drives, and many do not even have CD drives. Therefore, it can be useful to have a bootable USB stick which loads DOS. This page describes how to prepare such a stick using tools available in Portage.

Wiping
It is advisable to wipe the USB stick before loading it with a new environment. If the USB stick is at /dev/sdb, this can be done with where COUNT is replaced with the size of the USB stick in MiB.
 * 1) dd if=/dev/zero of=/dev/sdb bs=1M count=COUNT

Partitioning
The stick must now be partitioned. Most any partitioning tool can be used, such as cfdisk. In this article we assume that the first partition is to be used for this application. This partition should be marked bootable and its type set to FAT16.

Boot sector
Using ms-sys from the package sys-block/ms-sys, we now prepare the boot sector on the USB stick with

This writes a public domain boot sector compatible with DOSEMU which we will use below.

Formatting
Finally, using mkdosfs from the package sys-fs/dosfstools, format this partition as FAT16 with

Note that the maximum file system size under FAT16 is 4GiB. It should also possible to load a DOSEMU environment from FAT32, though this author has not tried it.

Loading a DOS environment
We will now use DOSEMU to create a DOS environment in the USB stick. If DOSEMU is not already on your system, install app-emulation/dosemu.

Configuring DOSEMU
Edit ~/.dosemurc
 * Add the USB partition you prepared to the list of "hdimages" in the DOSEMU configuration file ~/.dosemurc:


 * Make sure the USB stick is not already mounted, e.g through your desktop environment file manager, as DOSEMU requires block-level access. This means that DOSEMU must be invoked as root, unless the permissions of the device file have been modified.

Setting up DOS with DOSEMU
C:\>sys F:
 * After starting DOSEMU, the disk should appear as F:. Make the USB partition a DOS boot disk with

C:>xcopy /s /n D: F: Note that to prevent problems with booting and conflicts between drivers and firmware software, this author recommends editing config.sys and autoexec.bat to be minimal. For example: config.sys
 * To have a usable DOS environment, it is helpful to copy over tools from DOSEMU into the disk:

autoexec.bat To edit these files within DOSEMU, use the tool edit. If editing from Linux, take care to make sure that the files retain their DOS-style CR+LF newlines.

Checking with QEMU
You can check that the USB stick is bootable without actually rebooting your computer by using QEMU (app-emulation/qemu in Portage):

Keep in mind that this is no guarantee that your BIOS will boot the computer off the USB stick successfully, only a check that you've done things correctly.

Load your firmware software
Just mount the USB stick as you would normally, and copy over the necessary software -- good luck!

Possible improvements
To have a bootable DOS partition as well as a bootable Linux partition (e.g., SystemRescueCD) on the same disk, a bootloader setup more sophisticated than mbr-sys is required. This can be done with GRUB, as described in another HOWTO.