Spotlight not working after Casper Imaging in Target Disk Mode

cgiordano
Contributor

Hi all,

I've noticed that the machines I image in Target Disk Mode end up having issues with Spotlight. Nothing other than web results (URL, movies, etc) and dictionary terms show up; None of the local applications show. I've seen a couple other posts on JAMF Nation but they are all pretty old, pre-dating Yosemite so those results haven't really worked for me. I've tried the following to see if it would net me the desired results (they didn't):

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

Source

I've also tried this:

rm /.metadata_never_index
rm /.fseventsd/no_log
sudo mdutil -E -a -i on

Source
Pretty much any mdutil command presents me with the same error message:

~ Administrator$ sudo mdutil -E /
Password:
/:
    Indexing and searching disabled.
SEA-EIS-EWindell:~ Administrator$

If anyone has any suggestions that would be much appreciated. I really like the ease of Thunderbolt imaging, however if I continue to run into this issue I'm going to have to use Casper Imaging via another method.

Thanks!
Chris

3 ACCEPTED SOLUTIONS

davidacland
Honored Contributor II

I would also try deleting the .Spotlight-V100 at the root of the hard drive.

View solution in original post

asegura
Contributor

I created the following script as I was having the same issues. I worked with Apple Enterprise Support and they couldn't figure it out. After hours and hours trying to figure out the issue I discovered a file on the root of my hard drive labeled metadata_never_index. Hopefully the below script will help you. I named it Bruteforce_Spotlight for a little humor.

!/bin/bash

sudo rm -f /.metadata_never_index

sudo mdutil -i off / sudo rm -rf /.Spotlight*
sudo mdutil -i on /
sudo mdutil -E /

View solution in original post

cgiordano
Contributor

@asegura @davidacland It was a combo of both your suggestions that did it for me. I didn't even have to use any of the mdutil commands. I just ran the following:

sudo -Rf /.Spotlight-V100 /.metadata_never_index

After that I saw the indexing start and I was able to find Applications and files using Spotlight. I'll be adding that script to my imaging list.
Thanks for the suggestions and the help!
Chris

View solution in original post

15 REPLIES 15

strider_knh
Contributor II

You could try turning on indexing with eh following command: sudo mdutil -i on

After this you could try running your command again to see if it indexes.

davidacland
Honored Contributor II

I would also try deleting the .Spotlight-V100 at the root of the hard drive.

asegura
Contributor

I created the following script as I was having the same issues. I worked with Apple Enterprise Support and they couldn't figure it out. After hours and hours trying to figure out the issue I discovered a file on the root of my hard drive labeled metadata_never_index. Hopefully the below script will help you. I named it Bruteforce_Spotlight for a little humor.

!/bin/bash

sudo rm -f /.metadata_never_index

sudo mdutil -i off / sudo rm -rf /.Spotlight*
sudo mdutil -i on /
sudo mdutil -E /

cgiordano
Contributor

Thanks everyone. I'll give these a shot and see if they resolve my issue.

cgiordano
Contributor

@asegura @davidacland It was a combo of both your suggestions that did it for me. I didn't even have to use any of the mdutil commands. I just ran the following:

sudo -Rf /.Spotlight-V100 /.metadata_never_index

After that I saw the indexing start and I was able to find Applications and files using Spotlight. I'll be adding that script to my imaging list.
Thanks for the suggestions and the help!
Chris

elund
New Contributor III

I'm having trouble getting an Extension Attribute built to see if ".metadata_never_index" exists. What am I missing? Help is appreciated.
Ed

#!/bin/bash

###
#
#     Description:  Casper extension attribute that checks whether .metadata_never_index is
#                   detected.
#

if  -a '/.metadata_never_index' 
then
    resultString=".metadata_never_index detected"
else
    resultString=".metadata_never_index not detected"
fi

echo "<result>$resultString</result>"

exit 0

bentoms
Release Candidate Programs Tester

@elund I normally use -f for this.

Also, the IF LOOP would start like:

if [ -f '/.metadata_never_index' ];
then

There is always this site to double check against

Lastly, if the goal is to remove the file to enable spotlight.. You could add the rm command to the if looop if the file has been found.

elund
New Contributor III

@bentoms Thanks for the help! I appreciate it!

Kaltsas
Contributor III

So I have been experimenting with TMI for our desktop staff (especially with the new MacBooks starting to trickle in) and this had been frequently occurring. The above script works great (actually I had provided those exact instructions to our desktop team on fixing spotlight issues in the past, just didn't occur to me to dump it in a script until seeing this thread) , I did open a support call with our TAM but they reported JAMF wasn't ever able to replicate this issue.

In my case it is not 100% the issue will occur when deploying via TMI, but it only occurs when deploying via TMI.

paulvb
New Contributor II

I have been trying to find a solution to this issue and I am a bit confused by the previous posts. Which one of these scripts will reestablish Spotlight Search? And am I running these as scripts or executable commands?
Any help will be greatly appreciated.

davidacland
Honored Contributor II

In the OP case it was this command that works:

sudo -Rf /.Spotlight-V100 /.metadata_never_index

It can be run from a policy using the 'execute command' section.

cgiordano
Contributor

@paulvb I have this set as a script that runs during my imaging process. Note, however, that I have the priority set to "Reboot" so it runs when the machine is running the Post-Imaging processes, like binding to the domain, adding printers, etc.

I'm using this script:

sudo -Rf /.Spotlight-V100 /.metadata_never_index

Let me know if you have any further questions.
Thanks!
Chris

merps
Contributor III

@Kaltsas We see this only on brand new machines. If we erase the "fresh from Apple" disk with Disk Utility first, we don't see the problem. There's a chance that JAMF can't reproduce because they're using test machines instead of brand new, out of the box items.

Thanks to everyone for the fix - it will save us a step in the TMI process. We had tried removing the .Spotlight-V100 file, but hadn't come across the .metadata_never_index.

jhalvorson
Valued Contributor

The line that has been shared and posted above is missing the "rm" command.

sudo rm -Rf /.Spotlight-V100 /.metadata_never_index

paulvb
New Contributor II

Thanks jhalvorson. the rm command was the missing key.