I know that the Linux kernel supports TRIM as of version 2.6.33, so there should be TRIM support in ubuntu.
Is TRIM enabled by default or do I need to change some settings or install additional software for it to work? If so, how?
Ubuntu 14.10 onwards
In Ubuntu 14.10 and 15.04, TRIMming happens automatically every week on all SSDs supported by
As of Ubuntu 14.04, scheduled TRIM is enabled by default for Intel, SAMSUNG, OCZ, Patriot and Sandisk SSDs. If you have another brand, you could disable the vendor check by running the following command:
(or just edit the file
Ubuntu 13.10 and Earlier
There are three ways to perform TRIM, manual, scheduled, and automatic:
In Ubuntu this can be performed with
however it is not needed when scheduled or automatic TRIM are enabled, as detailed in the sections below.
Note: For Ubuntu 11.04 and earlier systems, fstrim is not available so you have to use
Scheduled TRIM (Recommended)
This is the currently recomended method, and is planed to be activated per default for Ubuntu 14.04. Here's how to activate it manually in older versions of ubuntu (11.10 to 13.10):
Create a weekly CRON job script file:
Paste the following code in the file, then save and close the file:
Note that the above assumes that only your root filesystem
Make the script executable:
And finally test it:
If you see no errors, your cron job should be working fine.
Automatic TRIM (Deprecated, Slow)
Automatic TRIM has been supported since Ubuntu 10.10 (kernel 2.6.33) with the EXT4 file system. However, sending TRIM commands to the SSD in real-time - after every delete - has been recognized to make deletion much slower than usual on some drives. Therefore a weekly scheduled TRIM via a cron job (described above) is recomended.
To enable automatic TRIM on a drive or partition, they need to be mounted with the
Close and save fstab, then reboot and automatic TRIM should now be working.
Testing automatic TRIM
To test if TRIM is working issue the following commands (source):
From the output copy the number under
Run the following but replace
the output should be a long string of characters for those sectors
If you get only zeros then automatic TRIM is working. However if after removing the file the sectors are still not empty then wait a while and run the command again.
Note that if you are using encryption the solutions posted here so far won't help you, because you need to enable TRIM support in the encryption layer as well. This can be done with kernel versions 3.1+ and cryptsetup versions 1.4+, both of which are included in Ubuntu 12.04.
Find my guide on setting TRIM up for LUKS encrypted partitions here
How to Activate TRIM on LUKS Encrypted Partitions in Ubuntu & Debian
This step by step walkthrough will let you take advantage of the TRIM technology for your encrypted SSD partitions for cryptsetup 1.4 or higher and kernel 3.1 or higher. This leads to a hassle-free SSD experience because
Notebook with SSD as the single drive, Linux installed in single ext4 LVM root partition with LVM swap partition, both over LUKS encrypted logical partition.
TRIM is activated. Enjoy your hassle-free SSD!
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?