38

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.

  • Does just waiting for the processes to end work? I've found this works in practice for me. – Chogg Aug 28 '17 at 19:13
25

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.

  • 4
    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 '15 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 '16 at 23:56
  • @njboot - No. The command "history" just gives me the history of the commands entered, it does not give me back their result. – Nicolas Barbulesco Feb 18 '16 at 17:43
  • 1
    After issuing the mdutil command, I still could not eject the disk. So I also issued "sudo killall mds", and that made it work. – Thomas Tempelmann Mar 24 '16 at 11:52
19

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.

  • 1
    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 '15 at 16:32
4

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).

  • Interesting. Maybe the "quickly" is key! – Nicolas Barbulesco Feb 19 '16 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 '16 at 14:15
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
  • 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. – Nicolas Barbulesco Aug 19 '14 at 16:11
  • Then set the no spotlight flag & wait for it to see it & stop indexing. – Tetsujin Aug 19 '14 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 '14 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 '14 at 23:36
  • @njboot - I did not try your diskutil command. But I did try the equivalent with Disk Utility - to no avail. – Nicolas Barbulesco Aug 21 '14 at 12:29
1

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.

  • 1
    Surely I can shut down the Mac. But this is not an option. – Nicolas Barbulesco Aug 21 '14 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. – Nicolas Barbulesco Aug 21 '14 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 '15 at 11:26
  • @bauerMusic - How do you "force eject the drive"? – Nicolas Barbulesco Feb 19 '16 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 '16 at 19:43
1

Another simple option is to eject it through Disk Utilities.

  • Did you read the comments in Tetsujin's answer? Disk Utility doesn't offer the "force" option – klanomath Dec 19 '14 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." – Tim Undheim Dec 19 '14 at 20:01
  • I did try to eject the drive with Disk Utility. But this did not work. – Nicolas Barbulesco Dec 23 '14 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. – Tim Undheim Dec 24 '14 at 6:19
  • 1
    For whatever reason, using Disk Utility unmount command worked for me on a problem disk. – MiB Jan 2 '15 at 5:34
1

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.

  • how would one do that ? force quit finder ? – Buscar웃 May 18 '15 at 3:45
  • Option+Command+ESC ! – sdive Dec 7 '15 at 15:26
  • But can this work in the Spotlight case of my question? – Nicolas Barbulesco Feb 19 '16 at 16:04
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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.