Summary
- Don’t try to eject a drive when you’ve got files open or are copying large amounts of data to or from it.
- If nothing seems to be using the drive, use Terminal to highlight any background services that are to blame. Remove the drive from Spotlight indexing to avoid being unable to eject it.
- Repair the drive using Disk Utility to ensure there are no hardware problems.
Ever tried to eject an external drive, only for macOS to tell you that it’s still in use when you’re absolutely certain that it isn’t? It’s a common and annoying problem, but is fixable. Here’s how I did it.
Use Terminal to See What’s Using the Drive
The error message saying that your drive “wasn’t ejected because one or more programs may be using it” can be confusing.
Normally, if you’ve still got a file open, or you’re copying data to or from the disk, the message will tell you what app is involved. Close the file, wait for the task to finish, and you’re good to go.
But sometimes, there doesn’t appear to be any app using the drive, yet even the “Try Again” and “Force Eject” options won’t work. This likely means that there’s some background task still running. The only way to find out what it is is through a terminal command.
Open Terminal (press Command+Spacebar and type “Terminal”) and type in the following command, leaving a space at the end.
sudo lsof
Then drag your drive icon into the Terminal window to add the full path to it, so that it looks like this:
sudo lsof /Volumes/[your drive]
Hit Enter, and type in your password if prompted.
The resulting output will list all the apps that are using the drive in the column labeled “Command.” If you recognize the culprit, you might be able to shut down the app or go into Activity Monitor and quit the relevant process. In my case, and what seems like the most common issue, the process “mds” was accessing the disk’s contents.
“mds” stands for Metadata Server, and means that Spotlight is indexing the drive’s files. To begin with, you can try and wait for it to finish, although in my experience that might never happen. If it doesn’t, you can remove the drive from Spotlight altogether.
Remove the Drive From Spotlight Indexing
Spotlight is a Mac search tool you can access by pressing Command+Spacebar on your keyboard. Among other things, it indexes all the files and folders on your external drives so you can easily access them. But sometimes this can cause problems. I had two flash drives and an external SSD that I couldn’t eject, and Spotlight was the reason in all cases.
The solution is to remove the drive from Spotlight indexing. The downside to this is it means you won’t be able to search quickly for files on your external device. On the other hand, it does mean you’ll be able to eject it properly.
Go to System Settings > Spotlight and scroll down to click the “Search Privacy” button. Drag your external drive into the window that opens and click “Done.” This will prevent Spotlight from indexing the drive.
Now, you should be able to eject your drive as normal.
If you can’t drag the external disk into the search privacy window, it might mean that Spotlight has already begun indexing it. If this happens, log out of your Mac, remove the drive, log back in, reattach the drive, and then try again. It should work this time and fix the problem.
Repair the Drive
The final step is to repair your external drive, just to ensure that there aren’t any hardware issues. You have to do this part last because the repair process involves ejecting the volume, which it won’t be able to if you haven’t fixed it.
Open Spotlight by pressing Command+Spacebar and start typing “Disk Utility.” Select it from the list when it pops up.
Under “External” in the sidebar, select the Volume for your external drive (not the drive itself) and go to First Aid > Run. Disk Utility will eject and scan it, then repair it if necessary.
It’ll also flag up any warnings that could be a sign of any hardware problems. If you see something here, it’s time to consider replacing the drive so you don’t get hit by hardware failure in the future.
With all the steps complete, you should now be able to eject the disk without any problems. Repeat these steps for any subsequent drives that you can’t eject.
There are lots of generic tips for removing drives that macOS can’t eject. These might include force-quitting Finder, logging out of your user account, shutting the lid on your MacBook, or even just yanking it out and dealing with “Disk Not Ejected Properly” warning.
Unless you’re writing to the drive at the time, your data is unlikely to get corrupted. But it’s still preferable to fix the problem, and these steps should help you do that.