Installing Required Tools:
You can easily format USB flash drives as FAT. In order to do that, you need to have dosfstools installed. The package name is that same in all the common Linux distributions. It should already be installed on your computer. If it isn't, just use your package manager to install dosfstools.
On Ubuntu/Debian, you can install dosfstools with the following command:
$ sudo apt install dosfstools -yOn CentOS 7 or RHEL 7, you can install dosfstools with the following command:
$ sudo yum install dosfstools -yFormatting a USB Flash Drive as FAT:
Now, insert the USB flash drive that you want to format as FAT.
Then, run the following command to find the device name of your USB flash drive.
$ sudo lsblkAs you can see, the 4 GB USB flash drive has the device name sdb in my case. So, I can access it as /dev/sdb. It may be different for you. Make sure you replace it with yours from now on.
As you can see, I already have a partition /dev/sdb1 on my USB flash drive. So, I don't have to create a partition. But if you don't have a partition already, then you should create one first.
If you do have a partition, then unmount the partition first if it is mounted (as in my case). Otherwise, you won't be able to format it.
To unmount the partition, run the following command:
$ sudo umount /dev/sdb1
Suppose you don't have a partition on your USB flash drive for some reason. You can use fdisk to easily create one.
To do that, open /dev/sdb with fdisk as follows:
$ sudo fdisk /dev/sdb
Now, press o and press
Now, to create a new partition, press n and then press
As this is the first partition of our precious USB flash drive, the default value 1 is alright. So, press
Press
Press
You may see the following message. Just press y and then press
The partition should be created.
Now, you have to change the partition type to W95 FAT32. Otherwise, Windows and other operating system may not be able to recognize the filesystem.
To do that, press t and press
As you can see, the partition type is changed to W95 FAT32.
Now, press w and press
Now, you can format the USB flash drive partition /dev/sdb1 as FAT32 (32-bit FAT) filesystem with the following command:
$ sudo mkfs.vfat -F 32 -n MyFlashDrive /dev/sdb1NOTE: Here -n flag sets a label (MyFlashDrive in my case) for your USB flash drive. Label helps you identify the USB flash drives easily if you have multiple USB flash drives.
Your USB flash drive should be formatted as FAT32. Ignore the warning. Windows don't support lowercase letters in FAT32 labels. It will just show the label in uppercase letters. That's all. If the warning does bother you, then consider using only uppercase letters in label.
As you can see, I can mount the USB flash drive and copy files there.
As you can see, the USB flash drive works on Windows just fine. The files I copied from Linux are accessible.
So, that's how you create FAT (or FAT32) filesystems on Linux. Thanks for reading this article.