How to FAT32 in macOS 🛠
What’s going on
I had an SD card with some invisible Linux partitions that I could not partition or delete in macOS’ Disk Utility. Even when I erased the entire disk as FAT-32, the invisible partitions was still there.
So to work around this, I used
diskutil in the terminal to repartition and delete the entire SD card (128GB) for one single large FAT32 partition with a 32kb cluster size. This is how I did it.
Find the disk identifier
First, every disk in macOS including SD-cards, external drives and mounted ISO- and DMG-files has a name and ID assigned to it. For example your internal harddrive in your Mac is normally disk1. The next is disk2 an so on.
To identify the correct disk, there’s a command you can run in your terminal. This command will show all external disks, and the correct identifier:
$ diskutil list external physical
This command will list all external disks connected to your Mac, for example:
$ diskutil list external physical /dev/disk5 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *127.9 GB disk5 1: Linux 134.2 MB disk5s1 2: Linux_Swap 268.4 MB disk5s2 3: DOS_FAT_32 3DS 127.5 GB disk5s3
This shows that my SD-card is identified as disk5. It also shows that my SD-card currently contains 3 partitions, one linux, one linux swap and a large fat32 named 3DS.
Format the disk
Now that we know that my disk is named disk5, we can erase it:
$ diskutil eraseDisk FAT32 NAME_OF_DISK MBRFormat disk5
The command is pretty simple:
diskutil [command] [filesystem] [new name of disk] [format] [disk identifier]
The above command will result in something like this:
Started erase on disk5
Creating the partition map
Waiting for partitions to activate
Formatting disk5s1 as MS-DOS (FAT32) with name NAME_OF_DISK
512 bytes per physical sector
/dev/rdisk5s1: 249674176 sectors in 3901159 FAT32 clusters (32768 bytes/cluster)
bps=512 spc=64 res=32 nft=2 mid=0xf8 spt=32 hds=255 hid=2048 drv=0x80 bsec=249735168 bspf=30478 rdcl=2 infs=1 bkbs=6 Mounting disk
Finished erase on disk5
Boom 💥 Now you’ll have a clean SD-card with a single FAT32 partition (32768 bytes/cluster) ((32kb/cluster)). Easy as pie 🥧
Bonus info: Other Partition Table Formats
In the example above I’m using MBR (Master Boot Record) as my Partition Table Format.
Master Boot Record (MBR) disks use the standard BIOS partition table. GUID Partition Table (GPT) disks use Unified Extensible Firmware Interface (UEFI). One advantage of GPT disks is that you can have more than four partitions on each disk. GPT is also required for disks larger than two terabytes (2 TB).
MBRFormat as stated in the example above you can use
Bonus info: Additional filesystems
Formatting a Disk to macOS Extended Journaled (JHFS+)
diskutil eraseDisk JHFS+ DiskName disk5
Formatting a Disk to macOS Extended (HFS+)
diskutil eraseDisk HFS+ DiskName disk5
Formatting a Disk to MS-DOS FAT-32
diskutil eraseDisk FAT32 DiskNameGoesHere dis55
Formatting a Disk to ExFAT
diskutil eraseDisk ExFAT DiskName disk5
Bonus info: Specify cluster size for the FAT-32 partition
Some devices are very specific and require a specific cluster size on a FAT 32 partition to work. In such cases, it is possible to use the
newfs_msdos command built into macOS to format the FAT32 partition with a specific cluster size definition:
sudo newfs_msdos -F 32 -c 128 disk5s1