Enabling OS X TRIM Support for Non-Apple SSDs

Photo of Greg

To my mind, it seems like a no-brainer to opt for a single solid state drive paired with a single spinning drive in a Mac Mini server. Doing that, however, means installing a non-Apple SSD, and that means jumping through a few extra hoops to get TRIM support from OS X.

One of the great things about moving to a Mac Mini dedicated server purchased outright and housed in a colocation facility is that you can take advantage of the speed of a solid state device as your primary drive for a modest up-front cost, rather than paying for it over and over again in the form of exhorbitant rental fees to a hosting provider every month. Given that as of this writing, a colo provider can install a 250 GB SSD for you as a boot drive for a couple of hundred dollars — and given that the 2012 Mac Mini comes either with dual 5400 RPM hard drives or dual SSDs (meaning in the latter case that you don’t then have a roomy second drive for backups and a boot drive clone) — I cannot think of any reason not to be running a Mac Mini server with a third party SSD as its primary drive.

If you do go down this route, however, there’s one fly in the ointment: Mac OS X provides built-in TRIM support only for Apple-installed SSDs. You’ll find arguments all over the web about the pros and cons of TRIM, and what it does or doesn’t do for speed or longevity. In my view, quite a few of these arguments are specious and not particularly well-informed, but I’m not going to spend any time diving into that kettle of fish here. For the purposes of this article, I’m just going to assume that you want TRIM support for your non-Apple SSD and leave it at that.

Most of the instructions you’ll find on the web for enabling TRIM support on non-Apple SSDs either recommend using a software utility to apply the patch for you or using a global search and replace on the relevant kernel extension from the command line. For example, as of 10.8.2, the search and replace sequence looks like this (DO NOT JUST COPY AND PASTE THIS):

sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x4D)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

However, I personally would rather not do this ‘blindly’ — I’d much rather be able to see what is being found by the search sequence and see if its context matches what is expected. I’d then like to make the replacement myself, provided the context matches, and go from there. For that, you can use a tool like Hex Fiend to make the specific changes you want and only the changes you want.

Start by making a backup of the kernel extension that needs to be modified:

sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage-backup

If anything goes wrong, you can restore from that backup by copying right back over the top of the modified file:

sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage-backup /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

Once this backup is safely in hand, you can temporarily make the file writable:

sudo chmod o+w /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

Now the easiest way to open the file with Hex Fiend is to navigate to the enclosing directory and then open a Finder window there, like so:

cd /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS

open .

That should pop open a Finder window containing both the original file and your backup. Drag the original file onto Hex Fiend to open it for editing. Use Hex Fiend to find the string “APPLE SSD” in the file, and change those 9 characters and only those 9 characters so they match the first 9 characters of your drive’s model identifier as shown in “System Information”. In this example, I have changed these characters to “Samsung S”. If there is a second sequence of “APPLE SSD TS”, do not change that sequence. Save the file and quit Hex Fiend.

Samsung SSD

Now go back to remove the temporary write permissions:

sudo chmod o-w /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

And let the system know to use the modification by touch the extensions folder:

sudo touch /System/Library/Extensions/

As user ‘shurcool’ notes in a forum posting about this procedure, you should not see any output of any kind at this stage. If you do see any output, you should immediately abort the procedure and restore from your backup as described above.

Finally, restart the machine and check in “System Information” under “Serial-ATA” to see if your SSD now has TRIM enabled. If it doesn’t, drop back and punt: restore the kernel extension from your backup, restart again, and have a look around for newer instructions than these.

Samsung SSD with TRIM Enabled

Note that any time a software update replaces this kernel extension, TRIM support will be disabled, and you’ll need to repeat the whole procedure again from the beginning, starting with making a new backup.

All material on this site is carefully reviewed, but its accuracy cannot be guaranteed, and some suggestions offered here might just be silly ideas. For best results, please do your own checking and verifying. This specific article was last reviewed or updated by Greg on .

This site is provided for informational and entertainment purposes only. It is not intended to provide advice of any kind.