Monday, September 13, 2010

Add bootable DOS support to your USB stick

Building on the previous post where we added SystemRescueCD capabilities to our USB stick (please see that post for details and conventions that pertain to this one as well) while still being able to use it for transferring files between various OS, we will now add bootable DOS support so that we can use it for BIOS updates as well as other DOS based tools such as Intel's SSD firmware updater.

I was frustrated by other methods I found when researching. One needed my whole USB stick, which was undesirable and another using a pre-built image with no control over the config.sys, etc. left me in a pseudo floppy mode (A:\ drive) and also crashed on a regular basis. There had to be a better way. I wanted the whole nine yards - one USB stick for system rescue, BIOS/firmware upgrades, and file transfer between Windows and 'nix systems. A veritable digital swiss army knife! This way you get full control over the config.sys and autoexec.bat files. New embedded systems without floppy and CD/DVD drives really helped make the case for solving this issue without purchasing new hardware to drag around.

This post will have less hand-holding than the previous one. Hopefully the detail provided previously will get you through this post without problems.

For enhanced flexibility we'll use a separate "/boot" partition. This will allow for easily updating the SystemRescueCD and other partitions with new/updated data without disturbing the installed GRUB files.

We'll need two more products: FreeDOS (download the fdfullcd.iso) and install makebootfat (your distro most likely has this packaged).

Create a working directory for the necessary FreeDOS files and loop mount the FreeDOS iso.
  • mkdir fdwrk
  • mkdir fdboot
  • mount -o loop /path/to/fdfullcd.iso /mnt/loop
Copy (as a minimum) the files:
  • kernel.sys
  • himem.exe
  • more.exe
 from /mnt/loop/freedos/setup/odin to your fdwrk directory.

Create or copy a config.sys file (necessary to load the command interpreter) to your fdwrk directory:
Example config.sys file:

Create or copy an autoexec.bat file (the simple one below will avoid the date/time prompt) to your fdwrk directory:
Example autoexec.bat file:

Make sure your config.sys and batch files use DOS/Windows line termination - CR+LF and not just LF as is standard with 'nix systems.

Copy the file:
  •  /source/ukernel/boot/fat16.bin
 from inside the /mnt/loop/freedos/packages/src_base/ file to the fdboot directory.

Instead of just two partitions as in the previous post we will make 4. Basically the same instructions but partitions 2 & 3 can be pretty small. I made them both 128M which really is overkill but I don't need the space that bad. I used:
  1. 6500M type "c" FAT32LBA (for file sharing - must be first partition, sde1/hd4,0)
  2. 128M type "e" FAT16 (the DOS partition, sde2/hd4,1)
  3. 128M type "83" Linux (the /boot partition - where grub resides, sde3/hd4,2)
  4. 800M (or remaining space) type "83" Linux (the SystemRescueCd partition, sde4/hd4,3)
Format partition 1 as previously, format partitions 3 & 4 as we did partition 2 previously. Format partition 2 as fat16:
  • mkfs.vfat -F16 /dev/sde2
Mount the linux partitions on available mountpoints:
  • mount -t ext4 /dev/sde3 /media/usbstickgrub
  • mount -t ext4 /dev/sde4 /media/usbsticksysrescue
Copy the SystemRescueCD files to /media/usbsticksysrescue:
  • cp -a /where.your.System.RescueCD.files.are/* /media/usbsticksysrescue/*

Prepare /media/usbstickgrub:
  • mkdir -p /media/usbstickgrub/boot/grub
  • cp -a /lib/grub/<distro-specific>/* /media/usbstickgrub/boot/grub
Add the FreeDOS entry to the grub's menu.lst file we created in the previous post (/media/usbstickgrub/boot/grub/menu.lst):
timeout 10

title SystemRescueCD 32bit
kernel (hd0,3)/isolinux/rescuecd
initrd (hd0,3)/isolinux/initram.igz

title SystemRescueCD 64bit
kernel (hd0,3)/isolinux/rescue64

initrd (hd0,3)/isolinux/initram.igz

title FreeDOS
rootnoverify (hd0,1)
chainloader +1

Install grub:
  • grub
  •   grub> find /boot/grub/menu.lst (will help identify the root partition)
  •   grub> root (hd4,2)    (specify our new /boot partition)
  •   grub> setup (hd4)     (install GRUB in the USB stick's MBR)
  •   grub> quit
Prepare our bootable DOS partition:
  • makebootfat -P -o /dev/sde2 -b /path/to/fdboot/fat16.bin /path/to/fdwrk
When this is complete you can mount the DOS partition and add any other files you want. You could have also placed these in fdwrk and they would have been added by the makebootfat process.

The nice thing about this method is that when booting into DOS the partition is seen as the C: drive, however, many BIOS/firmware upgrade batch (and config.sys) files may assume you're booting from a floppy and have some hardcoded A:\ paths. Simply edit these files as needed and remove the A:\.

The FreeDOS partition may have to exist under some limit (8GB, 16GB ?). As my USB stick is only 8GB I didn't run into any issues. If you have a larger USB stick you may not have success if your FreeDOS (2nd) partition is beyond such limit.

Please comment on whether you find this information useful or what might be done to improve it. Thank you!


  1. Chris,
    After giving your first tutorial a go, I tried this one and it was great.

    I even took it a bit further put the System Rescue CD in an extended partition and created another partition on the end for an encrypted section.

    Here is my partition table now:
    sdc1 25GB - FAT32
    sdc2 128M - FreeDOS (FAT32)
    sdc3 128M - Grub2 (ext4)
    sdc4 - extended
    sdc5 800M - System Rescue CD (ext4)
    sdc6 5GB - Encrypted partition (ext4)

    BTW FreeDOS does boot after the 25GB partition.

  2. Thanks map7, good to know that FreeDOS boots from a partition beyond 25GB.

  3. I had to use the -X option to make the makebootfat command work on Fedora 12. Otherwise, it assumed a FAT32 partition and failed with error:
    Invalid code start 3E in the boot sector (for fat32 it must be at least 5A).

  4. OK I install as you explain above. When I boot to DOS it fails like this (after the heading info):
    C: HD1, Pri[ 1], CHS= 0-1-1, start= 0 MB, size= 2505 MB
    Bad or missing Command Interpreter: /P /E:256
    Enter the full shell command line:

    (Sysrescue CD works fine so I am sure Grub etc is working correctly. I copied all the files you list.) I have been searching the web for the fix without any result. Any ideas? Thanks.

  5. @leek was one of the files that needed to be copied to your fdwrk directory - makebootfat should have installed them (although it looks like I typo'd fdwrk as fdwork later on which I will correct now).
    BTW, not all BIOSes are capable of booting FreeDOS like this. With some older system you may have to resort to old school techniques.

  6. Thank you for your reply!
    I did spot that typo and correct it, and I can see that is on the stick, so I have no idea what the problem is.

    The machine is a relatively new one (about a year) and does support boot from USB.

    There is one other small typo on this page where you copy the System Rescue CD files, the destination should not have a * at the end.