Sweepfor Mac

Mac maintenance

How to Use diskutil on Mac (Repair, Format, Mount From the Terminal)

A practical guide to diskutil on macOS — list, mount, format, repair, and partition disks from the Terminal, with APFS containers and external drives.

10 min read

The Disk Utility app is fine for one-off operations, but if you’re working with multiple drives, scripting a setup, or trying to fix a stuck volume, the command-line diskutil is dramatically more powerful and (after a brief learning curve) faster. It’s what Disk Utility uses internally.

This is a tour of the commands that actually come up.

See what’s plugged in

diskutil list

Output looks something like:

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk3         1.0 TB     disk0s2

/dev/disk3 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +1.0 TB     disk3
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            12.6 GB    disk3s1
   2:              APFS Snapshot com.apple.os.update-... 12.6 GB    disk3s1s1
   3:                APFS Volume Preboot                 6.5 GB     disk3s2
   4:                APFS Volume Recovery                1.0 GB     disk3s3
   5:                APFS Volume Data                    487.2 GB   disk3s5
   6:                APFS Volume VM                      20.5 KB    disk3s6

The “synthesized” disk (disk3 here) is the APFS container, which is the layer that holds multiple volumes. Volumes inside a container share free space pool. Multiple physical disks can also share one container, though Apple doesn’t ship Macs with that setup.

The numeric IDs (disk0, disk0s1, disk3s5) are what every other diskutil command takes.

Detailed info on a single disk or volume

diskutil info /dev/disk3s5
diskutil info "Macintosh HD - Data"

Both work — you can pass a device path, a volume label, or a UUID. The output gives you the file system, capacity, mount point, encryption status, and a host of other fields.

For just one field:

diskutil info -plist /dev/disk3s5 | plutil -extract VolumeUUID xml1 -o - -

Hacky but it works. For most one-offs, diskutil info | grep is faster than building a parser.

Mount and unmount

diskutil mount /dev/disk5s1
diskutil mount "Untitled"

Mount a specific volume. Untitled is the default name macOS gives newly formatted volumes — pass either the device path or the label.

diskutil unmount /Volumes/Backup
diskutil unmount /dev/disk5s1

Unmounts a single volume. To unmount every volume on a physical disk (so you can eject):

diskutil unmountDisk /dev/disk5

To eject (unmount and power down):

diskutil eject /dev/disk5

If macOS says a volume is “in use” and won’t unmount, force it:

diskutil unmountDisk force /dev/disk5

This skips the “are any apps using files on this disk?” check. Use sparingly — apps with open files will get errors.

Tip: If you can't figure out which app is holding a volume open, lsof | grep /Volumes/Backup shows every process with an open file there.

Verify and repair

The CLI version of First Aid:

diskutil verifyVolume /dev/disk3s5
diskutil repairVolume /dev/disk3s5

verifyVolume is read-only. repairVolume makes changes. For containers (the APFS layer):

diskutil verifyDisk /dev/disk3
diskutil repairDisk /dev/disk3

For the boot disk on Apple Silicon, you need recovery mode for repair (covered in another guide). Verify works fine on the running system.

Format a drive (APFS)

The modern way to format an external drive as APFS:

diskutil eraseDisk APFS "MyDrive" /dev/disk5

This erases the whole disk, creates a GUID partition scheme, makes one APFS container that fills it, and creates one APFS volume named “MyDrive” inside.

For HFS+ (older format, sometimes needed for compatibility with older Macs):

diskutil eraseDisk HFS+ "MyDrive" /dev/disk5

For ExFAT (cross-platform with Windows):

diskutil eraseDisk ExFAT "MyDrive" /dev/disk5

For FAT32 (small drives, max 32 GB volume):

diskutil eraseDisk FAT32 "MYDRIVE" MBRFormat /dev/disk5

FAT32 needs an MBR partition scheme and an uppercase 11-character-max name.

Erase just one volume (without touching the container)

If you have an APFS container with several volumes and want to wipe just one:

diskutil eraseVolume APFS "NewName" /dev/disk5s2

The container, other volumes, and free space accounting stay intact.

Power users use Sweep tooEven when you know the Terminal commands, Sweep is faster and harder to mess up. Get Sweep free →

APFS containers and volumes

APFS volumes share a container’s free space, which is super flexible — you can have ten volumes adding up to “more” than the disk size, as long as the actual used space fits.

Add a new volume to an existing container:

diskutil apfs addVolume /dev/disk5 APFS "Projects"

That creates a Projects volume in container disk5’s scheme, sharing space with whatever else is in there.

Delete a volume:

diskutil apfs deleteVolume /dev/disk5s4

Resize a volume (rare on APFS — they auto-grow within the container — but useful if you want a hard cap):

diskutil apfs resizeContainer /dev/disk5s2 500g

That sets the container size to 500 GB. You’d use this when you want to leave space on the underlying disk for a non-APFS partition.

To list volumes in a container with their actual sizes (vs. logical):

diskutil apfs list

Shows every container, every volume, the role of each (System, Data, VM, Preboot, Recovery), and current vs. allocated sizes.

Snapshots

APFS supports cheap, copy-on-write snapshots. Time Machine on Apple Silicon Macs and on APFS-formatted external drives uses these.

List snapshots on a volume:

diskutil apfs listSnapshots /dev/disk3s5

Take a snapshot:

sudo tmutil localsnapshot

(That’s the Time Machine wrapper — it integrates with TM. There’s also apfs takeSnapshot for non-TM use, but it’s typically only invoked by tools.)

Delete a snapshot:

sudo diskutil apfs deleteSnapshot /dev/disk3s5 -name "com.apple.TimeMachine.2026-04-01-031022.local"

Encryption (FileVault and externals)

Encrypt an APFS volume:

diskutil apfs encryptVolume /dev/disk5s2 -user disk

You’ll be prompted for a password. -user disk means the password is on the volume; the alternative is -user "user_uuid" to tie it to a specific macOS user.

Decrypt:

diskutil apfs decryptVolume /dev/disk5s2

Both operations happen in the background and can take hours on large volumes — diskutil apfs list shows progress.

For your boot drive’s FileVault status:

fdesetup status

That tells you whether FileVault is on, off, or in the middle of encrypting.

Unicode names and weird quoting

Volume names with spaces need to be quoted:

diskutil eraseDisk APFS "External SSD" /dev/disk5

Names with quotes or special characters: just don’t. Stick to ASCII, no slashes, no quotes, no leading dot. Names that work in Finder don’t always survive diskutil.

RAID (if you really must)

diskutil can build RAID 0, RAID 1, and concatenated sets:

diskutil appleRAID create stripe "FastBackup" APFS /dev/disk5 /dev/disk6

Stripe two disks. For mirror:

diskutil appleRAID create mirror "Mirrored" APFS /dev/disk5 /dev/disk6

This functionality has been quietly de-emphasized — Apple recommends using Software RAID through Finder for most users, or specialty hardware for serious RAID. The CLI commands still work but Apple’s enthusiasm has waned. For most use cases, just buy a single fast SSD.

Repartition without losing data

Resize a non-APFS partition:

diskutil resizeVolume /dev/disk5s1 500g JHFS+ "NewVolume" 0b

That shrinks disk5s1 to 500 GB and adds a new HFS+ volume in the freed space. The 0b is “fill the rest.” You can chain multiple new partitions in one command.

For APFS, the container handles this automatically — just use apfs addVolume instead.

Skip the Terminal stackSweep does the same cleanup with a UI and a preview before anything is removed. Download Sweep free →

Make a bootable installer

The official “Install macOS” approach, scripted:

sudo /Applications/Install\ macOS\ Sonoma.app/Contents/Resources/createinstallmedia \
  --volume /Volumes/MyUSBDrive

createinstallmedia is technically not part of diskutil, but it pairs naturally — first you diskutil eraseDisk JHFS+ "MyUSBDrive" /dev/disk5 to format the USB stick, then you run createinstallmedia to write the installer to it.

Disk activity (when you suspect a hardware issue)

diskutil doesn’t show real-time IO, but it can run a SMART check:

diskutil info /dev/disk0 | grep -i smart

You’ll see SMART Status: Verified or Failing. The internal SSD on Apple Silicon Macs reports SMART status; older external SATA SSDs over USB usually don’t.

For deeper SMART data, brew install smartmontools and use smartctl:

sudo smartctl -a /dev/disk0

That gives you wear leveling, error counts, and total bytes written. If “Percentage Used” is climbing past 80%, the SSD is wearing out.

Securely erase a disk (caveat for SSDs)

diskutil secureErase writes patterns over a disk:

diskutil secureErase 0 /dev/disk5

The number is the security level (0 = single zero pass, 4 = 35-pass Gutmann). For SSDs, none of these are meaningfully more secure than a single zero pass — wear leveling means data lives on chips that won’t be touched. If the data was on an SSD and you need it gone, the only sure-fire approach is a full ATA Secure Erase (which diskutil secureErase doesn’t do reliably) or destruction.

For HDDs (mostly external now), secureErase 1 (single random pass) is fine.

Some scripting examples

A one-liner to find every external disk:

diskutil list external | grep "^/dev/" | awk '{print $1}'

A safety-checked external mount:

DEV=/dev/disk5s1
if diskutil info "$DEV" | grep -q "Mounted: No"; then
  diskutil mount "$DEV"
fi

A backup script that mounts, syncs, and unmounts:

#!/bin/bash
DEV=/dev/disk5s1
MNT=/Volumes/Backup

diskutil mount $DEV || exit 1
rsync -a ~/Documents $MNT/Documents
diskutil eject $DEV

When diskutil fails

Common issues and their causes:

“Resource busy” when unmounting: an app is using the volume. lsof | grep /Volumes/Name to find which.

“Operation failed” with no detail on eraseDisk: usually trying to erase the boot drive (impossible while it’s running) or a drive that’s still mounted.

“Could not start aborted operation”: the disk has hardware issues. SMART status will likely show errors. Stop and image the disk before further attempts.

“diskutil command not found”: only happens in stripped-down environments. The binary lives at /usr/sbin/diskutil. Check your PATH.

There’s a GUI for thatSweep wraps the Terminal cleanup in a UI you don’t have to memorize. Try Sweep free →

The cheat sheet

diskutil list
diskutil info /dev/disk3s5
diskutil mount /dev/disk5s1
diskutil unmount /Volumes/Backup
diskutil eject /dev/disk5
diskutil verifyVolume /dev/disk3s5
diskutil repairVolume /dev/disk3s5
diskutil eraseDisk APFS "Name" /dev/disk5
diskutil apfs addVolume /dev/disk5 APFS "New"
diskutil apfs list

Most of what you’ll do is some combination of those ten commands. The man page has dozens more, but they’re niche enough that you can look them up when you need them.

diskutil is one of those tools that feels obscure until you’ve used it three times — after that, the GUI’s slowness and obfuscation start to feel like a tax.

← Back to all guides