brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: diskutil eraseDisk ExFAT formats a USB drive that Mac and Windows can both use

Disk
~/tips/tip-macos-diskutil-erasedisk-exfat

diskutil eraseDisk ExFAT SHARED MBR disk4

Formats a USB drive as ExFAT so it works on both a Mac and Windows.

A USB stick that has to work on my MacBook and on a Windows PC needs a file system both understand. APFS is out, so the choice is between FAT and ExFAT, and Apple’s own guide makes that choice easy.

Disk Utility’s guide says: MS-DOS (FAT) for disks of 32 GB or less, ExFAT for anything bigger. For the partition scheme, Apple says Master Boot Record gives compatibility with all Windows computers, while GUID Partition Map works with some newer ones. From the terminal it’s one command:

diskutil eraseDisk ExFAT SHARED MBR disk4

That erases the whole disk4, writes a new MBR partition map and creates one ExFAT volume named SHARED. diskutil listFilesystems shows every format name the command accepts, such as ExFAT and "MS-DOS FAT32". For a small 16 GB stick you’d swap ExFAT for MS-DOS FAT32.

In Disk Utility, choose View > Show All Devices first and select the device at the top of the tree, not the volume under it. Otherwise the Scheme pop-up menu isn’t there. For these Windows formats Apple also notes that the volume name can be 11 characters at most, which is why I keep it short and in capitals.

The caveat is that the command really does erase everything, and the wrong number erases the wrong disk. Run diskutil list external physical right before it, check the size and the name, and only then type the identifier. My habit would be to unplug every other external drive first, so there’s simply nothing else to get wrong.

Further reading: diskutil man page (SS64 mirror of Apple's man page), Format a disk for Windows computers in Disk Utility, Partition schemes available in Disk Utility

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (44) All topics

Link