How to Enable TRIM For SSD in Ubuntu

If you are using a Solid State Drive (SSD), you should know that you shouldn’t run any defragmentation or free space consolidation software on it. So how do you clean up your SSD and free up the empty space? TRIM is the command we use to inform the OS to do the cleaning job. Windows 8 comes with the “Optimize Drive” feature that can run the TRIM command regularly. What about Ubuntu? How can you enable TRIM for SSD in Ubuntu?

Note: The following steps will not work if you have encrypted your partition.

1. First, we have to make sure that the SSD in your computer supports TRIM. In Ubuntu, open a terminal and type:

If Ubuntu is not installed in the first partition of the SSD, change “sda” to reflect the partition where Ubuntu is residing. Scroll down the list till you see the “Enabled Supported:” section. Scroll down further and if you see something like “Data Set Management TRIM supported (limit 4 blocks)“, then TRIM is supported for your SSD.


2. Next, we need to test if the TRIM function is working in Ubuntu. In the terminal, type:

This will clean up the root partition of the SSD. If successful, you should see something like this:


3. Lastly, we will set a cron job for the OS to send the TRIM command once everyday.

Paste the following code into the blank area:

If your HOME directory in located on another partition, you can add additional line to the end of the above code:

If you want to save the output to a log file, you can use the following code instead:

Save (Ctrl + o) and exit (Ctrl + x).

Now, make the cron job executable:

That’s it.

Image credit: My SSD


  1. SATA TRIM can’t be queued. It can also take some time to process, and/or leave the drive “busy” (slower) for a time afterwards. Guess what, it turns out invoking it after every single delete is not automatically a good idea. Just going from the specification, If you want an OS to “support” such a unique command.

  2. if you prefer trimming while booting, add it to rc.local instead of creating a cron job. I wouldn’t use discard in fstab

  3. “Discard” in fstab kicks in after each and every delete. If you do a lot of deletes, “discard” can slow down your computer, negating the advantage of an SSD.

    If you shutdown and re-boot your computer regularly, m ake the trim process part your boot up or shutdwon routine. If your PC is always on, set up a daily or weekly cron job scheduled to run when you are least likely to use your computer.

  4. Based on the recommendation for the cron job script i made a semi-intelligent cronjob script which checks the usage of each partition and then decides how often (monthly, weekly, daily, hourly) the mountpoint should be trimmed. It can be found at github:

Comments are closed.

Sponsored Stories