Skip to content

Instantly share code, notes, and snippets.

@clarencesong
Last active June 6, 2025 19:19
Show Gist options
  • Select an option

  • Save clarencesong/3768688 to your computer and use it in GitHub Desktop.

Select an option

Save clarencesong/3768688 to your computer and use it in GitHub Desktop.
Enable TRIM in OS X 10.7.5 to 10.9.5

Enable TRIM on non-Apple SSDs in OS X

NOTE: This is tested on the versions mentioned in the title, and NOT earlier or later versions. YMMV.

Run the following commands in Terminal…

Backup the original driver:

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

Modify the driver (choose only one of the following lines, based on the version):

# 10.9.4 & 10.9.5
sudo perl -pi -e 's|(^\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

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

# 10.7.5, 10.8.1, 10.8.2
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

Run these commands in succession to clear the system caches to enable OS X to pick up the modified driver:

sudo kextcache -system-prelinked-kernel
sudo kextcache -system-caches
sudo touch /System/Library/Extensions/

Restart the Mac.

@RJVB
Copy link
Copy Markdown

RJVB commented Apr 26, 2020 via email

@clarencesong
Copy link
Copy Markdown
Author

@RJVB I've only tested this on SATA SSDs, as this was the only way to get TRIM back in the day. (Later versions of OS X supported the trimforce command.) Sorry, I don't know of a way to check if TRIM is actually working at a lower level.

@RJVB
Copy link
Copy Markdown

RJVB commented Apr 26, 2020 via email

@PhshPhan
Copy link
Copy Markdown

Thanks man. Worked on my evo860 SSD on my mid-2012 i5 on OSX 10.9.5 after the initial software update following reinstallation of OS X.

@Starkoman
Copy link
Copy Markdown

Hi there — Can confirm this code works on 2006 MacBook Pro 17" Core2Duo 3GB RAM with cheap Fanxiang S101 1TB SSD.

Had to paste into Terminal a couple of times, reboot, no joy in System Info — so tried final time but pasted all three of the second set all at once — rebooted again and System Info confirmed "Trim Enabled: Yes". Thank you so much! Very pleased.

Thanks for figuring this out.

@Starkoman
Copy link
Copy Markdown

P.S.: That's on Mac OS X 10.7.5. Lion (!). Works like a charm.

@RJVB
Copy link
Copy Markdown

RJVB commented Aug 6, 2024

Do you know if it's supposed to work with external drives?

Still doesn't, not for me in any case.

So periodically I just take the ones I use to a Linux rig that has Paragon's ufsd driver installed. I checked with them: even with the free version their HFSx support is good enough that you can run fstrim on them safely.

@clarencesong
Copy link
Copy Markdown
Author

On more recent macOS releases, there are other ways to enable TRIM, including external SSDs.

Check out this article: Will your new SSD support TRIM and SMART?

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