Here's what I do to customise FreeDOS images:
start with a bootable floppy image that I downloaded from the Freedos site. Unfortunately it's full of stuff I don't need just to run some once-off utility like a BIOS updater.
mount a copy of it with:
mkdir -p ./floppy
cp -a ./freedos-1440kb.img freedos-empty.img
mount -o loop,rw freedos-empty.img ./floppy
cd ./floppy and delete everything that isn't needed. This should end up with about 1.2 or 1.3MB free on the 1.44MB image.
cd .. ; umount ./floppy
That gives me an almost empty bootable image which I can use to make as many custom images as I want. I then make a copy of that and then copy whatever I need on to it. e.g.
cp -a ./freedos-empty.img ./freedos-spinrite.img
mount -o loop,rw freedos-spinrite.img ./floppy
cp spinrite.exe ./floppy
umount ./floppy
This image can then be copied to a floppy drive, flash drive, etc. e.g. cat freedos-spinrite.img > /dev/sdX (where sdX is the device node for your USB stick). I almost never bother doing this because I can never find an empty, usable flash drive when I need one....it's also more work and takes longer than using grub or tftp menus. And it's slower to boot a USB stick than a disk image stored on the local hard disk or on my tftp server.
In my case, I copy it to my /boot/images/ directory and run update-grub...and then use scp to copy it to other machines where it might be needed and run update-grub on them too via ssh.
I also copy it to my /var/lib/tfptboot/freedos/ and run a script I wrote to generate menu entries for all *.img files in that directory.
This lets me boot the freedos image from the grub menu at boot up, AND over the network via ipxe and tftp on any machine that has a "boot from network card" option at boot time (i.e. almost all machines these days. All if you include the fact that ipxe can be booted from grub too).
I've used this to build bootable images for updating BIOSes on motherboards, reflash LSI SAS cards into IT mode, and apply firmware updates to, e.g., some Seagate hard disks.
BTW, this is why I like to make "over-sized" /boot partitions (1 or 2GB or more) - so I can boot any image of any "reasonable" size. Also so that I don't run out of space in /boot and have to clear out my old kernel images all the time. It's also useful for, e.g., booting gparted or clonezilla images.
Extra stuff: setting up grub
Setting up tftp for this is a fair bit of work initially so I won't go into that here (I'm pretty sure I've described the process in another answer on this site, and my tftp scripts are on my github account - but I haven't uploaded the memdisk/freedos scripts), but there's very little that needs to be done for grub:
- install
syslinux (or at least, get a copy of the memdisk binary from it).
cp memdisk /boot
- mkdir -p /boot/images
- copy your bootable
*.img, *.iso image file(s) into /boot/images.
- copy the script
42_memdisk (see below) into /etc/grub.d/ and make it executable with chmod +x /etc/grub.d/42_memdisk
- run
update-grub as root
Note: the above works for Debian and most related/derivative distributions like Ubuntu and Mint. Other distros have slightly different setups for grub, so you'd have to adjust the procedure accordingly.
memdisk can boot any disk image that's bootable - from floppy images to CD-ROM/DVD images, to hard disk images.
42_memdisk (this is the script that does the work of generating menu entries for grub):
#!/bin/sh
set -e
IMAGES=/boot/images
. /usr/lib/grub/grub-mkconfig_lib
if test -e /boot/memdisk ; then
echo "Found memdisk: $MEMDISKPATH" >&2
MEMDISKPATH="$( make_system_path_relative_to_its_root "/boot/memdisk" )"
find "$IMAGES" -name '*.img' -o -name '*.iso' | sort |
while read image ; do
IMAGEPATH="$( make_system_path_relative_to_its_root "$image" )"
echo "Found image: $IMAGEPATH" >&2
cat << EOF
menuentry "Bootable image: $(basename $IMAGEPATH | sed -E -e 's/\.(img|iso)$//i')" {
EOF
prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e 's/^/\t/'
cat << EOF
linux16 $MEMDISKPATH bigraw
initrd16 $IMAGEPATH
}
EOF
done
fi
IIRC, this is modified from a script I found somewhere years ago while googling how to do stuff like this (I can't remember where).
Example output:
# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.14.0-2-amd64
Found initrd image: /boot/initrd.img-4.14.0-2-amd64
Found linux image: /boot/vmlinuz-4.14.0-1-amd64
Found initrd image: /boot/initrd.img-4.14.0-1-amd64
Found linux image: /boot/vmlinuz-4.12.0-2-amd64
Found initrd image: /boot/initrd.img-4.12.0-2-amd64
Found iPXE image: /boot/ipxe.lkrn
Found memtest86 image: /memtest86.bin
Found memtest86+ image: /memtest86+.bin
Found memdisk:
Found image: /images/LSI.img
Found image: /images/Seagate-PH-CC49.img
Found image: /images/fd-asus-m5a97.img
Found image: /images/freedos-empty.img
done