Spotlight Trouble
Fixing Spotlight search in OS X Mavericks
Alongside with many others who were tantalized by the free upgrade to the latest OS X version (Mavericks it is, if you haven’t received the memo), I jumped at the chance to breathe new life into the 2008 iMac I have at work.
Everything worked fine — no incompatible apps, no hiccups during installation and booting up… until I realized the incessant ticking of the hard disk read head after logging in to Mavericks for the first time. Things slowed to a crawl — Finder would crash every time I decided to open a window, and unforgivingly slow even after relaunching it. Icons would disappear from the dock and sidebar in Finder. More importantly, Spotlight refused to work, insisting that I give it time to estimate the time needed to re-index my iMac.
Brushing it off as the consequence of my (not-so-wise) choice of an upgrade instead of a clean install, I stopped the reindexing progress, purged old indexes and restarted it. One thing that you should know before you start:
sudo requires administrative privileges, and when combined with the “rm” command and the “-rf” flag, has the potential to cause major damage to your OS when misused.
In other words, sudo is perfectly safe to use unless you have no idea what you’re doing. Do copy the following command, character-by-character, to stay on the safe side of the fence.
# Disable indexing
sudo mdutil -i off /# Purge old indexes
sudo mdutil -E /# Remove any possible traces of index left
sudo rm -rf /.Spotlight-V100/*
sudo rm -rf /var/folders/*# Restart indexing
sudo mdutil -i on /
I left for home hoping that it will all be fixed tomorrow…
Additional note: Michael noted that the command to initialize reindexing may break if there is a conflict with Spotlight’s privacy preferences — if all mounted and available HDs are added to the privacy list, Spotlight will not have anything to index to begin with, causing a failure to rebuild index. Make sure you check that beforehand, by ensuring that at least the main Macintosh HD is available for indexing.
Not.
Autumn dawn melted away into morning, and the Spotlight is still stuck at “Estimating indexing time…”. Oh, snap.Thinking that I have just messed up my workstation and mentally preparing myself for a clean reinstallation (possibly much to the annoyance of the IT department staff, “told you that you shouldn’t upgrade until we test everything out!”), I tried a last-minute solution that screams desperation.
Since Finder refuses to cooperate, I had to access the /Library/Spotlight folder through terminal, and check what’s in there:
cd /Library/Spotlight
ls
Voila! I was greeted with several files that clearly do not belong to the OS itself, one of which I suspect was dropped in by Microsoft Office. It might not be the actual culprit, but considering that how Microsoft ships out half-baked apps for Mac — I have lost count of the number of times Excel has crashed on me in the middle of working on something — I decided to purge the folder.
sudo rm -rf /Library/Spotlight/*
Bam! I also checked my own library (~/Library/Spotlight) just in case, but the directory does not exist. Good, that’s going to save me a few seconds.Without further ado, I rebooted the Mac.
Booted up, logged in. So far, so good.
Checked Spotlight and was still greeted with a “Estimating indexing time” but Finder is now a lot more responsive, and no longer crashes. No more missing icons in the sidebar and dock. So far, so much better.
I checked Spotlight a few minutes later, and voila—it tells me that it will need 12 hours to re-index my iMac. At least it is working, for now.
Update: It seems that Time Machine will fail, or stall, when the Spotlight Index is corrupted. After rebuilding the said index, my Time Machine backups proceeded without a hitch as before.