Mac – cannot turn off spotlight indexing on external drive

backupexternal-diskspotlighttime-machine

I know this question has been asked before, but the solutions suggested are not working for me.

I just finished attaching a brand new external hard-drive and waiting for 14 hours for Time Machine to finish backing it up. Now, I cannot eject the drive. I get this error:

enter image description here

I don't want to "Force Eject…" because the last time I did that it destroyed the file system in a fashion that it could not be repaired. Thus the need for new external hard drive.

It seems like Spotlight indexing is the culprit here:

$sudo lsof | grep /Volumes/Backup/
mds          64           root   21r      DIR                1,7       2108  3347098 /Volumes/Backup/.Spotlight-V100/Store-V2/26061632-2165-4372-BACA-B77080B37A25
mds          64           root   24u      REG                1,7          0  3347143 /Volumes/Backup/.Spotlight-V100/Store-V2/26061632-2165-4372-BACA-B77080B37A25/journalExclusion
mds_store   310           root  txt       REG                1,7          8  3347107 

I have tried adding my Backup drive to the Spotlight privacy list.
This is apparently supposed to take effect immediately.
But it does not.

enter image description here

When I try to stop it using the command-line, here's what happens:

mdutil -v -a -s
/:
    Indexing disabled.
/.MobileBackups:
2015-12-06 14:53:51.707 mdutil[11654:1215293] Metadata.framework [Error]: mdsCopyStoreAttributes failed: (8) (os/kern) no access
    No index.
/Volumes/Backup:
    Indexing and searching disabled.
/Volumes/Backup/Backups.backupdb:
    Indexing enabled. 
    Scan base time: 1970-01-01 00:00:01 +0000 (1449442430 seconds ago), reasoning: '(null)'

also tried this …

$sudo mdutil -i off -d -E /Volumes/Backup/Backups.backupdb/
Password:
/Volumes/Backup/Backups.backupdb:
2015-12-06 16:42:53.210 mdutil[11822:1237806] mdutil disabling Spotlight: /Volumes/Backup/Backups.backupdb -> kMDConfigSearchLevelOff
    Indexing enabled. 

$sudo lsof | grep /Volumes/Backup/
mds          64            root   14r      DIR                1,7       1972  3359270 /Volumes/Backup/.Spotlight-V100/Store-V2/26061632-2165-4372-BACA-B77080B37A25
mds          64            root   22u      REG                1,7          0  3359315 /Volumes/Backup/.Spotlight-V100/Store-V2/26061632-2165-4372-BACA-B77080B37A25/journalExclusion
mds_store   310            root  txt       REG                1,7          8  3359279 /Volumes/Backup/.Spotlight-V100/Store-V2/26061632-2165-4372-BACA-B77080B37A25/0.indexIds

also tried killing the spotlight processes …

$ps -ax | awk '/[m]ds/{print $1}'
64
310
$sudo kill 64
$sudo kill 310
$sudo lsof | grep /Volumes/Backup/
backupd   11828            root    4w      REG                1,7       1453  3359329 /Volumes/Backup/Backups.backupdb/Alex’s MacBook Pro/2015-12-06-164406.inProgress/.Backup.471141846.204163.log
backupd   11828            root    6w      REG                1,7 1780482048  3366847 /Volumes/Backup/Backups.backupdb/Alex’s MacBook Pro/2015-12-06-164406.inProgress/88F84A3D-497C-4059-99AE-BF8C3C91534C/Macintosh HD/Users/alexryan/VirtualBox VMs/boot2docker-vm/boot2docker-vm.vmdk
mds       11849            root   12r      DIR                1,7       2108  3359270 /Volumes/Backup/.Spotlight-V100/Store-V2/26061632-2165-4372-BACA-B77080B37A25
mds       11849            root   17u      REG                1,7          0  3359315 /Volumes/Backup/.Spotlight-V100/Store-V2/26061632-2165-4372-BACA-B77080B37A25/journalExclusion
...

Is there any way that I can safely eject my external hard drive without destroying the file system again?

I am running OS X 10.11.1 on a Macbook Pro (Mid-2010).
The external drive is:
Seagate Backup Plus Slim 2TB Portable External Hard Drive with Mobile Device Backup USB 3.0

Solution:
I was a little nervous about killing the spotlight process because I wasn't sure if it would cleanly close the files it had opened before shutting down. I didn't want to corrupt my file system again.

Directly killing the processes did not work. They just came back to life again with new process ids.

However, using launchctl did work.
I was able to eject the drive.
And it looks like my file system did not get corrupted.

$sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
$ps -ax | awk '/[m]ds/{print $1}'
$sudo lsof | grep /Volumes/Backup/

Best Answer

Have you tried disabling spotlight on the device per terminal command?

Something like sudo mdutil -i off -d -E <mountpoint> to disable indexing, searches and to erase spotlight caches on the drive.

According to your output /Volumes/Backup has it disabled but /Volumes/Backup/Backups.backupdb hasn't, it may make a difference to run the command with that mountpoint.


Another solution suggested here is to stop the spotlight process entirely. You could do this with kill <procid> or launchctl. You can re-start it after ejecting the drive.

(The procid for the kill command is the one in the second column of your lsof results, or you can alternatively use use ps -ax | awk '/[m]ds/{print $1}' to get the procids for mds and mds_store.)