Beyond the GUI Disk Utility
Every Mac comes with a graphical “Disk Utility” application. For basic tasks like erasing a USB thumb drive, it is perfectly adequate. However, power users, system administrators, and developers often find the GUI application restrictive, slow, or prone to hanging when dealing with complex partition maps or failing hardware.
The true power of macOS disk management lies in its underlying command-line engine: diskutil.
This tool allows you to manipulate partitions, format drives, mount hidden volumes, and repair Apple File System (APFS) containers directly from the terminal, often succeeding where the GUI fails.
Step 1: Listing Available Drives
Before you format or modify a drive, you must know its exact device identifier. Unlike Windows, which uses drive letters (C:, D:), macOS uses a UNIX-style device node system (e.g., /dev/disk2).
Open the Terminal and type:
diskutil list
You will see a detailed output of every physical drive and virtual container attached to your Mac.
/dev/disk0is almost always your internal Mac SSD./dev/disk1is usually the synthesized APFS container holding your operating system data.- If you plug in an external USB drive, it will likely appear as
/dev/disk2or/dev/disk3.
Crucial Warning: Always triple-check the device identifier based on the SIZE of the drive listed in the output. If you accidentally target disk0 instead of disk2 in the next steps, you will instantly and permanently erase your entire Mac.
Step 2: Formatting an External Drive (Erase)
Imagine you have a corrupted 32GB USB flash drive mounted as /dev/disk2. You want to completely wipe it and format it as ExFAT so you can share large files between your Mac and a Windows PC.
The syntax for erasing a disk is:
diskutil eraseDisk [Format] [New_Name] [Device_Identifier]
To format the USB drive, type:
diskutil eraseDisk ExFAT "Transfer_Drive" /dev/disk2
The terminal will unmount the drive, destroy the old partition map, write a new Master Boot Record (MBR) or GUID Partition Map (GPT), format it with the ExFAT file system, and remount it on your desktop as “Transfer_Drive”—all in about three seconds.
Step 3: Unmounting Stubborn Drives
Sometimes, when you try to eject a drive by dragging it to the trash, macOS refuses, throwing a “Disk is in use” error. This happens when a hidden background process (like Spotlight indexing) refuses to let go of the drive.
You can force the drive to unmount using the terminal.
To cleanly unmount the entire disk hierarchy for disk2:
diskutil unmountDisk /dev/disk2
If it still refuses, you can apply the force flag (use with caution, as this can corrupt files that were actively saving):
diskutil unmountDisk force /dev/disk2
Step 4: Repairing Volumes
If an external drive is mounting successfully but behaving erratically (files disappearing, permissions errors), you can run a First Aid repair from the command line.
To verify the integrity of the file system on disk2 without making changes:
diskutil verifyVolume /dev/disk2
If the verification reports errors, you can instruct the utility to actively repair them:
diskutil repairVolume /dev/disk2
This is functionally identical to clicking the “First Aid” button in the GUI Disk Utility, but it provides a much more detailed verbose log of exactly which inodes and directory structures are being fixed.