mkdosfs Command in Linux



The mkdosfs command in Linux is used to create an MS-DOS file system under Linux. This command is part of the dosfstools package, which provides utilities for creating and checking MS-DOS file systems.

The mkdosfs command is often used to format USB drives, SD cards, and other storage devices with the FAT file system, which is widely supported by various operating systems, including Windows, macOS, and Linux.

Table of Contents

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

Understanding mkdosfs Command

The mkdosfs command is a powerful and versatile tool for creating FAT file systems on various storage devices. It provides a wide range of options and parameters that allow users to customize the file system according to their needs. While the FAT file system has some limitations compared to more modern file systems, it remains a popular choice due to its wide compatibility and simplicity.

Syntax of mkdosfs Command

The mkdosfs command is a versatile tool that allows users to create a FAT file system on a specified device. The command supports various options and parameters that enable users to customize the file system according to their needs.

The basic syntax of the mkdosfs command is as follows −

mkdosfs [options] device

Here, device refers to the storage device on which the file system is to be created. The options parameter allows users to specify various settings and configurations for the file system.

Examples of mkdosfs Command in Linux

Here are some examples of how to use the mkdosfs command to create a FAT file system on a storage device −

Creating a FAT32 File System on a USB Drive

To create a FAT32 filesystem on a partition, you can use the following command −

sudo mkdosfs -F 32 /dev/sdb1
mkdosfs Command in Linux1

In this example, the mkdosfs command is used to create a FAT32 file system on the first partition of a USB drive (/dev/sdb1). The -F 32 option specifies that a FAT32 file system should be created.

Creating a FAT16 File System with a Volume Label

To create a FAT16 filesystem, use the -F option with the value 16 −

sudo mkdosfs -F 16 -n "MY_USB" /dev/sdb1
mkdosfs Command in Linux2

In this example, the mkdosfs command is used to create a FAT16 file system on the first partition of a USB drive (/dev/sdb1). The -F 16 option specifies that a FAT16 file system should be created, and the -n "MY_USB" option sets the volume label to "MY_USB".

Creating a FAT12 File System with a Custom Cluster Size

To create a FAT12 filesystem, use the -F option with the value 12 −

sudo mkdosfs -F 12 -s 4 /dev/sdb1
mkdosfs Command in Linux3

In this example, the mkdosfs command is used to create a FAT12 file system on the first partition of a USB drive (/dev/sdb1). The -F 12 option specifies that a FAT12 file system should be created, and the -s 4 option sets the number of sectors per cluster to 4.

Creating a File System on a Regular File

The -C option specifies that a file system should be created on a regular file, and the size of the file system is set to 1,048,576 bytes (1 MB).

mkdosfs -C myfilesystem.img 1048576
mkdosfs Command in Linux4

In this example, the mkdosfs command is used to create a file system on a regular file (myfilesystem.img).

Setting the Volume Label

The -n option allows you to set a volume label for the filesystem. This label can be used to identify the filesystem −

sudo mkdosfs -n "MyVolume" /dev/sdX1
mkdosfs Command in Linux5

Specifying the Cluster Size

You can specify the cluster size of the filesystem using the -s option. For example, to create a filesystem with a cluster size of 8 sectors −

sudo mkdosfs -s 8 /dev/sdX1
mkdosfs Command in Linux6

Specifying the Number of Reserved Sectors

The -r option lets you specify the number of reserved sectors for the filesystem −

sudo mkdosfs -r 32 /dev/sdX1
mkdosfs Command in Linux7

Creating a Filesystem with a Specific UUID

The -i option allows you to set a specific UUID (Universally Unique Identifier) for the filesystem −

sudo mkdosfs -i 12345678 /dev/sdX1
mkdosfs Command in Linux8

Setting the Number of FATs

The -f option allows you to set the number of File Allocation Tables (FATs) for the filesystem. By default, this is set to 2 −

sudo mkdosfs -f 2 /dev/sdX1
mkdosfs Command in Linux9

Specifying the Root Directory Entries

The -R option lets you specify the number of root directory entries for the filesystem −

sudo mkdosfs -R 512 /dev/sdX1
mkdosfs Command in Linux10

Setting the Media Type

The -M option allows you to set the media type for the filesystem. This can be useful for compatibility purposes −

sudo mkdosfs -M 0xf8 /dev/sdX1
mkdosfs Command in Linux11

Creating a Filesystem with a Specific Backup Boot Sector

The -b option allows you to specify a backup boot sector for the filesystem −

sudo mkdosfs -b 6 /dev/sdX1
mkdosfs Command in Linux12

Using a Configuration File

The -C option lets you use a configuration file to set various parameters for the filesystem −

sudo mkdosfs -C configfile /dev/sdX1
mkdosfs Command in Linux13

Creating a Filesystem for a USB Drive

If you have a USB drive that you want to format with a FAT32 filesystem, you can use the following command −

sudo mkdosfs -F 32 /dev/sdb1
mkdosfs Command in Linux14

This can be useful for creating a filesystem that is compatible with Windows and other operating systems.

Creating a Filesystem for a Small Partition

For small partitions, such as those used for boot loaders or temporary storage, a FAT16 or FAT12 filesystem can be a good choice due to its simplicity and low overhead −

sudo mkdosfs -F 16 /dev/sdX1
mkdosfs Command in Linux15

Creating a Filesystem for an Embedded System

In embedded systems, where resources are limited, a FAT12 or FAT16 filesystem can be a good choice due to its simplicity and low resource requirements −

sudo mkdosfs -F 12 /dev/sdX1
mkdosfs Command in Linux16

If you have any specific questions or need further examples, feel free to ask!

Conclusion

The mkdosfs command is a powerful tool for creating MS-DOS filesystems in Linux. These filesystems are widely compatible with various operating systems, making them a versatile choice for many applications. By understanding the various options and features available with mkdosfs, you can create filesystems that are tailored to your specific needs.

By understanding the various options and parameters available with the mkdosfs command, users can create optimized and reliable file systems for their storage devices. Whether you are formatting a USB drive, creating a bootable disk, or setting up a file system on a regular file, the mkdosfs command provides the flexibility and functionality needed to get the job done.

Advertisements