Skip to content

Instantly share code, notes, and snippets.

@sames
Forked from slagdang/enable_trim.sh
Created February 11, 2013 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sames/4754430 to your computer and use it in GitHub Desktop.
Save sames/4754430 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion, should work on earlier OSes too.
# Tested on 10.8.2, checked for proper operation on 10.8.0, but never booted with the modified kext.
#
# Original source: http://digitaldj.net/2011/07/21/trim-enabler-for-lion/
set -e
set -x
# Back up the file we're patching
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.original
# Patch the file to enable TRIM support
# This nulls out the string "APPLE SSD" so that string compares will always pass.
# on 10.8.2, the sequence is Rotational\0APPLE SSD\0MacBook5,1\0
# on 10.8.0, the sequence is Rotational\0\0APPLE SSD\0\0\0Queue Depth\0
# The APPLE SSD is to be replaced with a list of nulls of equal length (9).
sudo perl -pi -e 's|(Rotational\x00{1,20})APPLE SSD(\x00{1,20}[QM])|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|' \
/System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
# Force a reboot of the system's kernel extension cache
sudo touch /System/Library/Extensions/
echo "Now reboot!"
@slagdang
Copy link

I updated my version to support 10.8.3 and also to add some instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment