This morning I tried to open Mail on my Mac and was using Spotlight for it as usual. But despite a dictionary-, web- and wikipedia-search nothing was found.
The Spotlight index was somehow corrupted and I tried to fix it by running mdutil (manages the metadata stores used by Spotlight). Unfortunately my boot volume was not in the list of indexed volumes.
$ sudo mdutil -as
Trying to turn the indexing on was not possible for “/” or “/Volumes/Macintosh\ HD”.
$ sudo mdutil -i on -E /Volumes/Macintosh\ HD
/:
Error: unable to perform operation. (-400)
No index.
After I deleted the Spotlight directory and killed all “mdworker” processes via the Activity Monitor, mdutil was finally willing to start rebuilding the index. A system reboot should have made it as well as killing the mdwokers directly, I guess.
$ sudo rm -Rf /.Spotlight-V100
$ sudo mdutil -i on -E /
My Spotlight also broke. I followed your guide up to the last command. But when i try to “restart” the Spotlight with “$ sudo mdutil -i on E /” i get a “Error: unable to perform operation. (-400) No Index”. Error.
Do anyone have a solution?
A restart seems to get the index kick-started.
Hi Jacob, removing all mdworker processes seems to be essential. Good to hear that a system restart started the indexing. A colleague said “sudo killall -9 mdworker” is the recommended way to get them all out of the system.
It worked! I just quit the SystemUIServer with Activity Monitor before using your command lines. Thank you
Thank you all, this solved the problem here:)
Still actual info as of 2013… deleted /.Spotlight-V100 … However now I had no mdworker at all, so I killed mds instead and viola – got a new mds and a bunch of hard working mdworker reindexing my drive
Have been suffering the same basic problem, but with an unpleasant twist: the instructions given here worked, but only until the next restart. In the hope that my solution might save someone else some grief, here’s what I eventually realised:
The problem wasn’t caused by the restart itself, but by the fact that the Applescript I use at startup automatically mounts two volumes on a Synology NAS (the DS412+). Though Spotlight indexes these quite happily, the process of mounting them hangs some part of its internal workings. Bizarre, but true. Equally bizarre: accessed via the Finder, Spotlight was still fully functional. This probably comes down to yet another bug in Lion – the same script works fine on a second Mac running Mountain Lion.
It’s quite possible that mounting the volumes via System Preferences/User & Groups/Login Items would get around the issue I had, but I didn’t test it since there’s a disadvantage to using that which I wanted to avoid (doing so automatically opens a window, rather than just mounting the volume).
The eventual solution was to add the killall command to my script, so that as soon as the volumes are mounted, mds is forced to restart (and with it, any instances of mdworker). With that in place, everything was back to how it should be, including all of my Smart Mailboxes that search the Entire Message. For reference, here are the relevant bits of my script:
set TheName to “YourUserName”
set TheWord to “YourPassword”
set nDrives to {“YourVolume1”, “YourVolume2”}
repeat with TheVolume in nDrives
set TheVolume to “afp://192.168.0.x/” & TheVolume
try
mount volume TheVolume as user name TheName with password TheWord
on error ThisError
ErrorRoutine(ThisError)
end try
end repeat
do shell script “sudo killall mds” password TheWord with administrator privileges
on ErrorRoutine(ThisError)
tell application “Finder”
display dialog ThisError buttons {“Okay”} default button 1 giving up after 15
end tell
end ErrorRoutine
One other thing worth mentioning: if you need to rebuild the Spotlight index for your Mail folder, the appropriate Terminal command is ‘mdimport ~/Library/Mail/’.
Thank you for the write up. I ran into the same issue with an old 10.75 System and the same mounting script in place. Your shell script addition fixed that nicely.
All I had to do was delete the “/.Spotlight-V100” folder and then restart the system to have the indexing rebuild itself. Glad it’s fixed again, a bunch of other solutions didn’t work for me.