This is for my own reference more than anything else; periodically I find myself needing to boot DOS. Usually because I want to upgrade a BIOS and the upgrade tool only works with Windows or DOS. Yes, I’m aware of flashrom, but the scary messages about toasting laptops means I’m much happier going the DOS route there. So I need a writable medium with a DOS boot image. The easy way to do it is to find a DOS floppy image and write that to a USB stick with dd, but it’s basically a one off and means you can’t fit a whole lot on the image. I wanted to do a native USB boot. The following did the trick for me.

Firstly, this is all on a Debian testing box, in particular with dosfstools (3.0.9-1), mbr (1.1.11-4) and syslinux (2:4.04+dfsg-2). I don’t think I’m using anything particularly new from these tools, so I suspect Debian stable will work just fine.

In the below my USB stick is on /dev/sdb, I’ve got a copy of FreeDOS in ~/FreeDOS/ (I extracted the files from a balder10.img floppy image that’s easy enough to find, but all you need is kernel.sys and command.com), and I wanted things neatly in their own subdirectories so I could try and keep the key for repeated use and know which bits I wanted to keep and which were transient. I also added a copy of the Debian Installer for convenience; it would need a copy of the netinst ISO dropped into the root to actually be useful, as there’s not enough to do a full netboot from the wider Internet using just the HD initrd.

    # Create a single bootable LBA VFAT partition spanning entire stick.
    echo 0,,C,* | sfdisk /dev/sdb
    # Format as VFAT and give it a disk label.
    mkfs.vfat -n 'DOS BOOT' /dev/sdb1
    # Install an MBR
    install-mbr /dev/sdb
    # Mount it and create some directories for our files.
    mount /dev/sdb1 /media/DOS\ BOOT/
    cd /media/DOS\ BOOT/
    mkdir boot
    mkdir boot/syslinux/
    mkdir FreeDOS
    # Copy the chain.c32 syslinux tool over.
    cp /usr/lib/syslinux/chain.c32 boot/syslinux/
    # Copy FreeDOS over and move the important bits to /
    cp ~/FreeDOS/* FreeDOS/
    mv FreeDOS/command.com .
    mv FreeDOS/autoexec.bat .
    mv FreeDOS/fdconfig.sys .

    # Add the Debian Installer
    mkdir boot/d-i/
    cd boot/d-i/
    wget http://cdn.debian.net/debian/dists/squeeze/main/installer-amd64/current/images/hd-media/initrd.gz
    wget http://cdn.debian.net/debian/dists/squeeze/main/installer-amd64/current/images/hd-media/vmlinuz

    # Install syslinux
    syslinux -d boot /dev/sdb1

I made a boot/syslinux.help file containing:

    Available boot options are: FreeDOS d-i

and a boot/syslinux.cfg with:

    prompt 1
    display syslinux.help
    default FreeDOS

    label FreeDOS
    	COM32 /boot/syslinux/chain.c32
    	APPEND freedos=/FreeDOS/kernel.sys

    label d-i
    	KERNEL /boot/d-i/vmlinuz
    	INITRD /boot/d-i/initrd.gz

Initial testing was done using kvm which was a lot easier than constantly rebooting my laptop.

Hopefully this is of help to someone. The only neat bit that I didn’t see elsewhere when I was looking was the use of chain.c32 to load kernel.sys rather than having to use a FreeDOS provided boot sector image.