Creating floppy disk images from folders of data files for VirtualBox

VirtualBox is able to pass floppy disk images (in a format called IMA) to VMs. For a data preservation project, I need to create a lot of those images.

My host system is macOS 11.6 Big Sur, and I have Homebrew tools available.

My data files are on my APFS disk, in a folder hierarchy where every folder contains the files that were originally on the corresponding floppy. Those folders seem to have been created by just copying floppy contents on an old DOS/Win311 machine. Example:

disk1
  file1.ext
  file2.ext
disk2
  another1.txt
  another2.txt

None of the disks need to be bootable, so boot sector creation is irrelevant in this context.

I tried to just create the images using hdiutil, but the resulting image files would not work:

hdiutil create -size 1440k -fs "MS-DOS FAT12" -layout NONE -srcfolder disk2 -format UDRW -ov diskimage2.ima

So, can you suggest a (scriptable, non-interactive) way to go through a folder hierarchy and convert every folder to a disk image for VirtualBox containing that folder's files?


Solution 1:

I executed the command from your question, which is also shown below.

hdiutil create -size 1440k -fs "MS-DOS FAT12" -layout NONE -srcfolder disk2 -format UDRW -ov diskimage2.ima

A hexadecimal/ASCII dump of the BIOS Parameter Block in the diskimage2.ima.dmg file shows the following.

hexdump -s 0xb -n 51 -Cv diskimage2.ima.dmg
0000000b  00 02 01 01 00 02 00 02  40 0b f0 09 00 20 00 10  |........@.... ..|
0000001b  00 00 00 00 00 00 00 00  00 00 00 29 fd 0c e6 34  |...........)...4|
0000002b  44 49 53 4b 32 20 20 20  20 20 20 46 41 54 31 32  |DISK2      FAT12|
0000003b  20 20 20

I used VirtualBox to create a formatted floppy stored in the file Windows_3.1_1.img. A hexadecimal/ASCII dump of the BIOS Parameter Block in the Windows_3.1_1.img file shows the following.

hexdump -s 0xb -n 51 -Cv Windows_3.1_1.img 
0000000b  00 02 01 01 00 02 e0 00  40 0b f0 09 00 12 00 02  |........@.......|
0000001b  00 00 00 00 00 00 00 00  00 00 00 29 16 55 c8 ea  |...........).U..|
0000002b  20 20 20 20 20 20 20 20  20 20 20 46 41 54 31 32  |           FAT12|
0000003b  20 20 20                                          |   |
0000003e

By comparing the two outputs, the following possible problems were found.

  • Maximum number of FAT12 or FAT16 root directory entries at sector offset 0x11. Your value is 512. I was expecting 224.
  • Physical sectors per track at offset 0x18. Your value is 32. I was expecting 18.
  • Number of heads for disks at sector 0x1a. Your value is 16. I was expecting 2.

An image of a unformatted floppy can be made by using the following command.

dd if=/dev/zero of=myfloppy.img bs=512 count=2880

Either of the following commands below can format the floppy with the label MYFLOPPY. This format matches the format used by VirtualBox.

newfs_msdos -v MYFLOPPY -f 1440 -b 512 -S 512 -r 1 -F 12 ./myfloppy.img 

or just

newfs_msdos -v MYFLOPPY -f 1440 ./myfloppy.img

Note: Both commands will produce the following warning message.

newfs_msdos: warning: ./myfloppy.img is not a character device
ioctl(DKIOCGETPHYSICALBLOCKSIZE) not supported

I would suggest using these commands or VirtualBox to create a floppy image. Attach the image, copy some files to the image, eject and then see if your virtual machine can read the image as a floppy.

References

Design of the FAT file system
Creating bootable FreeDOS DOS floppy diskette IMG file for V86 on OSX