87

Is it possible to create and format an exFAT partition from Linux?

2
  • 2
    Here's another good reference: itsfoss.com/format-exfat-linux. It mentions sudo apt install exfat-fuse exfat-utils for Ubuntu 20.04 and older, and sudo apt install exfat-fuse exfatprogs for Ubuntu 22.04 and later. May 22, 2023 at 6:37
  • 1
    I needed exFAT for Windows-compatible USB flash drives. After hours of struggles, I found it was just easier to format the drives on Windows.
    – onewhaleid
    Aug 29, 2023 at 10:43

10 Answers 10

95

Yes, there is a project implementing exfat and the related utilities at relan/exfat.

To format a partition, use mkexfatfs / mkfs.exfat like with most filesystems, e.g.:

mkfs.exfat /dev/sdX1

As for creating the partition in the first place, this is the same as for any other filesystem. Create a partition in your favourite partition manager. If you have an MBR partition table, set the partition type to NTFS (that is, code 7).

Note, that some distributions only package the fuse module, so you may have to build it yourself.

8
  • 24
    On Ubuntu I just had to install a couple packages first: sudo apt-get install exfat-utils exfat-fuse. Source: askubuntu.com/a/374627/18665
    – bmaupin
    Aug 28, 2015 at 18:21
  • 3
    To be clear, the code is 7 (hex), not 7h.
    – thetoolman
    Mar 17, 2016 at 0:27
  • 1
    On modern fdisk the type you want is 11 (Microsoft basic data). Disregard the google.code.com link in the answer and instead use @bmaupin's command on Debian/Ubuntu.
    – Adam Katz
    Dec 2, 2017 at 20:07
  • be careful while doing this, it didnot warn me and completely deleted all the files I had in it. So first backup and then do it
    – doniyor
    Mar 30, 2018 at 9:58
  • 2
    This worked fine for me. I already had the exfat and fuse installed. BUT... the post blow from Billious is misleading. IF you have just formatted a drive, you must supply more information to mkfs.exfat -- Like where to put the partition and how big, ya-da-ya-da. I'm just lazy. I used gParted to set-u my USB how I wanted. Leave the partition you want to make exFAT alone. Or format it to FAT32 to process the whole USB. Next ensure the target partition is unmounted. Proceed, e.g.: sudo mkfs.exfat -i DAT -n data /dev/sdc3. I let gParted deal with alignments and such.
    – will
    Oct 8, 2018 at 13:09
11

The mkfs.exfat solution above works if a partition already exists on a drive, like a purchased USB pen drive. Use this link if you're starting from a bare disk:

Formatting a Universal Drive

2
  • I tried following several guides, which all failed in Fedora 29. This one worked. :)
    – Nick Ribal
    Nov 6, 2019 at 4:08
  • This should be the accepted answer! That link contains a brilliant explanation that I couldn't find anywhere else on the internet. Oct 18, 2021 at 11:29
9

On the command line, the process is as follows:

Use the lsblk command to find out which drive your usb stick is. (for example /dev/sdx)

lsblk

Then start parted and tell it which drive you want to perform operations on:

sudo parted /dev/sdx

In parted interactive mode type:

mklabel msdos

Now reboot. And after the reboot do:

sudo parted /dev/sdx

And in parted interactive mode type:

mkpart primary ext4 0% 100%

When the partition is created, press q to exit parted.

Now that the flash drive contains a partition, create an exFAT filesystem on the newly created partition (replacing the ext4 filesystem that only works on Linux):

sudo mkfs.exfat /dev/sdx1

Copy-pasted from https://forum.manjaro.org/t/how-to-format-a-usb-stick-so-that-it-is-usable-on-manjaro-windows-and-macos/3972

Personally, I skipped the "reboot" step. Instead, I pulled out the USB stick (sdb went away) and after reinserting it came up as sdd. If it wasn't obvious, with sdx1 the "x" could be any letter of the alphabet (usually it's a, b, c, d...) but it depends on your particular setup.

0
9

Install exFAT utilities first.

sudo apt install exfat-utils

Then

sudo mkfs.exfat -n Volume Name /dev/USB_dev_file
5

See guidance below for completely wiping and restoring afresh any USB pen drive from anuy Linux command line/terminal. I often do this when pen drives become corrupted and stop working. In this example, the pen drive is /dev/sdb, but yours may be different,


sudo fdisk -l

This lists the disks/partitions. Remember the correct /dev/sdx name for the device. In this example it is /dev/sdb

You may need to unmount any already mounted partitions - e.g sudo umount /dev/sdb1, etc.

The following wipefs command will remove any existing file systems from the drive. If you do not have wipefs installed, install it using your package manager.

sudo wipefs --all /dev/sdb

At this point, all file systems have been removed, any data on the drive is technically still recoverable. To permanently wipe all data from the drive :-

sudo dd if=/dev/zero of=/dev/sdb bs=1M

This dd command should complete quickly. This writes zeros (the if = input file) to the of (output file), which is the device. The bs (block size) flag sets how many bytes to read/write at a time, the default is 512 bytes, but above it has being set to 1 megabyte (or 1,000,000 bytes).

OR, for a more secure version which writes random data instead of zeros :-

dd if=/dev/urandom of=/dev/sdb

This one can take a while.

The pen drive is completely wiped now. and all data is unrecoverable.

If you want to now create a bootable USB drive now in Linux from an OS ISO file, use the dd command again here, e.g.

dd bs=4M if=ubuntu-12.04.2-server-i386.iso of=/dev/sdb

The pen drive is now bootable, and no further action is needed if this is all you want to do.

Or, to create a blank pen drive for storage purposes, you could put the drive into a Windows machine and format there, which might be easier/quicker, but to partition the pen drive in Linux, continue below as below

sudo fdisk /dev/sdb

This goes into the fdisk program. You need to now input specific commands in the following order.

  1. Option d - this delete partitions (this is not needed if you have used the dd command above on the device). Repeat for each partition if present.

  2. Option n - create a new partition, just accept all the defaults (unless you need multiple partitions of specific sizes, most people won't)

  3. Option w (write changes)

To create a vFAT partition (readable on Windows)

sudo mkfs -t vfat /dev/sdb1

Or, to create exFAT partition, use the following command instead:-

sudo apt-get install exfat-utils exfat-fuse #if not already installed
sudo mkfs.exfat -n volume_name /dev/sdb1

When complete, Linux should auto-mount the device. If not, mount the device as below :-

mkdir /media/usbdrive
mount /dev/sdb1 /media/usbdrive
5

Currently, the best filesystem to share content between Windows and Linux is exFAT, specially on USB pendrives and SD cards. exFAT is, roughly speaking, a revision of FAT32 without the 4GB max file size limitation. Since kernel version 5.4, exFAT is a native filesystem for Linux and does not rely on FUSE anymore.

If not installed, you will have to install exFAT support, as follows.
Note: On systems with older kernels, use exfat-utils instead of exfatprogs.

$ sudo apt install exfatprogs # Debian/Ubuntu
$ sudo dnf install exfatprogs # Red Hat/Fedora/CentOS
$ sudo pacman -S exfatprogs # Arch Linux/Manjaro

From here, you have two options. Use a graphical tool like gparted or the command line (which is more fun). Find below steps for the latter.

  1. Plug-in the USB pendrive/SD card.
  2. Identify the device. It should be one of /dev/sd?. In a terminal, run the below command which will show connected devices and partition mount points. In this example, /dev/sdb is the device, with two partitions, the first of which is mounted.
    $ lsblk
    NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sdb           8:16   1    15G  0 disk 
    ├─sdb1        8:17   1   256M  0 part /media/myuser/mydevice
    └─sdb2        8:18   1  14,7G  0 part 
    nvme0n1     259:0    0 931,5G  0 disk 
    ├─nvme0n1p1 259:1    0   512M  0 part /boot/efi
    ├─nvme0n1p2 259:2    0    64G  0 part /
    ├─nvme0n1p3 259:3    0   256G  0 part /home
    ├─nvme0n1p4 259:4    0    38G  0 part [SWAP]
    ├─nvme0n1p5 259:5    0   448G  0 part /data
    ├─nvme0n1p6 259:6    0    16M  0 part 
    └─nvme0n1p7 259:7    0   125G  0 part 
    
  3. Unmount mounted partitions.
    $ umount /dev/sdb1
    
  4. Create a new partition table and partition of type HPFS/NTFS/exFAT.
    $ sudo fdisk /dev/sdb # Pay attention! No final digit is used.
    
    Welcome to fdisk (util-linux 2.34).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help):
    
    • Create a new (dos) partition table: press o and enter.
    • Create a new partition: press n, enter and accept default options.
    • Change the partition type to HPFS/NTFS/exFAT: press t, enter, 7, enter.
    • Quit saving changes: press w and enter.
    • You can quit without saving changes: press q and enter.
  5. Format the partition.
    $ sudo mkfs.exfat -n "my label" /dev/sdb1 # Pay attention! Final digit is used.
    mkexfatfs 1.3.0
    Creating... done.
    Flushing... done.
    File system created successfully.
    
2
  • 1
    Answer originally given here. Aug 16, 2022 at 11:49
  • For getting the "use exfat-utils instead of exfatprogs" part of your answer correct ... +1. :)
    – Seamus
    Nov 12, 2023 at 16:51
4

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:

  1. First, use gparted to prepare a partition. Format it to anything initially--ex: ext4. We'll change that later from the command line.

  2. Install dependencies. See: https://itsfoss.com/format-exfat-linux/

    sudo apt update 
    
    # For Ubuntu 20.04 and earlier
    sudo apt install exfat-fuse exfat-utils
    
    # For Ubuntu 22.04 and later
    sudo apt install exfat-fuse exfatprogs
    
  3. Ensure your partition you are about to format is NOT mounted:

    sudo umount /media/your_name/your_disk
    
  4. Format your partition as exFAT, setting the cluster size to 8 KiB.

    For the Ubuntu 20.04 case, this assumes your sector size is 512 bytes. The -s 16 argument says 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" or -L "label" part to whatever you want your volume name to be, up to 15 chars (see man mkexfatfs):

    # For Ubuntu 20.04 and earlier
    # 8 KiB clusters (takes 0.698 sec) <=== WHAT I USE AND RECOMMEND
    time sudo mkexfatfs -n "my_exFAT" -s 16 /dev/sda999
    
    # For Ubuntu 22.04 and later
    # 8 KiB clusters <=== WHAT I USE AND RECOMMEND
    time sudo mkfs.exfat -L "my_exFAT" -c 8K /dev/sda999
    

    This just takes a few seconds.

  5. Done!

  6. For help, see:

    # For Ubuntu 20.04 and earlier
    # See this online here: https://man.archlinux.org/man/mkexfatfs.8.en
    man mkexfatfs
    
    # For Ubuntu 22.04 and later
    man mkfs.exfat
    mkfs.exfat -h
    

Details: cluster size, and mkexfatfs

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

enter image description here

Details: cluster size, and mkfs.exfat on Ubuntu 22.04 or later

man mkfs.exfat shows that the "SD Card Association" recommends the following cluster sizes for exFAT:

Card Capacity Range      Cluster Size   Boundary Unit
──────────────────────────────────────────────────────
            ≤8 MiB           8 KiB          8 KiB
  >8 MiB   ≤64 MiB          16 KiB         16 KiB
 >64 MiB  ≤256 MiB          16 KiB         32 KiB
>256 MiB    ≤1 GiB          16 KiB         64 KiB
  >1 GiB    ≤2 GiB          32 KiB         64 KiB
  >2 GiB   ≤32 GiB          32 KiB          4 MiB
 >32 GiB  ≤128 GiB         128 KiB         16 MiB
>128 GiB  ≤512 GiB         256 KiB         32 MiB
>512 GiB    ≤2 TiB         512 KiB         64 MiB

Again, though, I disagree with this, in particular for SSDs, and recommend 8 KiB cluster sizes. See my extensive analysis and speed and space testing here: https://gabrielstaples.com/exfat-clusters/.

Here are the commands to specify different cluster sizes with mkfs.exfat:

#                                                       cluster size
#                                                       ----------
time sudo mkfs.exfat -L "my_exFAT" -c 512  /dev/sda999  #   0.5 KiB (512 byte) clusters
time sudo mkfs.exfat -L "my_exFAT" -c 4K   /dev/sda999  #   4 KiB clusters
time sudo mkfs.exfat -L "my_exFAT" -c 8K   /dev/sda999  #   8 KiB clusters <=== WHAT I USE AND RECOMMEND: 8 KiB clusters
time sudo mkfs.exfat -L "my_exFAT" -c 32K  /dev/sda999  #  32 KiB clusters
time sudo mkfs.exfat -L "my_exFAT" -c 128K /dev/sda999  # 128 KiB clusters
time sudo mkfs.exfat -L "my_exFAT" -c 32M  /dev/sda999  # 32 MiB clusters

See also

  1. My answer: Is it best to reformat the hard drive to exFAT using 512kb chunk, or smaller or bigger chunks?
  2. My answer: Server Fault: How to find the cluster size of any filesystem, whether NTFS, Apple APFS, ext4, ext3, FAT, exFAT, etc.
1
  • 1
    Interesting stuff.
    – Seamus
    Nov 12, 2023 at 17:02
2

In the latest Ubuntu version (22.10) the package you are looking for is named exfatprogs instead of exfat-utils.

2

To make exFat formatting available for ubuntu.

(Maybe works fort other distros as well? will modify this claim if its been confirmed false or true.)

After these steps exFat formatting will work in ubuntu.

Ubuntu 20.04 and lower versions:

sudo apt install exfat-fuse exfat-utils

Ubuntu 22.04 and higher versions:

sudo apt install exfat-fuse exfatprogs

cited from: https://itsfoss.com/format-exfat-linux/#command-line

  • Article is about how to format into exfat, for example needed when making bootable windows media.
1
  • 1
    I think your answer would be "more complete" if you addressed the OP's question re "... create and format an exFAT partition". +1 anyway...
    – Seamus
    Nov 12, 2023 at 17:05
1

Disks (gnome-disks) and KDE Partition Manager are two GUI tools that can achieve this. (Gparted cannot do it.)

For USB sticks, there is the USB Stick Formatter, part of the mintstick tool .

1
  • Mint Stick helped a lot. as I was using Mint and did not realise its existence.
    – Ramesh
    Jun 6, 2020 at 5:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .