how to format an usb drive in fat16/fat32/ntfs from linux command line

One of the reasons of having to use an usb drive is to transfer files between different machines, usually with different operating systems. Unfortunately, there are still enough Windows machines out in the wild that reads only specific file systems in formats such as FAT32 or NTFS.

This means you will need to format your USB drives in formats that is understood by MS Windows. These may be either FAT16, FAT32 or NTFS file system formats. We will see how you can format an usb drive in any file system format from the Linux command line.

The command that is used to create a new file system is called mkfs in Linux. You can use this to create file systems on any disk, drive or partitions on the system. This utility supports many different file systems, including the FAT ones.

Install dosfstools Package

The support for the FAT file systems are provided by the dosfstools package. Most Linux distros should have this installed by default. If it is not installed, then you will need to install this first using your package manager installation process (apt-get, pacman, emerge etc).

The mkfs utility is only a front-end to the underlying file system builders, which means you can only use those utilities directly as well. The mkfs utility takes a command line option –type (or -t) to specify the file system type to be used.

In order for the system to format the drive, the system should be able to identify the device correctly. You also will need to know the device name for the USB drive. We will assume that the usb is loaded at /dev/sdc for the examples below.

Note: You can use the fdisk command to find the device. Use the fdisk -l command, which will print out all the devices identified by the machine.

fdisk listing of drive

In order to create a FAT16 file system on the device, you use one of the following commands.

bash# mkfs -t fat /dev/sdc1

mkfs to create fat32 format

bash# mkfs.fat -F 16 -I /dev/sdc1

There are several different commands, which are all symlinks to mkfs.fat command or utility. There are several different (legacy) names to the tools, which are all available by symlinks. You can use mkdosfs, mkfs.msdos, mkfs.dos, mkfs.fat or mkfs.vfat all of which does the same thing.

If you want to set the block size to 32 then you specify 32 as the value to the -F command line option.

bash# mkfs.fat -F 32 -I /dev/sdc

If you want to use the NTFS for formatting instead of the FAT32, then you can specify that using the same command line options as above….but using NTFS instead.

bash# mkfs.ntfs /dev/sdc1

bash# mkfs -t ntfs /dev/sdc1

All of these commands do support additional options, that will allow you to set or specify several other formatting values. You can specify sector size, volume labels, compression, indexing etc etc. These advanced options vary between the FAT and NTFS formats. You can check manual page of these utilities to find the additional options that they support.