3

I am trying to repair permissions on my external HD. I cannot empty my trash when it is plugged in, because I get a bunch of "such file is in use". I read online that this might be resolved by repairing permissions on the drive. I am currently unable to unmount the drive because it is in use the second I restart or unplug and replug it in. I used lsof to see what is using it but I am unable to understand this and can't seem to find a clear guide to learn what this means. The output is below:

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mds 59 root 23r DIR 1,9 1701 5 /Volumes/SEAGATE mds 59 root 31r DIR 1,9 1701 5 /Volumes/SEAGATE 

Command

ps ax | egrep '[ /](PID|mds)' 

Output

PID TT STAT TIME COMMAND 660 ?? Ss 0:12.49 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Support/mds 673 ?? Ss 0:08.68 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mds_stores 

Command

/usr/bin/sudo kill 660 

Output

//new line$ 

Command

sudo lsof /dev/disk2s2 

Output

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mds 1599 root 11r DIR 1,8 1764 5 /Volumes/SEAGATE 

In that order

If I run the bash file several times in a row I can get

PID TT STAT TIME COMMAND 1737 ?? Ss 0:00.69 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Support/mds 

But the drive is still locked by mds

Just to show that the exception was added, here are screenshots:

enter image description here

enter image description here

7
  • Could you add to your question the output of: df and of lsof /dev/disk… where /dev/disk… is the name of your external disk SEAGATE. I don't talk here of its mount point which is /Volumes/SEAGATE . Commented Jul 2, 2015 at 12:09
  • added, but df would only allow for the mount point Commented Jul 2, 2015 at 12:16
  • Now run lsof /dev/disk2s2. Commented Jul 2, 2015 at 12:20
  • I did run that in the image above? It returns the same thing, which is nothing Commented Jul 2, 2015 at 12:23
  • Now that you are sure nothing is reading your external disk, you can unmount it forcibly with: umount -f /dev/disk2s2. Next open Disk Utility select it, click [Verify Disk], if necessary [Repair Disk]. Commented Jul 2, 2015 at 13:52

2 Answers 2

2

Too fast diagnosis

I read online that this might be resolved by repairing permission on the drive.

Unfortunatly, from the description of your problem, this is wrong. What need to be repaired is the filesystem on your external disk SEAGATE.

Analysis of lsof

The output of your lsof command tells that the command mds (1st column) is actually reading your filesystem /volumes/SEAGATE (last colume). To learn more about this fantastic command, just read the manual which is coming with MacOS X:

man lsof 

mds is a MacOS X server in charge of providing an access to the metadata of all your filesystems. Its most important clients are Finder and Spotlight.

If you can't eject your external disk, this is legitimate and due to mds still reading it. If you nonetheless extract it, you will surely corrupt its filesystem.

Free and repair the filesystem

Now that it is corrupted, here is how to fix this.

  1. Open System Preferences > Spotlight select Privacy window and add (+) your SEAGATE external disk to stop Spotlight to try to index it.

  2. If mds is still running:

    ps ax | egrep '[ /](PID|mds)' 

    You will have to kill it:

    _pid_to_kill=`ps ax | egrep '[ /]mds' | awk '{print $1}'` if [ "${_pid_to_kill}" ] ; then echo "${_pid_to_kill}" | while read _pid ; do /usr/bin/sudo kill ${_pid} done fi 

    Check with lsof that your SEAGATE disk is now free:

    lsof /Volumes/SEAGATE 

    If this is OK, GOTO 4.

  3. If killing mds doesn't free /Volumes/SEAGATE then there is another process accessing this filesystem through mds. (This might be an anti-virus or a crapware. And this is quite another size of investigation). In this case, the fast path will be to stop launchd from starting mds.

    Proceed as follows:

    cd /System/Library/LaunchDaemons /usr/bin/sudo launchctl unload com.apple.metadata.mds.plist 

    Check that you don't have anymore mds process:

    ps ax | egrep '[ /](PID|mds)' 

    Check with lsof that your SEAGATE disk is now free:

    lsof /Volumes/SEAGATE 

    This should be OK, GOTO 4.

  4. Start Disk Utility and check your disk SEAGATE. I suspect that some repairs will be needed. In this case repair it.

    Eject it, and check that you don't have any more any "file in use" error message.

  5. Open System Preferences > Spotlight select Privacy window and remove (-) your SEAGATE external disk to permit Spotlight to index it.

  6. If you passed strep 3. where you had to stop launchd from starting mds you will have to enable this function back (otherwise a lot of thing managing your filesystem will fail).

    Proceed as follows:

    cd /System/Library/LaunchDaemons /usr/bin/sudo launchctl load com.apple.metadata.mds.plist 
1
  • I did as you suggested, lsof now returns nothing but the drive is still unmountable due to disk utility claiming its still in use. Even ps ax | egrep '[ /](PID|mds)' returns nothing. You have been so very helpful. I don't know if you have any other suggestions? But you have answered the original question, this is just a matter of finding what is using the drive. Commented Jul 2, 2015 at 11:04
2

It appears that Spotlight is indexing this drive. There could be a problem that is causing Spotlight to hang up and constantly pound this drive.

The mds process is the metadata server. Try killing this process and then tell spotlight to not index this drive.

To disable spotlight indexing go to System Preferences -> Spotlight -> Privacy and add the disk to the exclusions list. You might have to kill mds and restart it to get spotlight to stop the indexing.

Not sure that this is your problem, but it would be a good place to start.

2
  • 1
    So I kill mds and it just shows up with a new PID. IT WONT STAY DEAD! Commented Jun 30, 2015 at 20:39
  • 1
    Yeah that shouldn't be a huge problem, just make sure that you modify the Spotlight configs then kill it and let it respawn. It should not show up in the lsof command anymore if things are correctly set up. Commented Jun 30, 2015 at 21:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.