mformat Command in Linux



mformat is a useful utility in Linux that is part of the Mtools suite. It allows you to format MS-DOS file systems on floppy disk and other removal storage devices without needing to use MS-DOS itself. This command is pretty useful in case you need to prepare a disk to be compatible with older systems or software that require MS-DOS formatted media.

Table of Contents

Here is a comprehensive guide to the options available with the mformat command −

Syntax of mformat Command

The basic syntax to use the mformat command on Linux is as follows −

mformat [options] drive

Where −

  • mformat is the command used to format MS-DOS filesystems.
  • [options] are various command-line options that modify the behavior of mformat.
  • drive is the drive letter of the device you want to format.

mformat Command Options

Listed here are various options you can employ with the Linux mformat command −

Option Description
-t tracks Specifies the number of tracks on the disk.
-T tot_sectors Specifies the total number of sectors on the disk.
-h heads Specifies the number of heads (sides) on the disk.
-n sectors Specifies the number of sectors per track.
-f size Specifies the size of the disk in kilobytes.
-v volume_label Sets the volume label of the disk.
-M software_sector_size Specifies the software sector size.
-N serial_number Sets the disk's serial number.
-B bootsector Specifies a file to use as the boot sector.
-r root_dir_len Sets the length of the root directory.
-L fat_len Sets the length of the FAT.
-I fsVersion Specifies the filesystem version.
-S hardsectorsize Specifies the hardware sector size.

Examples of mformat Command in Linux

Below are some examples demonstrating how to utilize the mformat command in a Linux environment −

  • Basic Formatting
  • Specifying Volume Label
  • Setting the Number of Cylinders
  • Setting the Number of Heads
  • Specifying Cluster Size

Basic Formatting

To format a USB drive as a DOS-compatible filesystem, you can use the command without additional options −

sudo mformat /dev/sdb1

This command initializes and formats the partition /dev/sdb1 with the default DOS file system parameters.

Specifying Volume Label

If you want to assign a specific name to the disk you're formatting, use the -v option followed by the desired volume label −

sudo mformat -v MYDISK /dev/sdb1

This command formats the partition /dev/sdb1 and sets its volume label to "MYDISK". The volume label helps you identify the disk when it is mounted or accessed, making it easier to manage multiple disks.

Setting the Number of Cylinders

To specify the number of cylinders on the disk, use the -t option followed by the number of cylinders −

sudo mformat -t 80 /dev/sdb1

This command formats the partition /dev/sdb1 with 80 cylinders. Cylinders are part of the disk's geometry, representing the number of circular tracks per side of the disk.

Setting the Number of Heads

When dealing with double-sided disks, you can specify the number of heads (or sides) using the -h option −

sudo mformat -h 2 /dev/sdb1

This command formats the partition /dev/sdb1 with 2 heads, meaning it considers both sides of the disk. This ensures that all storage areas on a double-sided disk are properly formatted.

Specifying Cluster Size

To optimize the disk's storage efficiency, you can set the cluster size with the -c option, followed by the size in sectors −

sudo mformat -c 4 /dev/sdb1

This command formats the partition with a cluster size of 4 sectors. A cluster is the smallest unit of storage that the filesystem uses to manage files. Setting an appropriate cluster size can improve the disk's performance and storage efficiency.

Conclusion

The mformat is a useful command in Linux that is part of the Mtools suite. It enables formatting MS‑DOS filesystems on floppy disks and other portable storage devices without requiring MS-DOS. By understanding its syntax and exploring the various options available, you can effectively use mformat to ensure your disks are properly formatted.

Whether it's setting volume labels, specifying the number of cylinders, or customizing cluster sizes, the mformat command offers a flexible and powerful way to manage your disk formatting needs.

Advertisements