Skip to content

Instantly share code, notes, and snippets.

@steveswing
Forked from clarencesong/os-x-enable-trim.md
Created October 13, 2012 15:28
Show Gist options
  • Save steveswing/3885000 to your computer and use it in GitHub Desktop.
Save steveswing/3885000 to your computer and use it in GitHub Desktop.
Enable TRIM in OS X 10.8.2
Enable TRIM on non-Apple SSDs in OS X 10.8.2 Mountain Lion.
WARNING: This is ONLY tested on 10.8.2, and NOT earlier or later versions. YMMV.
Technical note: The driver changed in 10.8.2 and similar perl commands that worked in earlier OS X versions did not work for me once I updated to 10.8.2.
Run the following commands in Terminal…
1. Backup the original driver. Added -p to preserve original metadata about the file
sudo cp -p /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage ~root/IOAHCIBlockStorage-original
sudo echo /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage > ~/root/IOAHCIBlockStorage.original.path
sudo cp -p /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
cp -p ~root/IOAHCIBlockStorage.trim-enabled /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
2. Modify the driver
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
2a. Attempt to make it look like we were never here:
sudo touch -acfm -r /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
3. 2 commands to clear the system caches to enable OS X to pick up the modified driver
sudo kextcache -system-prelinked-kernel
sudo kextcache -system-caches
4. Restart the Mac
@itavero
Copy link

itavero commented Nov 19, 2012

Has this been tested on 10.8.2 12C60?

@steveswing
Copy link
Author

@itavero sorry I didn't see you comment until now. I have been using this with 12C60 for about 5 months and have had no discernable issues. Seems to be working well... Finding this is a good reminder of not updating to 10.8.3 until I find if there are any changes required and corresponding updates to this script.

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