Clicking the eject icon next to an external hard drive, USB flash drive, or SD card in macOS Finder only to be blocked by the notification: “The disk ‘[Disk Name]’ was not ejected because one or more programs may be using it. You can try to eject the disk again, or click Force Eject to eject it immediately” is a regular frustration for Mac users. While clicking “Force Eject” is tempting, forcibly detaching a drive while an active write buffer or file descriptor is open risks file system corruption, partition table damage, and data loss. In macOS, disk locks occur when background daemons, indexing services (such as Spotlight), or open background applications maintain active read/write handles on the external volume. This guide shows you how to safely identify the locked process using Terminal tools, terminate the offending process cleanly, and unmount your storage device without risking data corruption.
Why Does macOS Refuse to Eject External Drives?
macOS enforces POSIX file lock semantics. As long as any running process holds an open file handle referencing a mount point inside /Volumes/, the Darwin kernel blocks the unmount syscall. Common culprits include:
- Spotlight Metadata Indexing (mds / mdworker): When an external volume is connected, macOS immediately begins indexing documents, media metadata, and text strings for search queries.
- Time Machine Backup Daemons: Time Machine actively preparing or writing differential snapshot data to external backup partitions.
- QuickLook and Preview Daemons: Previewing images or documents in Finder leaving orphaned thumbnail rendering daemons connected to files.
- Background Applications and Cloud Sync: Photo management tools (Lightroom, Apple Photos), code editors (VS Code), or torrent clients holding open directory watches.
- Terminal Active Directory: An open Terminal tab whose current working directory is set to a subfolder on the mounted volume.
Method 1: Identify the Locking Process with lsof in Terminal
The standard Unix utility lsof (List Open Files) pinpoints the exact process and process ID (PID) holding an active lock on your external volume.
- Press Command + Space, type Terminal, and press Return.
- In Terminal, enter the following command (replace DiskName with the actual name of your mounted drive):
lsof | grep "/Volumes/DiskName" - Examine the output. The first column lists the application or daemon name (for example,
mds,QuickLook, orFinder), and the second column displays the PID number. - If the locking application is a standard desktop program (like Photoshop or VLC), switch to that application and quit it normally (Command + Q).
Method 2: Check for Spotlight Indexing
If the locking processes listed by lsof are mds or mdworker_shared, Spotlight is currently indexing files on the drive.
- Click the Spotlight (magnifying glass) icon in the macOS menu bar.
- If indexing is actively in progress, Spotlight will display an “Indexing [Drive Name]…” progress bar.
- Wait a few moments for the indexing run to complete. Once finished, Finder will eject the disk smoothly.
- To prevent Spotlight from indexing this external drive in the future, navigate to System Settings > Siri & Spotlight > Spotlight Privacy, click +, and add the external drive to the exclusion list.
Method 3: Ensure Terminal Is Not Parked on the Volume
One of the most common reasons an unmount fails for developers and power users is simply having an open Terminal shell parked inside the volume path.
- Check all open Terminal or iTerm windows.
- In each terminal session, type:
cd ~ - Press Return to return your shell session to your local user home directory.
- Attempt to eject the disk from Finder again.
Method 4: Safely Unmount via Disk Utility or diskutil Command
If Finder’s graphical interface continues to stall, using macOS’s low-level disk management commands provides a clean, graceful unmount.
- In Terminal, list mounted external volumes to find your drive identifier:
diskutil list - Locate your external disk identifier (for example,
disk4s1ordisk5). - Execute a safe unmount request:
diskutil unmount /Volumes/DiskName - If all partitions unmount cleanly, Terminal will return
Volume [DiskName] on disk4s1 unmounted, confirming that write buffers have flushed and you can safely unplug the cable.