thumb

After working with an external hard drive (further simply - disk) I want to cleanly unmount it. But to my surprise when pressing the ‘eject’ button Finder warns me with the following error messages:

The volume can't be ejected because it's currently in use.
The disk "Elements" wasn't ejected because one or more programs may be using it.

For regular users, I recommend reading another article about this issue. It describes how to do almost the same thing using the Activity Monitor application, instead of using commands in the Terminal. This article is intended for advanced users (when the “QuickLookUI” process is not the cause) and/or for coder’s fun :smiley:

After several attempts, I tried to use the umount command in the Terminal app, and get the same error:

$ umount /Volumes/Elements
umount(/Volumes/Diskname): Resource busy -- try 'diskutil unmount'

And the same with the diskutil unmount command recommended in previous error message:

$ diskutil unmount /Volumes/Elements
Volume Elements on disk4s1 failed to unmount: dissented by PID 16314 (/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc/Contents/MacOS/QuickLookUIService)

What causes this error

This error message is self explanatory. It means that we are trying to eject the disk that is currently in use. If we have any file stored on the disk open in any app, macOS may prevent us from ejecting the disk so we don’t lose any of our data. If this happens, we just need to close the file in question and try again eject the disk. But I’m sure I have not launched any app neither opened any file from the disk.

In some cases, macOS will allow us to “force-eject” the disk, but we may still lose data, so force eject is not reasonable.

What I have:

How to solve it

First I found this article on the Apple Support website, but unfortunately it did not help. In short, it says to logout, then login again and try to eject the disk. And if you still can’t eject the disk, it suggest to shut down the computer and then unplug the disk… :confused:

As I’m in the middle of doing multiple tasks, logging out and logging in is not preferred as is the installation of third party software like the What’s Keeping Me? or the Why not unmount?. I prefer a clean unmount of the drive. So I need to find the solution myself.

As far as I’m aware, I’m not using the disk but Finder says I do, so I must be wrong. Now I need to know what app is using my disk so I can properly quit that app and eject my disk. To solve this, we will use the Terminal app and few console tools. All the tools are built-in in macOS, so we do not need to download or install anything. Let’s begin!

Launch the Terminal app from the Utilities folder of your Applications folder, or use Spotlight to find it.

Firstly we need to find the proper name of our disk:

ls /Volumes/
Elements  Macintosh HD

“Macintosh HD” is an internal MacBook drive, and “Elements” is my external hard drive. So, in my case, the name of the disk is “Elements”. In your case, the disc name will be different.

The below commands assume this is Elements, but replace Elements with the correct disk name if it’s something different.

Now let’s find out which system process uses our disk. For this we use the lsof tool.

sudo lsof | grep /Volumes/Elements

We must run the above command with sudo (as an Admin). For this we need to enter our password when prompted.

Note! Do not forget to replace “Elements” with the name of your disk before pressing Enter.

Enter your password after prompted and then watch the magic happen…

mds          83               root   21r      DIR               1,15        288          2 /Volumes/Elements
mds          83               root   22r      DIR               1,15        288          2 /Volumes/Elements
mds          83               root   24r      DIR               1,15       2208         21 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35
mds          83               root   25r      DIR               1,15        288          2 /Volumes/Elements
mds          83               root   27u      REG               1,15          0         72 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/journalExclusion
mds_store   252               root  txt       REG               1,15         24        620 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexDates
mds_store   252               root  txt       REG               1,15         10        621 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexGroups
mds_store   252               root  txt       REG               1,15          8        627 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexCompactDirectory
mds_store   252               root  txt       REG               1,15       2056        626 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexDirectory
mds_store   252               root  txt       REG               1,15       8192        588 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexCompactDirectory
mds_store   252               root  txt       REG               1,15      13108        582 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexGroups
mds_store   252               root  txt       REG               1,15      16448        587 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexDirectory
mds_store   252               root  txt       REG               1,15         96        619 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexIds
mds_store   252               root  txt       REG               1,15      32768        581 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexDates
mds_store   252               root  txt       REG               1,15      65536        630 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.directoryStoreFile
mds_store   252               root  txt       REG               1,15      72256        628 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexArrays
mds_store   252               root  txt       REG               1,15     131072         57 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/reverseDirectoryStore
mds_store   252               root  txt       REG               1,15     131072        580 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexIds
mds_store   252               root  txt       REG               1,15     131072        591 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.directoryStoreFile
mds_store   252               root  txt       REG               1,15    2097152        584 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexTermIds
mds_store   252               root  txt       REG               1,15    2097152        586 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexPositionTable
mds_store   252               root  txt       REG               1,15    4194304        589 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexArrays
mds_store   252               root   27r      DIR               1,15       2208         21 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35
mds_store   252               root   42r      REG               1,15      72256        628 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexArrays
mds_store   252               root   44r      DIR               1,15       2208         21 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35
mds_store   252               root   65u      REG               1,15         28         28 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/indexState
mds_store   252               root   66u      REG               1,15     593920         55 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/store.db
mds_store   252               root   67u      REG               1,15     593920         56 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/.store.db
mds_store   252               root   68r      REG               1,15          8        627 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexCompactDirectory
mds_store   252               root   69u      REG               1,15       4096        618 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexHead
mds_store   252               root   70u      REG               1,15         96        619 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexIds
mds_store   252               root   71u      REG               1,15         24        620 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexDates
mds_store   252               root   72r      REG               1,15       1694        622 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexPostings
mds_store   252               root   79r      REG               1,15       2056        626 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.indexDirectory
mds_store   252               root   99u      REG               1,15      65536        630 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/0.directoryStoreFile
mds_store   252               root  103u      REG               1,15       4096        579 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexHead
mds_store   252               root  106u      REG               1,15     131072        580 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexIds
mds_store   252               root  108u      REG               1,15      13108        582 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexGroups
mds_store   252               root  109u      REG               1,15    2097152        583 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexPostings
mds_store   252               root  110u      REG               1,15    2097152        584 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexTermIds
mds_store   252               root  111u      REG               1,15    8388608        585 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexPositions
mds_store   252               root  112u      REG               1,15    2097152        586 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexPositionTable
mds_store   252               root  113u      REG               1,15      16448        587 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexDirectory
mds_store   252               root  114u      REG               1,15       8192        588 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexCompactDirectory
mds_store   252               root  115u      REG               1,15    4194304        589 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.indexArrays
mds_store   252               root  116u      REG               1,15     131072        591 /Volumes/Elements/.Spotlight-V100/Store-V2/C59C29F8-4296-456C-B45B-CBD4AF706C35/live.0.directoryStoreFile
QuickLook 16314             arthur    3r      REG               1,15 2283237221       3207 /Volumes/Elements/PATH/TO/FILE/filename.mov

The output of the command may seem complicated in understanding, but it is not. The first column indicates the running process, and the last column indicates the file on our disk that is currently in use. In my case, three processes are running: mds, mds_store and QuickLook. Also, the hidden folder .Spotlight-V100 and the file filename.mov are used. So now I know what is preventing me from ejecting my disk.

The mds and mds_store processes are related to Spotlight. You can learn more about it here. Running these processes mean that the Spotlight is currently indexing our disk. We can leave the disk turned on for a while, so that the Spotlight could finish its work, or we can force the process to stop.

The QuickLook process is a feature that was introduced in the Mac OS X 10.5 Leopard. You can learn more about it here. I noticed that when I use the Quicklook feature to preview a video in any format, the process keeps active even when the Quicklook window was already closed. If I preview any other file like PDF or JPG the disk can be ejected normally. Why does Quicklook preventing me from ejecting my disk? I suspect that this is just a bug.

Once we know what process is preventing us from ejecting our disk, we can force it to stop. For this we use the killall tool.

sudo killall mds

We must run the above command with sudo (as an Admin). For this we need to enter our password when prompted.

Note! Do not forget to replace “mds” with the name of process that you want to stop before pressing Enter.

Also we can do this by using the Activity Monitor.

Finally, issue the following command to unmount the disk, replacing “Elements” with your actual disk name.

diskutil unmount /Volumes/Elements
Volume Elements on disk4s1 unmounted

Conclusion

That’s it, you’re done. Now our disk should be safely ejected. So simple isn’t it?

If you are having trouble fixing this problem with the instructions above, but are being able to solve this problem with any another method please describe it in the comment section below. Thanks!

If this article has helped you solve the problem then please leave a comment :smiley:

Thanks for reading!