How to Enable TRIM on SSD in Ubuntu EASILY!

As more and more computers ship with SSDs and as individuals seek more performance, it becomes a norm to also maintain them. SSDs don’t operate like traditional hard-disk-drives, instead they use super fast flash memory to read and write data. Although it is possible SSDs can lose ‘some’ performance over time, this can easily be overcome by enabling TRIM. Windows and MacOS do this by default but on Linux we need to make it automatic so it does it periodically.

TRIM is used so that the OS tells the SSD that X sector is no longer in use and it can be wiped internally. It was introduced immediately after SSDs were first brought into the market.

Checking if TRIM is supported on your SSD.
First find the path where the SSD is located, type lsblk in a terminal. Then replace /dev/sdaX with the letter of the drive (eg: /dev/sda)

sudo hdparm -I /dev/sdX | grep "TRIM supported"

Setting up daily cron job
Now in enter the following command into the terminal. You can replace “gedit” with nano, xed (Linux Mint), vim etc
gksu gedit /etc/cron.daily/trim
Paste the following into the file
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG

Save and exit the file.

Testing if fstrim works
Enter the following command into a terminal sudo fstrim -v /
If it all went smoothly, you should get something similar to this /: 165.2 GiB (177398394880 bytes) trimmed

Making it executable
Enter the final command to make the file executable so it will fstrim periodically. sudo chmod +x /etc/cron.daily/trim

Now you if you had no errors, you have successfully enabled TRIM on your SSD!

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image