Storage

Can't eject a disk on your Mac? Find what's using it

"The disk wasn't ejected because one or more programs may be using it." Something has a file open on the drive. Find it in Terminal, close it, and eject cleanly instead of pulling the cable.

Find what’s using it

Ask lsof for every open file on that volume. Give it the mount point, and it lists everything on that file system:

sudo lsof /Volumes/MyDrive
COMMAND     PID   USER   FD   TYPE DEVICE  SIZE/OFF   NODE NAME
zsh       61022    you  cwd    DIR   1,22       352      2 /Volumes/MyDrive
mds_store   412   root   12r   REG   1,22   1048576  10483 /Volumes/MyDrive/.Spotlight-V100/...
Preview   70511    you   18r   REG   1,22   2817332  20177 /Volumes/MyDrive/scan.pdf

Replace MyDrive with the name in Finder’s sidebar. Use quotes for names with spaces: "/Volumes/My Drive". sudo matters: without it, you won’t see system processes like Spotlight or Time Machine, which are often the culprits.

The FD column tells you how it’s being used. cwd means a process’s current folder is on the drive, typically a Terminal tab. r, w or u after a number means a file is open for reading, writing or both.

About lsof +D. Many guides suggest lsof +D /Volumes/MyDrive. It walks every folder on the drive, which is very slow on a large disk, and it doesn’t report anything the mount point form misses. Use the plain path.

Fix the usual culprits

ProcessWhyFix
zsh, bash, fish with cwdA Terminal tab is inside the drivecd ~ in that tab, or close it
An app (Preview, VS Code, Photos, Music)A file or library on the drive is openClose the file or quit the app
mds, mds_stores, mdworkerSpotlight is indexingWait, or exclude the drive (below)
backupdTime Machine is backing up to itWait, or stop the backup from the Time Machine menu
QuickLookUIService, FinderA preview or Finder window is reading a fileClose the window; relaunch Finder if it sticks
node, vite, dockerA dev server or container is using a project on itStop the server or container

To stop Spotlight indexing a drive:

sudo mdutil -i off /Volumes/MyDrive

Or add the drive in System Settings › Spotlight › Search Privacy.

Check whether Time Machine is running:

tmutil status

Running = 1 means a backup is in progress.

Then eject

From Terminal, the clean way:

diskutil eject /Volumes/MyDrive

If it still refuses, diskutil usually says which process is in the way:

Volume MyDrive on disk4s2 failed to unmount: dissented by PID 61022 (/bin/zsh)

That PID is your answer. Check it with ps -p 61022 -o command.

Force unmount: only as a last resort

diskutil unmount force /Volumes/MyDrive

This unmounts the volume even with files open. Apps that had files open lose access instantly. If an app was writing, that file can end up incomplete or corrupt. Use it only when:

  • You’ve checked lsof and nothing is writing (only r file descriptors or cwd), or
  • The holder is a hung process you can’t quit.

For a whole physical disk with several volumes:

diskutil list
diskutil unmountDisk force /dev/disk4

Never force unmount while Time Machine is backing up to the drive, or while a copy is in progress. Wait for it to finish, or cancel it first.

If nothing shows up

  • Wait 30 seconds and try again. Spotlight and QuickLook often let go on their own.
  • Log out and back in. This closes everything you started.
  • Restart. If the disk still won’t eject after a restart, check it with Disk Utility › First Aid.

Doing this with Stat Space

Stat Space’s Disk tab lists every volume with an eject button for external drives. If macOS refuses to eject, it shows which apps are holding the disk, so you can close them without running lsof. The Devices tab lists external storage too and links back to Disk when an eject fails. Both are free.

Questions

Is it bad to unplug a drive without ejecting?

It can corrupt files that were being written and, less often, the file system itself. macOS also caches writes, so data you just copied may not be on the drive yet. Eject first whenever you can.

Why does Spotlight stop my disk from ejecting?

When a drive is connected, mds and mdworker index it and hold files open while they do. Waiting a minute often fixes it. To stop it for good, add the drive to System Settings › Spotlight › Search Privacy.

Why can't I eject a disk image or network share?

The same cause: an open file or a Terminal shell whose current folder is on it. lsof /Volumes/<name> works for disk images and most network mounts too.

Get started

Know what your Mac is doing, without adding to it.

Free, no account. Pro is $9.99 once for the first 100 buyers.