Skip to content

Instantly share code, notes, and snippets.

@pjobson
Last active Aug 12, 2021
Embed
What would you like to do?
Create exFat Partiion in Linux Accessible to Windows / MacOS

To create a exFat partition which is compatible with all operating systems, I recommend using a drive with under 2TB. This will allow you to use an MBR partition table instead of GPT, I've had issues mounting GPT exFat drives in Windows.
This could be partially because I don't know how to Windows anything.

List Disks

fdisk -l

Mine for example is /dev/sdl, because I have many disks.

Disk /dev/sdl: 114.6 GiB, 123010547712 bytes, 240254976 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb2fdd74a

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sdl1          2048   2402549   2400502   1.1G 83 Linux
/dev/sdl2       2404352   2404999       648   324K 83 Linux
/dev/sdl3       2406400 240254975 237848576 113.4G 83 Linux

Note the Device list and Disklabel type which is the partition table.

Delete Existing Partitions

fdisk /dev/sdl

Follow through with the prompts like:

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): d

Partition number (1,2, default 2): 3
Partition 3 has been deleted.

Partition number (1,2, default 2): 2
Partition 2 has been deleted.

Command (m for help): d
Selected partition 1

Partition 1 has been deleted.

Command (m for help): w

The partition table has been altered.
Syncing disks.

Delete Existing Partition Table

gdisk /dev/sdl

This will show something like this, sometimes it may throw an error, the goal is to get to the Command (? for help): prompt.

GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: present

Found valid MBR and GPT. Which do you want to use?
 1 - MBR
 2 - GPT
 3 - Create blank GPT

Your answer: 3

Command (? for help): x

Expert command (? for help): z

About to wipe out GPT on /dev/sdo. Proceed? (Y/N): Y

GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.

Blank out MBR? (Y/N): Y

Verify Disk

fdisk -l /dev/sdl

Should now show no Devices or Disklabel.

Disk /dev/sdl: 114.6 GiB, 123010547712 bytes, 240254976 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Create New Partition

fdisk /dev/sdl

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x2a2a6e65.

Command (m for help): o
Created a new DOS disklabel with disk identifier 0xb2fdd74a.

Command (m for help): n

Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-240254975, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-240254975, default 240254975): 240254975 (or just hit enter)

Created a new partition 1 of type 'Linux' and of size 114.6 GiB.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 7 (This should be HPFS/NTFS/exFAT, verify with L)

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Verify Disk

fdisk -l /dev/sdl

Should show one Device and dos Disklabel.

Disk /dev/sdl: 114.6 GiB, 123010547712 bytes, 240254976 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xba873b20

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdl1        2048 240254975 240252928 114.6G  7 HPFS/NTFS/exFAT

Format exFAT

sudo mkfs.exfat -n meh /dev/sdl1

Where -n is your disk label, I didn't care so I used meh.

mkexfatfs 1.2.8
Creating... done.
Flushing... done.
File system created successfully.

Mount

mkdir /mnt/temp
mount /dev/sdl1 /mnt/temp

Good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment