Files
mtools
Access MS-DOS filesystems (FAT) from the command line.
Additional Notes
mtools is a collection of utilities for accessing MS-DOS filesystems (FAT12, FAT16, FAT32) without mounting them. The tools mimic DOS commands: mcopy, mdir, mdel, mformat, mren, mmove, mcd, and others.
They work directly with floppy disk images, USB drives, or raw disk images. This is useful for working with FAT filesystems on embedded devices, old floppy images, or when mounting is inconvenient.
Syntax
mcopy [options] source target
mdir [options] directory
mdel [options] file
mformat [options] drive:
Common Commands
mcopy: Copy files between DOS and Unix filesystems.mdir: List directory contents on a DOS filesystem.mdel: Delete files on a DOS filesystem.mren: Rename files on a DOS filesystem.mmove: Move files on a DOS filesystem.mcd: Change directory on a DOS filesystem.mformat: Format a DOS filesystem.mtype: Display the contents of a DOS file.mdigest: Compute a digest of files on a DOS filesystem.mpart: Partition a disk image.mrd: Remove a directory.mmd: Create a directory.
Parameters
options: Flags that change howmtoolsbehaves.target: Optional file, device, interface, user, service, or command target when the command supports one.
Common Options for mcopy
-o: Overwrite destination files without prompting.-n: No confirmation (auto-overwrite).-m: Preserve file modification time.-v: Verbose.-t: Text file conversion (convert newlines).
Examples
mcopy a:readme.txt ./
Copy readme.txt from the DOS floppy to the current directory.
mcopy -o *.txt a:/
Copy all .txt files from the current directory to the DOS floppy.
mdir a:
List the contents of the DOS floppy.
mdel a:oldfile.txt
Delete a file from the DOS floppy.
mformat a:
Format a floppy diskette with a FAT filesystem.
mcopy -m image.img::file.txt ./
Copy a file from a disk image.
mmd a:newdir
mcopy doc.txt a:newdir/
Create a directory and copy a file into it.
Configuration (~/.mtoolsrc)
Drive letters are configured in ~/.mtoolsrc:
drive a: file="/dev/fd0"
drive c: file="/dev/sda1"
drive i: file="/path/to/disk.img"
Practical Notes
- Default drive letters:
a:for/dev/fd0,b:for/dev/fd1. Other drives must be configured in~/.mtoolsrc. mtoolsreads and writes directly to the device; unmount it first to avoid filesystem corruption.- For modern FAT filesystem management, mounting with
mount -t vfatis often simpler. - The
mdircommand without arguments defaults to the current DOS directory on thea:drive.