3

I need to format a floppy disk image file with a format that is readable by an (emulated) 3.5" 80-track 9 sectors/track single-sided floppy drive.

With mformat, I have no idea how to specify a disk image. The option -i <disk image> :: did not work (it's not mentioned in the manual as such anyway). The manual mentions option -C to create a disk image, but not how it's used, and that's the only mention of the word 'image' in the man page.

mkfs.fat doesn't allow me to specify number of heads.

How can I create such an image?

Pedro Gimeno
  • 317
  • 3
  • 10

1 Answers1

3

The mtools set of commands have default settings in /etc/mtools.conf which can be overriden in ~/.mtoolsrc or by exporting the MTOOLSRC environment variable pointing to a configuration file:

Location of the configuration files
/etc/mtools.conf is the system-wide configuration file, and ~/.mtoolsrc is the user's private configuration file. If the environmental variable MTOOLSRC is set, its contents is used as the filename for a third configuration file. These configuration files describe the following items

You can thus just prepare an empty file and point the settings to it. No root access is needed (at least when trying on Debian 10's mtools version 4.0.23-1).

Size of image: 80*1*9*512=368640

Using dd:

dd if=/dev/zero of=/tmp/floppy.img bs=368640 count=1

(this would have worked too: dd if=/dev/zero of=/tmp/floppy.img seek=368639 count=1 bs=1)

$ file /tmp/floppy.img 
/tmp/floppy.img: data

Override floppy A:'s location: create or edit the file ~/.mtoolsrc with this entry:

drive a: file="/tmp/floppy.img"

UPDATE: OP needs this to be usable in a Makefile. In this case exporting the MTOOLSRC variable to point to the relevant configuration file with above content (which could possibly also be created dynamically if there was the need) rather than using ~/.mtoolsrc is better suited.

Format:

$ mformat -t 80 -h 1 -n 9 a:

Check result:

$ file /tmp/floppy.img 
/tmp/floppy.img: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "MTOO4023", sectors/cluster 2, root entries 112, sectors 720 (volumes <=32 MB), Media descriptor 0xf8, sectors/FAT 2, sectors/track 9, heads 1, serial number 0x6649c47, unlabeled, FAT (12 bit)

# mount -o loop /tmp/floppy.img /mnt
#
A.B
  • 31,762
  • 2
  • 62
  • 101
  • Thanks. I've upvoted it because it answered the question; however it's not suitable for me because it's intended to create a floppy image within a makefile, and fiddling with the user's mtools configuration doesn't seem like a good idea in that context. – Pedro Gimeno Jan 02 '20 at 21:23
  • Oh that's easy to correct: export MTOOLSRC . I'll add it in my answer – A.B Jan 02 '20 at 21:40