LinuxCommandLibrary

mformat

Format a MS-DOS filesystem disk

SYNOPSIS

mformat [options] [device]

PARAMETERS

-a
    Automatically selects output format based on device characteristics.

-A val
    Passes an option to the mdir command for specific behavior.

-c val
    Passes an option to the mdir command for specific behavior.

-C
    Creates the disk image file if it does not already exist.

-f size
    Specifies the size of the disk in kilobytes (e.g., 720, 1440, 2880).

-F type
    Sets the FAT type to 12, 16, or 32.

-h heads
    Sets the number of heads for the disk geometry.

-H sectors
    Sets the number of hidden sectors before the partition.

-i file
    Specifies a different device or image file to format instead of the default.

-I id
    Sets the volume ID (serial number) of the formatted disk.

-L label
    Sets the volume label for the formatted disk.

-M byte
    Sets the media descriptor byte in the boot sector.

-n
    Do not assign a volume label to the formatted disk.

-N serial
    Sets a custom serial number for the disk.

-P
    Formats a partition, using mformat's internal partition table processing.

-Q
    Quiet mode; suppresses warnings and most informational messages.

-r entries
    Sets the maximum number of root directory entries.

-R sectors
    Sets the number of reserved sectors in the boot record.

-s sectors
    Sets the number of sectors per track.

-S sectors
    Sets the total number of sectors on the disk.

-t tracks
    Sets the number of tracks.

-T
    Test mode; performs all steps except actually writing to the device.

-v
    Verbose mode; displays detailed information during formatting.

-V
    Verifies written sectors after formatting.

-X
    Uses extended BIOS parameter block for FAT32 filesystems.

-Z
    Zero-fills the data area of the disk during formatting.

DESCRIPTION

mformat is a utility from the mtools package designed to create an MS-DOS (FAT) filesystem on a floppy disk, hard disk partition, or disk image. It's analogous to the FORMAT command found in MS-DOS or Windows. This command is crucial for users needing to exchange data with systems running DOS or Windows, especially in environments where direct access to such systems is limited.

mformat handles the low-level formatting and filesystem creation, allowing the device to be recognized and used by DOS/Windows systems. It supports various FAT filesystem types (FAT12, FAT16, FAT32) and can configure parameters like cluster size and volume label. While its original purpose was heavily tied to floppy disks, it can also format partitions on hard drives or USB drives, effectively preparing them for use with FAT-compatible operating systems. It integrates seamlessly with other mtools utilities like mcopy, mdir, and mmd, providing a complete suite for MS-DOS filesystem manipulation.

CAVEATS

mformat operates directly on device files, often requiring root privileges or proper user permissions to function correctly. Incorrect usage or specifying the wrong device can lead to irreversible data loss. While powerful for FAT filesystems, it is not suitable for formatting other filesystem types (e.g., ext4, NTFS), for which dedicated tools like mkfs.ext4 or mkfs.ntfs should be used. For general FAT filesystem creation in modern Linux, mkfs.vfat (from dosfstools) is often preferred as it's typically more actively maintained.

DEFAULT DEVICE

If no device argument is specified, mformat attempts to format the first floppy drive (typically /dev/fd0). This default behavior can be overridden or configured via the mtools configuration files.

MTOOLS CONFIGURATION

mformat's behavior, including default drive mappings, geometry settings, and other options, can be extensively customized through the ~/.mtoolsrc user configuration file or the system-wide /etc/mtools/mtools.conf file. This allows users to define custom settings for various disk types or devices.

HISTORY

mformat is a core component of the mtools suite, which emerged in the early 1990s. Its development was driven by the need for seamless floppy disk exchange between Unix-like systems and MS-DOS/Windows environments, a common necessity during that era. The mtools project aimed to provide a robust set of utilities for direct manipulation of DOS filesystems from Unix, bypassing the need to boot into DOS. As floppy disks declined in prominence, mformat's utility adapted to formatting USB drives and disk images with FAT filesystems, maintaining its relevance for cross-platform data exchange, especially for embedded systems, virtual machines, or legacy hardware requirements.

SEE ALSO

mtools(1), mkfs.vfat(8), mkfs(8), fdisk(8), parted(8)

Copied to clipboard