system-log:tyr

Skyscraper I love you

How to stop USB drives from spinning up unnecessarily on OS X 10.7 Lion

If like me you use a Mac Mini as a media centre underneath the TV you may have a number of USB drives attached to it. Since upgrading to OS X 10.7 Lion I’ve found these are getting spun up at least once an hour even when the system is entirely unused, which is noisy, a waste of power, and probably shortens the drives life. After some digging around I finally managed to fix this. Read on for more details.

The key to unlocking this problem was to find out what was actually accessing the drive. Even with every user application closed something was accessing the drive. Being a fan of DTrace I used the hfsslower.d script from Brendan Gregg., you could probably do something similar with the built in fs_usage.

Running that like so

sudo dtrace -s ./hfsslower.d | grep -v syslogd | grep -iv terminal

Then listening out for the drives spinning up, it became clear these few lines were showing up every time.


2012 Jan 29 16:27:52 fseventsd R 8 0 0000000000336b92
2012 Jan 29 16:27:52 fseventsd R 7 0 0000000000336b92
2012 Jan 29 16:27:52 fseventsd R 8 0 00000000003165d4
2012 Jan 29 16:27:52 fseventsd R 7 0 00000000003165d4
2012 Jan 29 16:27:52 fseventsd R 8 0 0000000000416eea
2012 Jan 29 16:27:52 fseventsd R 8 0 0000000000416eea
2012 Jan 29 16:27:52 fseventsd R 8 0 0000000000416eea
2012 Jan 29 16:27:52 fseventsd R 2 0 0000000000416eea

Ah ha. fseventsd is the deamon that logs file system activity. The data is then consumed by Time Machine and Spotlight when they want to see what files have recently changed so they can back them up or index them.

I really don’t need any Spotlight indexing on these drives, nor are they going to be backed up by Time Machine so we can turn this off. This may also break ‘Versions’ on the drive, I’ve not tested it. For good measure Spotlight indexing is also disabled for the drive.

I started by adding the drive to the ‘Privacy’ section in the Spotlight preference in System Preferences, then it’s time to get the Terminal out. Assuming your drive is mounted at /Volumes/externalDrive perform the following: (thanks to Metaxis at apple.stackexchange.com for the pointers)


mdutil -i off /Volumes/externalDrive
cd /Volumes/externalDrive
rm -rf .fseventsd
rm -rf .Spotlight-*
mkdir .fseventsd
touch .fseventsd/no_log .metadata_never_index

Then eject and remount the drive.

I haven’t had the drives spin up unexpectedly since!


Categorised as: Mac


2 Comments

  1. my ninja power, my number cruncher says:

    Excellent! thanks for this. I tried it, and oddly after re-mounting the drive, Spotlight immediately started indexing it. The .metadata_never_index file is there at the root of the external drive; i’m on 10.7.3

  2. Stu says:

    Hi,

    I want to use this technique, but can you tell us how to reverse it? Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>