How to put DOS on an USB drive using linux

Having a bootable DOS partition on an USB drive can be necessary for flashing the BIOS of your motherboard or RAID controller (since most recent PCs come without a floppy drive). However the official way to do this requires you to have already a DOS bootable partition. Fortunately there're a couple of solutions in case you've only a running linux system. The linked page has the best description of the qemu+FreeDOS method (the one that I prefer) and lists various other approaches as well. To keep the instructions safe, I made a copy of them here.

Prerequisites:

Procedure (assumptions for this description: balder10.img is in CWD, stick appears as /dev/sdc):
  • Insert memory stick (Caution: all data on this stick will be destroyed)
  • Find out device name (e.g. /dev/sdc)
  • Make sure it's not mounted (check with mount command)
  • Clear the MBR:
    dd if=/dev/zero of=/dev/sdc bs=1012 count=2
  • Boot qemu:
    qemu -curses -boot a -fda ./balder10.img -hda /dev/sdc
    The -curses option will make it run in text mode.
    (This way you can run qemu easily eg. over an ssh connection.)
  • Answer all questions with their default values
  • At the A:\> prompt:
    fdisk
    (create a bootable, primary DOS partition)
  • Stop qemu
  • Remove memory stick and re-insert it.
  • Make sure it's still /dev/sdc, otherwise use new name in the next steps.
  • Make sure again that it is not mounted.
  • Boot qemu:
    qemu -curses -boot a -fda ./balder10.img -hda /dev/sdc
  • At the A:\> prompt:
    format c: /s
  • At the A:\> prompt:
    xcopy a: c: /n /e
  • Stop qemu
Done! Now you can mount the stick again and copy any required utilities on it ...


P.S.: of course you can use an MS bootdisk image too, but FreeDOS is usually up to the task (and in some aspects it's even better).