Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc



This article shows how to create a customized, bootable DOS USB flash drive using dosemu. It doesn't matter how you call your formerly-known-as-floppy: may you call it USB stick, USB disk, USB drive, flash drive or pen drive.


So you built your new and shiny machine, and you will never let a floppy drive come near it. When was the last time you bought a floppy disk, anyways? But then comes the time when you want to sell your ten year old ISDN PABX, which needs a DOS program to configure it.

Or perhaps you didn't pay attention when you built your new and shiny machine, and now your crappy DVD burner needs a firmware update, and the manufacturer offers only Windows and DOS programs to flash it.


You need a Gentoo install, of course (of course not, but this howto is tailored for Gentoo). I'm not sure whether the machine has to be x86 compatible. Obviously, it should be able to run dosemu and it has to have an USB port. A USB drive is needed, too.

Not all computers can boot from a USB drive, yet. Look in the BIOS setup of your computer to find out whether you can put USB drives into the Boot Sequence. You could also try to boot from your blank USB drive. It should at least come up with a message that it isn't bootable.

There are two ways to prepare a USB drive: either it's formatted like a hard disk, i.e. with an MBR and a partition table, or it's like a superfloppy, i.e. just a plain filesystem.

Alas, some computers can only boot from harddisk-like USB drives, while others can only boot from superfloppy USB drives. We'll come back to this in a minute.


If you haven't done so already, emerge dosemu. After emergeing it, you can start it with dosemu or xdosemu. You'll find a nicely prepared FreeDOS installation on "drive C:", which is ~/dosemu/freedos in reality. On "drive D:" you will find your home directory. Use exitemu to exit dosemu.

Note: Malahal 01:15, 30 October 2007 (UTC): I had to put $_mapping = "mapashm" in .dosemurc file before I could successfully run xdosemu as it tried to mmap with EXEC flag and my /dev/shm is mounted with "noexec" flag.

If you don't have mkdosfs, emerge sys-fs/dosfstools to get it.

In case you need to use harddisk mode, emerge app-admin/mbr to get install-mbr.

Your Gentoo system should already be setup to recognize the USB drive. After plugging in the USB drive, try fdisk -l or mount and look for a /dev/sd* device, e.g. /dev/sdb1. Setting this up is beyond the scope of this howto.

The following two paragraphs are taken nearly verbatim from Without that guide I wouldn't have had a chance to get this working.

Formatting in superfloppy mode

To format the drive in superfloppy format, you simply do:

mkdosfs -I /dev/sdb
Warning: Of course if your USB drive is /dev/sda, use /dev/sda instead.

Formatting in harddisk mode

Formatting in harddisk mode requires more steps, if it's not already formatted that way. Use

dd if=/dev/zero of=/dev/sdb bs=512 count=1

to erase the start of the USB key (and again: if your USB drive is /dev/sda, use /dev/sda instead). After that you can do a cfdisk /dev/sdb and create a new FAT partition (FAT16 is suitable). Make sure you make the partition bootable or this won't work. To install an MBR and format the key afterwards, do

install-mbr /dev/sdb --force
mkdosfs -I /dev/sdb1
Note: Beware that you have to install the MBR to the whole disk /dev/sdb, while you create the DOS filesystem on the partition /dev/sdb1.

Now you should be able to mount your USB drive:

mount /dev/sdb1 /mnt/tmp

Unmount it again with:

umount /mnt/tmp

Installing FreeDOS to the USB drive

To make your USB drive visible in dosemu, add /dev/sdb1 to the $_hdimage variable in the ~/.dosemurc file. The default value for $_hdimage is "drives/*". dosemu expands the filelist in quotes and allocates each item a drive letter in sequence. So e.g. "/drives/* /dev/sdb1" expands to /drives/c /drives/d /drives/e /dev/sdb1 and these 4 items become C: D: E: F:. It seems however that it expects E: to be a cdrom (on /media/cdrom), and that cdrom may not be there. So unless you already have a configured cdrom, you should put a dummy (though existing) path in place of E: drive otherwise /dev/sdb1 will be assigned E: and the cdrom driver will cause problems:

$_hdimage = "drives/* /tmp /dev/sdb1"

Feel free to create ~/.dosemurc if you don't have it already. While you're at it, you can also change the keyboard layout if you need it:

$_internal_char_set = "cp850"
$_X_keycode = (auto)
$_layout = "de-latin1"

See /usr/share/doc/dosemu-*/README.txt.gz to find other values of $_layout.

Now when you fire up xdosemu, you should see your USB drive as a new drive F:

 F: HD3, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=   238 MB 

If xdosemu whines about

 *** device /dev/sdb1 in use, cannot do partition access

you need to unmount the drive. Maybe some kind of automounter has kicked in and mounted your USB drive, so just umount it.

Now that xdosemu can see your drive, you could use edit foo.txt to put some content on it. Leave xdosemu, mount the drive in Linux, look at the file. Hooray!

Putting the rest of the FreeDOS system on the USB drive

Start xdosemu, then change to drive containing kernel.sys (try z:), then use sys f:.

Okay: this will have only put the kernel.sys and files on the drive. But that's enough to boot from. Just leave xdosemu, reboot your machine, and you should see FreeDOS asking you to accept the date and time. You can skip this reboot and just go on with the next step.

Copy the remaining FreeDOS system files with

 xcopy /s /n c: f:

This copies also the config.sys and autoexec.bat. These files have a lot of references to the C: drive. When you boot from the USB drive, it will be recognized as drive A:. So just go to a: (type a:) and edit config.sys autoexec.bat. Replace all occurrences of c: with a:. Use "rem" or ": " to disable the lines that you don't need.


After all of that, you can easily copy your DOS applications to the USB drive. Your Linux home directory is drive D: in dosemu, so just unpack your DOS application into a subdirectory in your home, then start xdosemu and

xcopy /s /n d:\the_dir f:\the_dir

You should also be able to just mount your USB drive and copy the files in Linux.


In case you're wondering where you get all of the DOS programs for your ancient Emmerich Istec 1003 or Istec 1008 ISDN PABX,

is the place to go. That page also has copies of Estic, the wonderful program that once could be compiled in Linux, too.

Eric´s alternative idea

You might also want to try the whole thing without xdosemu... For that, use

to create the boot sector, and use mtools (or simply mount the drive) to copy all files. For Freedos 1.0, that will be kernel.sys,, and the contents of all binary package zips unzipped in the same directory on the flash drive, for example /fdos.

Please send feedback about this suggestion to eric bla where bla is the infamous at sign :-).

Retrieved from ""

Last modified: Fri, 19 Sep 2008 03:21:00 +0000 Hits: 39,744