Advertisement
Typhoon

TRIM - OS-X

Jun 26th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.13 KB | None | 0 0
  1. @ https://digitaldj.net/blog/2011/11/17/trim-enabler-for-os-x-lion-mountain-lion-mavericks/
  2.  
  3. TRIM ENABLER FOR OS X LION, MOUNTAIN LION, MAVERICKS
  4. NOVEMBER 17, 2011 ADMIN  26 COMMENTS
  5. OK. Now that Lion’s out, people want their SSD TRIM support back. I have one thing to say:
  6.  
  7. DO NOT USE TRIM ENABLER (VERSION 1.1 OR 1.2) TO ENABLE TRIM ON LION.
  8.  
  9. After a little inspection of this application, I found that instead of patching the file, it replaces an entire kernel extension. This means that when you use TRIM Enabler with Lion, it replaces a critical kernel extension, with lots of dependencies, with an older one (from Snow Leopard 10.6.8). This is bad. Very bad. While TRIM does become enabled, the kernel extension you now have has the potential to cause a ton of problems. That means anything from kernel panics, to disk I/O delays…and the dreaded spinning beach ball.
  10.  
  11. After confronting the developer, Oskar Groth (who I refuse to link to), via his blog’s commenting system, I was told that I was simply trolling and spreading fear (even though I offered the alternative I share here). Apparently, the next version of TRIM Enabler will correctly patch the file, instead of replacing it, but that hasn’t happened yet.
  12.  
  13. So, here’s the proper way to enable TRIM support. Run these commands in Terminal:
  14.  
  15. 1. Backup the file we’re patching
  16.  
  17. 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
  18. 2. If you’re using OS X Yosemite, disable KEXT signing
  19.  
  20. sudo nvram boot-args="kext-dev-mode=1"
  21. 3. Patch the file to enable TRIM support
  22.  
  23. FOR ML 10.8.5 AND MAVERICKS DP4+
  24.  
  25. 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
  26.  
  27. 4. Force a refresh of the system’s kernel extension cache
  28.  
  29. sudo touch /System/Library/Extensions/
  30. 5. Now Reboot!
  31.  
  32. a) If in the future you want to disable TRIM support
  33.  
  34. FOR ML 10.8.5 AND MAVERICKS DP4+
  35.  
  36. sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00).{9}(\x00\x54)|$1\x41\x50\x50\x4C\x45\x20\x53\x53\x44$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
  37.  
  38. sudo touch /System/Library/Extensions/
  39. b) If something goes horribly wrong, restore the backup
  40.  
  41. sudo cp /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
  42. All this patch does is simply replace the string “APPLE SSD” in the file IOAHCIBlockStorage with zeros. This happens to bypass the restriction of only allowing Apple branded SSDs. The backup of the original file is saved in the same directory as the original file.
  43.  
  44. To check if it worked, open up About This Mac, click the “More Info…” button then the “System Report” button. In the list on the left, choose “Serial-ATA”. Click on your SSD Drive and in the lower half of the screen you should now see “TRIM Support: Yes” instead of “No”.
  45.  
  46. Remember, if you have an older generation SSD, the hardware itself may not support TRIM …and therefore this patch won’t help you. This patch bypasses the restriction put in place by Apple to restrict TRIM support to Apple branded SSD drives.
  47.  
  48. You WILL need to re-apply this patch after each major update of OS X. That means for 10.7.1, 10.7.2, etc.
  49.  
  50. Credit where credits due, unlike the other TRIM Enabler, I originally found this on the InsanelyMac forums by digital_dreamer
  51.  
  52. As a note, the MD5 checksums for the original and patched file on 10.7.0 are as follows:
  53.  
  54. Original: 155b426c856c854e54936339fbc88d72
  55. Modified: 945944136009c9228fffb513ab5bf734
  56.  
  57. If you have already used the other TRIM Enabler, you can do the following:
  58. a) Attempt to copy and replace the extension from another Mac running the same version.
  59. b) Attempt to copy and replace the extension from the Recovery partition (Open up Disk Utility and Mount Recovery HD)
  60. c) Reinstall Lion
  61. d) Wait it out till 10.7.1 and hope that the extension is replaced in the update (but it may not be), then re-patch the file
  62.  
  63. UPDATE
  64.  
  65. a) Applying this patch does NOTHING else other than enable TRIM for 3rd party SSD drives. If you start seeing other problems, they’re not because of this.
  66.  
  67. b) Using this patch has no effect on hard disk drives. Firstly, mechanical hard disk drives do not understand the TRIM command, so it is discarded. Secondly, the Apple driver isn’t stupid enough to send TRIM commands to your hard disk. It knows the difference between an SSD and a HDD.
  68.  
  69. c) The wiping free space option is ALWAYS greyed out, even on Apple based SSDs. As reported here, you can try using `fsck -ffy` in Single User Mode, but personally I haven’t tested it. I’m sure there isn’t too much to worry about, especially if your drive has garbage collection.
  70.  
  71. d) If TRIM isn’t enabled after patching either a) you didn’t follow the steps correctly or b) your drive doesn’t support TRIM. If your drive doesn’t support TRIM, there’s no need to revert the patch, it simply has no effect.
  72.  
  73. e) The TRIM patch is NOT vendor/model specific. You can patch the driver for any damn SSD drive. Hell, you can apply the patch if you only use HDDs, but that’d be a little silly.
  74.  
  75. f) Regarding RAID and SSDs on Mac. I’m not completely sure but…if you’re using Apple RAID then I assume TRIM will work as usual. If you’re using a hackintosh and using a RAID controller (i.e. Intel ICHR), then no, RAID will not work. In either case, you should use a drive with garbage collection.
  76.  
  77. UPDATE 2
  78.  
  79. Regarding SSD durability and comments by Hyram:
  80.  
  81. The durability of SSDs has sweet fuck all to do with Mac OS X TRIM. It’s a fact, and always has been, that SSDs aren’t as durable as hard disks. This is simply due it it being a new technology. SSDs fail often due to the wear on the cells incurred by reads and writes.
  82.  
  83. If you don’t know what TRIM is, you probably shouldn’t be using a 3rd party SSD drive. Many have reported these commands don’t work, but that simply isn’t true. It just shows that a lot of people here don’t know how to use Terminal, don’t know what Bash is, nor Perl. These aren’t the sort of people that should be messing around with this. Instead, buy a SSD drive that offers garbage collection….or a Mac with an Apple SSD.
  84.  
  85. There has also been some confusion about garbage collection and TRIM. TRIM is ALWAYS preferred over Garbage Collection and will likely yield better results. If you have garbage collection, you don’t necessarily need TRIM, but it’ll probably offer better performance and there’s always a chance there’ll be a degradation of speed over time. Therefore, when using Garbage Collection, you may have to take the drive out and do a secure erase so that everything is re-marked as free space.
  86.  
  87. A drive will never fail because you haven’t enabled TRIM, even if it doesn’t have garbage collection. They simply become slower and the speed is not restored until you perform a destructive erase on the drive. However, drives that support TRIM, but do not have GC, and do not have TRIM enabled (in the OS) may fail more quickly than without enabling TRIM. In a very basic sense, since the SSD is no longer told what data to free up, when writing new data it will also re-write the deleted data, essentially causing more write cycles and wearing down the durability of the drive. If TRIM were enabled, the new data would be written without the deleted data, and hence less write cycles and extended durability. This ONLY relates to the combination of a drive that supports TRIM with no GC, while TRIM is disabled in the OS
  88.  
  89. Running garbage collection and TRIM at the same time is NOT a problem. They’re designed to work together. You can look at it like so: TRIM is called by your OS each time space is freed up. Garbage Collection is run by the drive’s firmware when idle and determines which parts of the drive can be cleaned up and rearranged. TRIM is obviously more efficient and obviously the drive’s firmware is aware of the TRIM commands and accounts for this.
  90.  
  91. As for the statements by Hyram, I believe some of them to be completely false. While it’s true that using TRIM and garbage collection at the same time is essentially using two mechanisms to do the same thing, the firmware on your SSD drive is designed to handle these things. All SSD manufacturers, GC or not, recommend the use of TRIM.
  92.  
  93. There is zero evidence that Apple has specific code to handle their specific SSD hardware for reading and writing. TRIM is a standardized ATA command. However, it IS likely that Apple has designed their integrated SSDs (particularly in the Air) to not overheat. Basically, your SSD is likely to fail just as much in your MacBook as if it were surrounded by the same temperature in any other laptop.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement