I've heard of mtools several times over the years but never used it myself until recently.
From the get go I ran into some odd problems.
Here's my script to create an HDD image with a FAT partition:
----8<----
# based on example at
https://bochs.sourceforge.io/doc/docbook/user/diskimagehowto.html# broken mtools 4.0.33-1+really4.0.32-1build1 (Ubuntu 22.04 jammy = Deian bookworm)
# functional mtools 4.0.18-2+b1 (Ubuntu 16.04 xenial = Debian stretch)
PWD=$(pwd)
BASE=hdd10mb
IMG=$PWD/$BASE.img
CFG=$PWD/$BASE.cfg
echo "drive c: file=\"$IMG\" partition=1" > $CFG
export MTOOLSRC=$CFG
dd if=/dev/zero of=$IMG bs=1M count=10
echo init
mpartition -I -s 63 -t 20 -h 16 c:
echo create
mpartition -cpv -s 63 -t 20 -h 16 c:
echo activate
mpartition -a c:
echo format
mformat c:
----8<----
When running the above on Ubuntu 22.04 LTS I'm getting this output with an error from mformat:
----8<----
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.00907886 s, 1.2 GB/s
init
Warning: no active (bootable) partition present
create
sectors: 63 heads: 16 20480
*Partition 1
active=80
start: h=1 s=1 c=0
type=0x4
end: h=15 s=63 c=19
start=63
nr=20097
The following command will recreate the partition for drive C:
mpartition -c -b 63 -l 20097 -t 20 -h 16 -s 63 -b 63 C:
activate
format
Weird: read size (19585) not a multiple of sector size (512)
buffer_flush: short write
Error writing boot sector
----8<----
There's a strange coincidence that 19585 = 20097 - 512.
20097 is in sectors, whereas 512 is in bytes.
Anyway... If I manually install an older version of mtools, 4.0.18
everything seemingly works.
Alexey