Creating FAT Filesystems in Linux

The full form of FAT is File Allocation Table. It is a file system developed by Microsoft. FAT filesystem was developed for very old version of Windows operating system like DOS, Windows 98 etc. The FAT filesystem is still used today because it is supported on every operating system out there. For example, Android SD cards, Android supported USB flash drives uses FAT filesystem by default. In earlier days, floppy disks also used FAT filesystem. Linux supports FAT filesystem though the VFAT kernel module.  In this article, I will show you how to create FAT filesystems in Linux. So, let’s get started.

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 -y

On CentOS 7 or RHEL 7, you can install dosfstools with the following command:

$ sudo yum install dosfstools -y

Formatting 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 lsblk

As 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 <Enter> to create a new DOS partition table.

Now, to create a new partition, press n and then press <Enter>. You should see the following options. We want to create a primary partition. So, just press <Enter> (to select the default option).

As this is the first partition of our precious USB flash drive, the default value 1 is alright. So, press <Enter>.

Press <Enter> to leave the defaults for the first sector number.

Press <Enter> to leave the defaults for the last sector number as well.

You may see the following message. Just press y and then press <Enter>.

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 <Enter>. Now, type in the hex code b and press <Enter>.

As you can see, the partition type is changed to W95 FAT32.

Now, press w and press <Enter> to write the partition table to the USB flash drive.

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/sdb1

NOTE: 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.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Make Raspberry Pi Thin Client

A thin client is a low power computer that can connect to other powerful computers remotely usually via VNC or RDP protocol...

How to Install Spotify on Manjaro

Life itself is like music, right? There’s no human being without the passion for music. Whenever you’re on gym or a...

How to install RabbitMQ on Ubuntu

In this post, we will see how we can install one of the most popular asynchronous messaging tools, RabbitMQ. According...