Search This Blog

Enable SSD TRIM on Mac OS X Yosemite

I. enable TRIM

  1. Backup the file before 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
  2. [Yosemite only] Disable driver signature check by setting boot-args:
    sudo nvram boot-args="kext-dev-mode=1"
  3. [Yosemite only] Reboot after setting boot-args:
    sudo shutdown -r now
  4. Patch [Yosemite 10.10, Mavericks 10.9.5, 10.9.4] driver:
    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
    # for Mavericks and Mountain Lion from 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
     
    # for Mountain Lion from 10.8.1 to 10.8.2 and Lion 10.7.5
    #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
     
    # for Mountain Lion 10.8.0 and Lion 10.7.4 BELOW
    #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
  5. [Yosemite only] Rebuild kext cache (take a while):
    sudo kextcache -m /System/Library/Caches/com.apple.kext.caches/Startup/Extensions.mkext /System/Library/Extensions
    It will display the message like below:
    kext-dev-mode allowing invalid signature -67061 0xFFFFFFFFFFFEFA0B for kext IOAHCIBlockStorage.kext
    It is fine.
  6. Now it is time to reboot:
    sudo touch /System/Library/Extensions/
    sudo shutdown -r now





II. Recovering from stop sign on boot screen

If you stuck on the grey boot screen with a stop sign, here’s how you get back into OS X:
  1. Boot into recovery mode by holding CMD+R during boot
  2. If your volume was encrypted with FileVault, open Disk Utility and unlock/mount your drive
  3. Open the Terminal and run the command:
    nvram boot-args
    If it shows “kext-dev-mode=1″, you can skip to Step 5. If it says “error getting variable”, continue with Step 4.
  4. Run the command:
    nvram boot-args=kext-dev-mode=1
  5. Reboot back in to Recovery Mode again.
  6. Run these commands, replacing Your Disk Name with the name of your Mac disk (partition). You can type ls /Volumes to get a list of volumes. Note the quotes around the disk path and that there should be no / before System.
    cd "/Volumes/Your Disk Name"
    touch System/Library/Extensions
    kextcache -prelinked-kernel System/Library/Caches/com.apple.kext.caches/Startup/kernelcache -K System/Library/Kernels/kernel System/Library/Extensions 
    
  7. Wait until it finishes (can take as long as 5-10 minutes, don’t abort it) and reboot.
You should now be back in OS X with Trim enabled.




III. Revert back to original driver (TRIM will be disabled)

  1. Boot into recovery mode by holding CMD+R during boot.
  2. If your volume was encrypted with FileVault, open Disk Utility and unlock/mount your drive
  3. Open the Terminal and run the following commands: (Note: the quotes around the disk path and that there should be no / before System, except for the first part of the cp command.)
    nvram -d boot-args
    cd "/Volumes/Your Disk name"
    rm -rf System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
    cp -r /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
    
    chown -R root:wheel System/Library/Extensions
    chmod -R 755 System/Library/Extensions
    touch System/Library/Extensions
    kextcache -prelinked-kernel System/Library/Caches/com.apple.kext.caches/Startup/kernelcache -K System/Library/Kernels/kernel System/Library/Extensions
  4. Wait until it finishes (can take as long as 5-10 minutes, don’t abort it) and reboot.
You should now be back in OS X with Trim disabled.




see also

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I followed your instructions in the first part of this post. Very thing went as you stated. My question is how do I know if the TRIM turned on.
    Using the Alt+click the aapple.
    And then still holding the Alt clicking on “About this Mac”
    Still says “trim services: NO”

    ReplyDelete