Skip to content

Instantly share code, notes, and snippets.

@woods
Created August 12, 2012 20:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save woods/3334193 to your computer and use it in GitHub Desktop.
Save woods/3334193 to your computer and use it in GitHub Desktop.
Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion.
#!/bin/bash
#
# Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion
#
# 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
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x51)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' \
/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

slagdang commented Jan 8, 2013

Doesn't work on 10.8.2 Mountain Lion because this checks the whole string before the APPLE SSD to be nulled and the first character of the string after. In 10.8.2 the string after no longer is "Queue Depth", an additional SSD marker string "APPLE SSD TS" has been inserted so the first character after is "A" (\x41).

See my fork for a fix.

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