How to create exfat / vfat image file on Linux

Is there any way to make a exfat or vfat (Microsoft formatting file) image file on Linux machine and mount it for testing purpose?

The procedure to create an MS-DOS filesystem under Linux using mkfs.fat is as follows:

Step 1 - Use the fallocate to make an image file under Linux

The syntax is as follows to make a new 512 MB MS-DOS image file named exfat.img:

sudo fallocate -l 512M /exfat.img

See Linux / UNIX: Create Large 1GB Binary Image File With dd Command - nixCraft for more info.

Step 2 - Formatting image file using the mkfs.vfat

The syntax is:

sudo mkfs.vfat /exfat.img
## For exFAT (install mkfs.exfat, see below) ##
sudo mkfs.exfat /exfat.img

Step 3 - Creating a new mount point directory

Type the mkdir command as follows:

sudo mkdir -v /fatimagedir/

Step 4 - Mounting exfat / vfast image file under Linux

Use the mount command as follows to mount the /exfat.img under /fatimagedir/

sudo mount  /exfat.img /fatimagedir/


sudo mount  -o loop /exfat.img /fatimagedir/

Step 5 - Verification

Use the mount or df command to check Linux disk space usage using the CLI. For example"

mount | grep fat
df -T

That is all.

1 Like

This creates a FAT32, not exFAT:

$ sudo mkfs.vfat -vvvvv /exfat.img
mkfs.fat 4.2 (2021-01-31)
Auto-selecting FAT32 for large filesystem
Boot jump code is eb 58
Using 32 reserved sectors
Trying with 8 sectors/cluster:
Trying FAT32: #clu=130811, fatlen=1024, maxclu=131072, limit=65525/268435446
Using sector 6 as backup boot sector (0 = none)
/exfat.img has 32 heads and 63 sectors per track,
hidden sectors 0x0000;
logical sector size is 512,
using 0xf8 media descriptor, with 1048572 sectors;
drive number 0x80;
filesystem has 2 32-bit FATs and 8 sectors per cluster.
FAT size is 1024 sectors, and provides 130811 clusters.
There are 32 reserved sectors.
Volume ID is 195e0e47, no volume label.
1 Like

Oh, yes. Install exfat support for the mkfs. For example, try the apt command under Debian/Ubuntu Linux:

sudo apt install exfat-utils


mkfs.exfat /exfat.img

Rest of the tutorial is same.


As of Ubuntu 22.04 LTS Jammy it’s exfatprogs; 21.10 Impish has both, but exfatprogs is an older version in 21.10.