Skip to content

Instantly share code, notes, and snippets.

@woods
Created August 12, 2012 20:19
Show Gist options
  • Select an option

  • Save woods/3334193 to your computer and use it in GitHub Desktop.

Select an option

Save woods/3334193 to your computer and use it in GitHub Desktop.

Revisions

  1. woods created this gist Aug 12, 2012.
    22 changes: 22 additions & 0 deletions enable_trim.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/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!"