Bootable FreeDOS USB stick/CF Card

Today I needed to create a bootable USB stick that does nothing else but just a reboot of the machine.

Why? The machine is booting up from network, but the problem is what happens when the network is down or doesn’t reply fast enough. Unfortunately, the PXE didn’t have the option of booting in an endless loop.

The solution is to:

  1. try boot from the network first
  2. fall back to booting from USB/CF and reboot the machine


Now, a quick howto on how to create a system like that:

Plug in your USB stick or CF card to the machine. I’m assuming it is found under /dev/hda in your system.

Then:

  • With fdisk, create a FAT32 partition, make it active (bootable) and write changes. It should look like this afterwards:
Disk /dev/hdb: 8119 MB, 8119738368 bytes
64 heads, 32 sectors/track, 7743 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        7743     7928816    c  W95 FAT32 (LBA)

  • Then create a dos FS on the partition with
mkdosfs /dev/hda1
  • Install a master boot record (MBR)
install-mbr /dev/hda
  • and install a minimal syslinux system. This can be done using the script that can be found here (originally from here) with a command:
syslinux.pl –disk=/dev/hda1 –lba –offset=32

where the offset is the number from ” 32 sectors/track” of the fdisk output.

  • last but important step, from a FREEDOS image, extract and copy at least the files command.com and kernel.sys. To do that, simply download a freedos iso image from FREEDOS site, and then mount it somewhere with a command:
mount -o loop /root/freedos.iso /mnt/freedos

and then you can copy the files to the /dev/hda1 (which you also have to mount somewhere (-; )

That’s it! You have now a bootable USB stick/CF Card.

Now, the trick to make it reboot. Create an AUTOEXEC.bat file (ahh those old DOS days…), and inside type:

echo g=ffff:0000 | debug

And that’s all, it should work fine.

Expected problems:

  • If the systems hangs on “MBR” state when trying to boot, try to invoke syslinux.pl with custom parameters for cylinders, heads and offset, e.g. for the fdisk output above, the offset would be 32, and heads 64.

One Response to “Bootable FreeDOS USB stick/CF Card”

  • Hi,

    You can use also hex editor to write the reboot code directly to the MBR or bootsector. This way the reboot is a bit quicker without the syslinux and FreeDOS bootstrap. Just insert EA 00 00 FF FF, which is the same code you piped into debug to do the same thing. For the MBR, put it in the first five bytes; for the bootsector, the first two bytes will be e.g. EB 58 so add two to the second byte to get your offset within the bootsector e.g. 5A and write the code there. Also with your method using a pipe to debug, FreeDOS will write a temporary file every time.

Leave a Reply