Attempting to safely disconnect an external SSD, USB flash drive, or SD card in macOS only to receive a dialogue notification stating: ‘The disk couldn’t be ejected because one or more programs may be using it. To eject the disk immediately, click the ‘Force Eject’ button’ prevents safe hardware removal. Unplugging a drive without dismounting risks volume partition damage, corrupted APFS/exFAT file directory trees, and partial data loss. While macOS offers a ‘Force Eject’ option, identifying and terminating the specific background process holding active file handles ensures that all pending write buffers flush safely to disk before disconnection.
Why Does macOS Refuse to Eject the External Volume?
macOS kernel file-locking mechanisms maintain locks on volume nodes until all active read/write handles close. The lock is commonly held by:
- Spotlight Metadata Indexing (mds / mdworker): macOS indexing service scanning the newly inserted external drive to catalogue file contents.
- Finder Window Open to Subdirectory: A minimized Finder window or open file dialogue actively focused on a directory path within the drive.
- Background Cloud Sync Utilities: Backup software or photo management tools indexing external folder trees.
- Terminal Active Working Directory: An open Terminal shell whose current working directory (
pwd) resides inside the mounted drive volume.
Step 1: Identify the Locking Process with lsof in Terminal
The Unix lsof (list open files) utility identifies the exact Process ID (PID) locking the external filesystem.
- Open Terminal from Spotlight (Cmd + Space).
- Execute the following command to query all processes holding open handles on the volume (replace
VolumeNamewith your exact external drive name in quotes):lsof | grep "/Volumes/VolumeName" - Terminal will output columns displaying
COMMAND,PID, andUSER. For example:QuickLook 14820 user /Volumes/ExternalSSD/Video.mov - Identify the process name causing the lock (e.g.
QuickLook,Finder, orTextEdit).
Step 2: Terminate the Conflicting Process Safely
Once you have identified the PID from Step 1, close the application or terminate the specific background thread.
- If the process is a normal application (like Preview, QuickTime, or Word), switch to the app and close any open documents located on the drive.
- If the process is an unmanaged background daemon, terminate it using its PID in Terminal:
kill -9 14820 - If the locking command is
Terminalitself, ensure you navigate back to your home directory:cd ~ - Return to Finder and attempt to click the Eject icon next to the volume again.
Step 3: Prevent Spotlight from Indexing the External Drive
If mds or mdworker_shared locks the drive during indexing, exclude the volume from Spotlight search.
- Open System Settings on your Mac.
- Navigate to Siri & Spotlight > scroll down and click Spotlight Privacy.
- Drag your external drive icon from the desktop or Finder sidebar into the Privacy list window.
- Click Done. Spotlight will immediately release all open metadata locks on the volume.
Step 4: Relaunch Finder to Clear Stale Directory Locks
A corrupted Finder window handle frequently retains phantom locks on unmounted folders.
- Press Cmd + Option + Esc to open the Force Quit Applications window.
- Select Finder from the list.
- Click Relaunch in the bottom right corner.
- Finder will reboot its user interface shell, clearing lingering volume handles.
Step 5: Safely Unmount the Disk via diskutil
If Finder refuses to eject the drive, use macOS disk utility commands to flush write caches and unmount cleanly.
- Open Terminal.
- List all connected drives to find your disk identifier (e.g.
disk4s1):diskutil list - Unmount the volume safely using:
diskutil unmount /Volumes/VolumeName - If an uncooperative daemon persists, issue a graceful diskutil force unmount:
diskutil unmount force /Volumes/VolumeName - When Terminal reports ‘Volume successfully unmounted’, disconnect the hardware cable.