How to format an exFAT filesystem on Linux with the desired cluster size to tune your selection along the tradeoff curve between speed and disk usage
Quick summary
Here's how to manually set your own cluster size. I recommend a cluster size of 8 KiB. The below information is a summary from my website here: https://gabrielstaples.com/exfat-clusters/#formatting-an-exfat-drive-on-linux-ubuntu:
First, use gparted to prepare a partition. Format it to anything initially--ex: ext4. We'll change that later from the command line.
Install dependencies. See: https://itsfoss.com/format-exfat-linux/
sudo apt update sudo apt install exfat-fuse exfat-utils # for Ubuntu 20.04 and earlier sudo apt install exfat-fuse exfatprogs # for Ubuntu 22.04 and laterEnsure your partition you are about to format is NOT mounted:
sudo umount /media/your_name/your_diskFormat your partition as exFAT, setting the cluster size to 8 KiB. This assuming your sector size is 512 bytes, as
-s 16says to use a cluster size of 16 sectors, which would be 16 sectors x 512 bytes/sector = 8192 bytes in a cluster. Note that you can change the-n "name"part to whatever you want your volume name to be, up to 15 chars (seeman mkexfatfs):# 8 KiB clusters (takes 0.698 sec) <=== WHAT I USE AND RECOMMEND time sudo mkexfatfs -n "my_exFAT" -s 16 /dev/sda999This just takes a few seconds.
Done!
Details
Setting the cluster size is really important, it turns out, when formatting exFAT, as it significantly affects the speed and disk usage (see the plots I made, below).
If you use the Gnome Disks utility on Linux to format the exFAT drive, it chooses the cluster size for you, probably according to Microsoft's default values as shown in the table just below: Support.Microsoft.com: Default cluster size for NTFS, FAT, and exFAT:
Default cluster sizes for exFAT
The following table describes the default cluster sizes for exFAT.
Volume size Windows 7, Windows Server 2008 R2, Windows Server 2008,
Windows Vista, Windows Server 2003, Windows XP7 MB–256 MB 4 KB 256 MB–32 GB 32 KB 32 GB–256 TB 128 KB > 256 TB Not supported
When I used Gnome Disks to format my exFAT drive the first time, I realized later that it had used a cluster size of 128 KiB on my 500 GB SSD. This corresponds to the default values recommended by Microsoft in the table above.
If you'd like to use other cluster sizes, here are some more examples. YOu can use any power of 2 (to specify the number of sectors per cluster) after -s. The maximum cluster size allowed is 32 MiB, or 65536 512-byte sectors:
# Set the name after `-n` to whatever you want too. `-s` specifies how many
# sectors to use per cluster. Assuming you have 512 byte sectors, the following
# cluster size comments are accurate.
#
# cluster size (format time)
# ---------- -------------
time sudo mkexfatfs -n "my_exFAT" -s 1 /dev/sda999 # 0.5 KiB (512 byte)
# clusters (10 sec)
time sudo mkexfatfs -n "my_exFAT" -s 8 /dev/sda999 # 4 KiB clusters (1.340 sec)
time sudo mkexfatfs -n "my_exFAT" -s 16 /dev/sda999 # 8 KiB clusters (0.698 sec) <=== WHAT I USE AND RECOMMEND: 8 KiB clusters
time sudo mkexfatfs -n "my_exFAT" -s 64 /dev/sda999 # 32 KiB clusters (0.230 sec)
time sudo mkexfatfs -n "my_exFAT" -s 256 /dev/sda999 # 128 KiB clusters (0.075 sec)
time sudo mkexfatfs -n "my_exFAT" -s 65536 /dev/sda999 # 32 MiB clusters (0.120 sec) [absolute max cluster size allowed!]
Here are the tradeoff curves of cluster size vs speed and disk usage, as I first presented on my website here: https://gabrielstaples.com/exfat-clusters/
