[Nexus 6  General] AlkaliV2:
How to Trim Your Partitions in TWRP for a Truly Clean Install​

Do you flash a lot of ROMs? Do you ever think to yourself, "I wish I could go through extra steps to get a performance boost?" Do you lie awake at night and wonder what happens to your old data when the "mkfs.ext4" command gets passed in TWRP?

If you answered 'Yes!' to 2 or more of those questions then this guide is for you! I'll explain how to run the Trim command in TWRP prior to a clean flash of a ROM to give you peace of mind and perhaps a performance boost! I emphasize perhaps because the level of performance we're talking about here may or may not translate to real world applicability, but I do it anyway because science!

Steps!​

***WARNING: I highly recommend making a backup of your previous ROM because if you follow this guide we are going to send everything that isn't a binary zero to the data abyss until the only thing left on your device is a bunch of zeroes and TWRP. YOU'VE BEEN WARNED!***

Follow this method prior to a clean install only (TRIM command can be run at any time)

1.) Reboot to TWRP and Choose 'Wipe' from the main menu

2.) Choose 'Advanced Wipe' and select Data, System, Cache, and Dalvik Cache

OPTIONAL (Most people shouldn't do this step): If you copied your TWRP backup to your PC and want to wipe out your SD card select 'Internal Storage' otherwise

do NOT

check this option!

3.) Swipe to wipe the selected partitions

4.) Hit the home button and choose 'Mount'

5.) Mount the System partition (data and cache should already be mounted)

6.) Hit back or home, choose, 'Advanced', and then choose 'Terminal Command'

7.) Hit 'Select' in the bottom right corner to get to the command prompt (you'll be in the root directory)

8.) type this at the prompt, "fstrim -v /system" and hit enter (do not add the quotes)--it will show wiped space

9.) type this at the prompt, "fstrim -v /data" and hit enter (do not add the quotes)--it will show wiped space

10.) type this at the prompt, "fstrim -v /cache" and hit enter (do not add the quotes)--it will show wiped space

11.) Reboot to Recovery

12.) Install ROM and Gapps of choice then reboot to system when prompted

13.) Super clean install complete

But, Why?!

​

Here's a good article that sums up the answer to this question: http://arstechnica.com/gadgets/2015/04/ask-ars-my-ssd-does-garbage-collection-so-i-dont-need-trim-right/

F.A.Q.

​

Q: What does the TRIM command do?

A: When data is deleted by an operating system it gets flagged for deletion. Which basically means that it gets overwritten if the OS needs more space. Otherwise, it just sits there invisible on your drive for an arbitrary amount of time. I can't stand arbitrary. I prefer weekly.

Q: Who else uses this command?

A: fstrim specifically is a Linux/GNU command, but if you try to defrag an SSD in any modern version of Windows they pass this command as well. OSX recently decided to extend this trick to third-party drives that owners installed themselves. How...kind of them.

Q: Do I need to run this?

A: Absolutely not. Running fstrim just accelerates a process that Android will do itself eventually. There is even a hardware trim built into modern SSD drives, but I don't know that all smartphone flash memory has this feature.

Q: Break down the "fstrim -v / " command for me cause I wanna learn!

A: fstrim is the linux command, -v stands for verbose output so you can see the results, and / is your partition that you are calling to run trim on. We only have 3 partitions to choose from and those are: System, Cache, and Data.

Q: I get the error: fstrim command not found. Halp?

A: Reboot to TWRP, re-mount the System partition, and re-run the commands.

Q: Does it work on F2FS?

A: It seems to. I ran it on my data and cache partition after converting them to F2FS and it trimmed like normal.

Q: Running fstrim, rebooting recovery, and running fstrim nets the same output. Why?

A: I don't know why this happens. If you run fstrim twice in a row you'll see the first one gives a byte output and the second run shows zero if passed on the same partition. However, rebooting recovery and perhaps remounting the drives causes it to think trim hasn't been passed yet and does it anyway? I'm guessing honestly.

Q: Will you add more questions to this as members find errors in your guide and remind you that you left something out because you're human and clearly don't know everything?

A: Absolutely.