There are a number of guides online that show one how to create DOS bootable USB floppy disks, but these all follow the same theme:
The problem with that is that you're stuck with two things:
The other problem is that a lot of these guides are written for Windows. This one is for FreeBSD!
I've had more than one occasion where a firmware update simply couldn't fit into 1.44 MB, even after deleting everything but io.sys, msdos.sys, and command.com.
So I decided to figure out how to create a bootable DOS hard disk manually. One key difference between a hard disk and a floppy disk in this context is that the hard disk has an MBR and so can have multiple partitions - one for your bootable DOS image, another for the rest of your USB stick. The other difference is that hard disk partitions can be much larger than 1.44 MB. By setting up your USB stick like this you could even have multiple OSes installed with a boot manager to select between them, or just have a small DOS partition and another for your normal data.
So the first thing you need to do is setup your MBR and partition table. There are some limitations with DOS in that its boot partition can't start beyond a certain offset on the disk. For simplicity I'll only be showing you how to set things up with your DOS partition at the beginning of the disk, but feel free to experiment.
All commands assume your USB disk is at /dev/da0. Adjust accordingly. Before you begin you will need:
Step 1: Wipe your disk
Step 2: Create MBR and partitions
I'll be creating a 64 MB FAT16 partition. If you experiment with the size you might need to adjust the partition type. See here for a guide on partition types. I'm also using the basic, active partition chainloading boot manager at /boot/mbr, but you could try /boot/boot0 too.
Results:
Step 3: Create file system and system boot files
Decompress the attached bootsect.gz file:
It's important that you follow the next few steps precisely. Veering off from these instructions may cause the file system to be created incorrectly.
Take note of the start offset of the partition you created above. In this example it is 63. Create the file system:
You'll notice above the partition offset goes in the "-o" parameter. Make sure you specify a full path to the bootsect file or else newfs_msdos(8) will look in /boot.
Mount your file system:
Setup system files root directory entries:
The order of the files above and their uppercase names is crucial.
Copy valid system files to your file system:
(I haven't shown you where/how to get the above system files on purpose - they could come from many sources...)
Unmount:
You're done for now. You should be able to boot up with your USB stick now.
More details coming...
- Obtain preformatted floppy image.
- Write image to USB stick.
The problem with that is that you're stuck with two things:
- A DOS file system that can never hold more than 1.44 MB of data (ok, 2.88 MB if you manage to find a 2.88 MB image file).
- A USB stick that is useless for anything else unless you reformat it.
The other problem is that a lot of these guides are written for Windows. This one is for FreeBSD!
I've had more than one occasion where a firmware update simply couldn't fit into 1.44 MB, even after deleting everything but io.sys, msdos.sys, and command.com.
So I decided to figure out how to create a bootable DOS hard disk manually. One key difference between a hard disk and a floppy disk in this context is that the hard disk has an MBR and so can have multiple partitions - one for your bootable DOS image, another for the rest of your USB stick. The other difference is that hard disk partitions can be much larger than 1.44 MB. By setting up your USB stick like this you could even have multiple OSes installed with a boot manager to select between them, or just have a small DOS partition and another for your normal data.
So the first thing you need to do is setup your MBR and partition table. There are some limitations with DOS in that its boot partition can't start beyond a certain offset on the disk. For simplicity I'll only be showing you how to set things up with your DOS partition at the beginning of the disk, but feel free to experiment.
All commands assume your USB disk is at /dev/da0. Adjust accordingly. Before you begin you will need:
- The attached bootsect.gz file.
- A bootable DOS floppy image, or any source of io.sys, msdos.sys, and command.com (an MS-DOS 6.22 image from http://www.bootdisk.com/ is one option).
Step 1: Wipe your disk
# dd if=/dev/zero of=/dev/da0 bs=1m count=2
Step 2: Create MBR and partitions
I'll be creating a 64 MB FAT16 partition. If you experiment with the size you might need to adjust the partition type. See here for a guide on partition types. I'm also using the basic, active partition chainloading boot manager at /boot/mbr, but you could try /boot/boot0 too.
# gpart create -s MBR da0
# gpart add -s 64m -t \!6 da0
# gpart set -a active -i 1 da0
# gpart bootcode -b /boot/mbr da0
Results:
Code:
# gpart show da0
=> 63 32014017 da0 MBR (15G)
63 131040 1 !6 [active] (64M)
131103 31882977 - free - (15G)
Step 3: Create file system and system boot files
Decompress the attached bootsect.gz file:
# gunzip bootsect.gz
It's important that you follow the next few steps precisely. Veering off from these instructions may cause the file system to be created incorrectly.
Take note of the start offset of the partition you created above. In this example it is 63. Create the file system:
# newfs_msdos -B /full/path/to/bootsect -o 63 /dev/da0s1
You'll notice above the partition offset goes in the "-o" parameter. Make sure you specify a full path to the bootsect file or else newfs_msdos(8) will look in /boot.
Mount your file system:
# mount_msdosfs /dev/da0s1 /mnt
Setup system files root directory entries:
# cd /mnt && touch IO.SYS MSDOS.SYS COMMAND.COM
The order of the files above and their uppercase names is crucial.
Copy valid system files to your file system:
# cp io.sys msdos.sys command.com /mnt/
(I haven't shown you where/how to get the above system files on purpose - they could come from many sources...)
Unmount:
# umount /mnt
You're done for now. You should be able to boot up with your USB stick now.
More details coming...