55

I have plugged an external disk to my Mac. Now, I want to eject it. But my Mac stubbornly refuses and says that an application may be using the disk.

I have not launched any app neither opened any file from the disk.

I have downloaded and installed the app What's Keeping Me? This app is quite nice. She tells me that the process mds is using my disk.

I have killed the process mds and several processes mdworker. These are for Spotlight. But such processes get spawned again.

How can I eject my disk from my Mac ?

I have Mac OS X 10.6.8.

2
  • Does just waiting for the processes to end work? I've found this works in practice for me.
    – Chogg
    Aug 28, 2017 at 19:13
  • This worked for me... sudo killall mds then quickly drag the drive to the spotlight privacy list (in spotlight preferences).
    – Mark
    Oct 12, 2020 at 18:08

10 Answers 10

33

You may try to unmount it from the command line:

diskutil unmount /Volumes/MountPoint

or with force:

diskutil unmount force /Volumes/MountPoint

If it's still failing, check what's using your disk:

sudo fs_usage -w -f filesys | grep Volumes

Or using lsof:

sudo lsof | grep Volumes

(Some processes only turn up when lsof is run as administrator.)


To disable temporary Spotlight, run:

sudo mdutil -a -i off

Then sudo mdutil -a -i on to re-enable.


Other apps which can be helpful: Whats Keeping Me.

3
  • 2
    I just found out that Spotlight (mds, mds_store, mdworker) will not be listed when I run lsof as user. However, sudo lsof | grep Volumes works fine. ("Whats Keeping Me" has an "As Administrator" checkbox, respectively.)
    – hans_meine
    Nov 22, 2015 at 16:32
  • 5 years later whats keeping me is obsolete, but fs_usage works great!
    – hans
    Nov 19, 2020 at 7:44
  • Simple diskutil unmount force worked well in my case, thank you! Apr 23, 2022 at 15:13
31

Simply turn indexing off for the drive and erase the contents of the journal on the volume. To do so, open Terminal and enter the following command:

sudo mdutil -Ei off "/Volumes/Name_of_Drive"

You must run this procedure as an admin. Enter your password when prompted. A reboot may be required.

Alternatively, as suggested by Simon White, just shut down the machine and then unplug the drive. The caveat is that the drive will start indexing when connected again, however.

9
  • 5
    simply stopping the process is enough. sudo mdutil -i off "/Volumes/Name_of_Drive" (-E erases and rebuilds the index). It should start scanning again next time you mount the drive. to disable scanning that drive permanently, use -d (sudo mdutil -d "/Volumes/Name_of_Drive"). See all these arguments and more by typing mdutil into your command line.
    – Dannid
    Dec 3, 2015 at 22:45
  • 2
    Liked the tip, but please don't suggest exiting after the command...I didn't notice and lost the history of output I had there.
    – ravemir
    Jan 30, 2016 at 23:56
  • 2
    After issuing the mdutil command, I still could not eject the disk. So I also issued "sudo killall mds", and that made it work. Mar 24, 2016 at 11:52
  • 1
    "Simply"? Who is your audience? Maybe typing a random command into a terminal is not simple. *nix obfuscates every tool into meaningless bunch of characters. How about "Simply 'man mdutil', oh, wow: "The mdutil command is useful for managing the metadata stores for mounted volumes." Oh now google metadata... Nothing simple about this.
    – iJames
    Oct 30, 2021 at 17:30
  • 1
    @njboot Thanks for asking. I'm averse to the use of "simply" in basically any software support or documentation discussion. It only belittles the reader who doesn't have a solid grounding. It's worse for a command line with a bunch of switches to do something potentially unsafe, permanent, hard to undo. So a more thorough answer with more clarity on risk needs to be considered. Posters should assume the requestor knows very little. I hope that clarifies what I was trying to say above. Rule of thumb: if you think it's simple, it's not...
    – iJames
    Nov 1, 2021 at 23:28
6

Often I find it is mds that is preventing me from unmounting a volume.

sudo killall mds

And then (quickly) try ejecting the volume again.

In my case, I am mounting another Mac's main volume on my current Mac. I don't want to disable Spotlight as I want indexing to resume when the external volume is returned to the other Mac (as its boot up volume).

2
  • Interesting. Maybe the "quickly" is key! Feb 19, 2016 at 16:07
  • Thanks! This is the only answer that worked for me other than force ejecting, which I wouldn't want to do.
    – addison
    Mar 23, 2016 at 14:15
4

You can try to force-quit Finder, this worked for me. Finder was hanging onto the USB drive, so force-quiting and re-launching released whatever the hang was.

4
  • how would one do that ? force quit finder ?
    – Ruskes
    May 18, 2015 at 3:45
  • Option+Command+ESC !
    – sdive
    Dec 7, 2015 at 15:26
  • But can this work in the Spotlight case of my question? Feb 19, 2016 at 16:04
  • This worked for me on Catalina. Apr 30, 2020 at 22:23
2

To prevent Spotlight from indexing the drive, create a plaintext file in TextEdit with no content, just the title of .metadata_never_index and save to the external. Uncheck use extension "txt" ... and tell TextEdit that yes, you do want to save it with a dot at the front (which will make it invisible.)

I'm not sure whether that will stop it right now, but it will prevent it in future.

Alternatively, make this Applescript into an app, to force eject [with the usual caveats on force-ejecting...]... credit to The MacTipper Blog

    property show_credits : true

set the_volumes to do shell script "ls /Volumes/"
tell application "Finder" to set the_HD to path to home folder as string

set ejectable_volumes to {}
repeat with i in (every paragraph of the_volumes)
    if the_HD does not start with i then
        set end of ejectable_volumes to (i as string)
    end if
end repeat
if (count of items of ejectable_volumes) is 0 then
    tell me to activate
    display dialog "Sorry, but there are no ejectable volumes."
else if (count of items of ejectable_volumes) is 1 then
    tell me to activate
    set the_result to item 1 of ejectable_volumes as string
    display dialog ("Eject \"" & the_result & "\"?") buttons {"No", "Yes"} default button 2 cancel button "No"
    set the_path to quoted form of ("/Volumes/" & the_result as string)
    do shell script "hdiutil eject -force " & the_path
else
    tell me to activate
    set the_result to choose from list ejectable_volumes with prompt "Please choose a volume to eject (You can select multiple items):" with multiple selections allowed
    if the_result is not false then
        repeat with j in the_result
            set the_path to quoted form of ("/Volumes/" & j as string)
            do shell script "hdiutil eject -force " & the_path
        end repeat
    end if
end if

if show_credits is true then
    tell me to activate
    set the_credits to button returned of (display dialog "This applescript brought to you by The MacTipper Blog.\n\nhttp://mactipper.com" buttons {"Don't Show Again", "Visit TMB", "OK"} default button 3) as string
    if the_credits is "Don't Show Again" then
        set show_credits to false
    else if the_credits is "Visit TMB" then
        open location "http://mactipper.com"
    end if
end if
7
  • Thank you. But... "to force eject [with the usual caveats on force-ejecting...]" This is worrying. If I agreed to taking the risk of corrupting the disk, I would simply unplug it. Aug 19, 2014 at 16:11
  • Then set the no spotlight flag & wait for it to see it & stop indexing.
    – Tetsujin
    Aug 19, 2014 at 16:16
  • Or, you can run sudo diskutil unmountDisk force /Volumes/Name_of_Volume from Terminal to forcibly do so. That script is not necessary.
    – njboot
    Aug 20, 2014 at 23:34
  • @NicolasBarbulesco These are not the same. Forcibly unmounting a volume is not the same as pulling the plug. In the latter case, you are physically removing power from the device in a sudden way, which, as one imagines, can cause damage to a magnetic disk rotating at several K rpm. In the former, your simply forcing the device to unmount the volume. The disk then spins down properly, and you pull the plug as you normally would. It's much safer.
    – njboot
    Aug 20, 2014 at 23:36
  • @njboot - I did not try your diskutil command. But I did try the equivalent with Disk Utility - to no avail. Aug 21, 2014 at 12:29
2

If you can’t disconnect a drive for any reason, you can simply Shutdown the computer. When the computer is off, you can safely disconnect the drive. Then start the computer. This will not only enable you to safely unplug the drive, but it will ensure that the mds process restarts in case it is actually hung.

If you have decided that you don’t want to use Spotlight with that drive, all you have to do to stop it from being indexed is add the drive to the Privacy tab of the Spotlight pane of System Preferences. Spotlight will ignore the drive.

Alternatively, if you do want to use Spotlight on that drive, then building an index the first time the computer sees the drive is a necessary evil. Once the index is built, it is updated with every change to every file, so it won’t make you wait again. But if you don’t see a progress bar in the Spotlight menu, then it is likely that mds is hung. Again, just Shutdown the computer in that case, and disconnect your drive.

5
  • 1
    Surely I can shut down the Mac. But this is not an option. Aug 21, 2014 at 12:34
  • I like the idea of having Spotlight know my disk. But I tried to make Spotlight ignore my disk for the moment. By using the System Prefs → Spotlight. This did not work : "Impossible because of an unknown error." Great error message ! Apple must have hired a defector from Micro$oft ! I also tried letting time act. I went to work and let Spotlight index the disk during the whole day. The evening, I came back, and the problem was still the same. Aug 21, 2014 at 12:51
  • I actually think the problem is that the mds is either not telling the system that it finished with the drive or not quitting after it's done and by doing so, holds the drive until the process is killed somehow (like a shutdown). If I see the mds not using the CPU while claiming to use the drive, I force eject the drive.
    – bauerMusic
    Dec 16, 2015 at 11:26
  • @bauerMusic - How do you "force eject the drive"? Feb 19, 2016 at 16:01
  • @NicolasBarbulesco The 'Force eject drive' is an option the system offers after a while. If you try to eject, it should say 'Trying to eject your drive' (or similar) and after a minute or so (of being unsuccessful), show another popup that have an option to force eject.
    – bauerMusic
    Feb 19, 2016 at 19:43
2

This problem has resurfaced on Catalina and none of these worked. For now I'll force eject and pull the drive anyway if it balks about it.

It’s an awful solution but I don’t see how it lowers risk or saves time versus killing the process that is stuck and possibly reading or writing data.

1

Another simple option is to eject it through Disk Utilities.

7
  • Did you read the comments in Tetsujin's answer? Disk Utility doesn't offer the "force" option
    – klanomath
    Dec 19, 2014 at 17:15
  • Just try it. A simple eject through Disk Utilities always works for me when an external drive of any kind won't eject because it's "in use." Dec 19, 2014 at 20:01
  • I did try to eject the drive with Disk Utility. But this did not work. Dec 23, 2014 at 15:09
  • 1
    Sorry to hear about that. Disk Utility ejects unmountable "in use" disks just fine on my unit which runs on 10.7.5. You might look into DiskWarrior. Dec 24, 2014 at 6:19
  • 1
    For whatever reason, using Disk Utility unmount command worked for me on a problem disk.
    – MiB
    Jan 2, 2015 at 5:34
1

I was cleaning up the thousands of CDs and DVDs that have accumulated over the decades and one got stuck in the external Mac Apple "Superdrive." I tried all the tricks to eject it, including rebooting. Then the OS wouldn't even show that the external drive existed. There were lots of suggestions online of how to eject the DVD and I tried most of them -- saving the most extreme for last, which involved prying open the housing with a flathead screwdriver.

My solution was to unplug the drive's USB from the Mac and plug it in to a Windows 7 laptop. The laptop found the correct driver and automatically ejected the disc. I posted this solution to the Mac support forum, but they took it down, because "the post was not a technical question."

I think the irony of Windows 7 fixing a "Superdrive" was too much for them.

0

You can tell Spotlight that it should never index that drive and then you won't have to worry about it.

In the 10.11 System Preferences there's an entry for 'Spotlight', which has a tab named 'Privacy'. Click '+', select your drive, and you're done. Just close System Preferences, wait a few seconds for the system to notice the update, and you should be able to eject. Now it won't start indexing the disk the next time you connect, so you won't have the problem again in the future.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .