Software & AppsOperating SystemLinux

How To Enable TRIM for Your SSD in Ubuntu

Ubuntu 9

In this article, we will be discussing how to enable TRIM for your Solid State Drive (SSD) in Ubuntu. TRIM is an essential feature for maintaining the performance of SSDs and should be enabled for any SSD under Ubuntu.

Quick Answer

To enable TRIM for your SSD in Ubuntu, you can check the status of TRIM using the systemctl status fstrim.timer command. If it’s not enabled, you can manually enable it by editing the /etc/cron.weekly/fstrim file. For Ubuntu 13.10 and earlier, you can perform TRIM manually, schedule it using a script, or enable it automatically by adding the discard option to the fstab file.

What is TRIM and Why is it Important?

TRIM is a command that allows an operating system to inform a Solid State Drive (SSD) which blocks of data are no longer considered in use and can be wiped internally. Without using TRIM command, SSDs can slow down over time as the operating system has to manage both deleting and writing data in the same operation. TRIM allows the drive to clean and manage the storage space, which leads to sustained performance over time.

Checking TRIM Status

Before we proceed to enable TRIM, it’s important to check if it’s already enabled on your system. For Ubuntu 14.10 and later, TRIM is enabled by default and runs once a week. To check the status of the TRIM operation, you can use the following command:

systemctl status fstrim.timer

This command will show the status of the fstrim timer which is responsible for the weekly TRIM operation.

Enabling TRIM in Ubuntu 14.04

In Ubuntu 14.04, scheduled TRIM is enabled by default for certain SSD brands (Intel, SAMSUNG, OCZ, Patriot, and Sandisk). If you have a different brand, you can disable the vendor check by editing the /etc/cron.weekly/fstrim file. Here’s how to do it:

  1. Open the terminal and type the following command to edit the file:
sudo nano /etc/cron.weekly/fstrim
  1. In the file, find the line that reads exec fstrim-all. Add --no-model-check to the end of this line. The line should now read exec fstrim-all --no-model-check.
  2. Save the file and exit the editor.

This command will disable the vendor check and enable TRIM for your SSD, regardless of its brand.

Enabling TRIM in Ubuntu 13.10 and Earlier

For Ubuntu 13.10 and earlier, there are three ways to perform TRIM: Manual, Scheduled, and Automatic.

Manual TRIM

You can use the fstrim command to manually trim your SSD. This command tells the SSD to clean up blocks that are no longer in use. To perform a manual TRIM, use the following command:

sudo fstrim /

This command will manually TRIM the root directory. If you have other directories on your SSD, you should replace / with the path to those directories.

Scheduled TRIM

Scheduled TRIM is the recommended method as it performs the TRIM operation regularly, ensuring your SSD maintains its performance. To set up a scheduled TRIM, follow these steps:

  1. Create a new file in the /etc/cron.weekly/ directory named fstrim:
sudo nano /etc/cron.weekly/fstrim
  1. Paste the following code into the file:
#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG

This script will run the fstrim -v / command every week and write the output to a log file. The -v option tells fstrim to output the amount of discarded bytes.

  1. Make the script executable:
sudo chmod +x /etc/cron.weekly/fstrim
  1. Test the script:
sudo /etc/cron.weekly/fstrim

Automatic TRIM

Automatic TRIM is not recommended as it can slow down deletion operations on some drives. However, if you still want to enable it, you can do so by adding the discard option to the fstab entry for your SSD. Here’s how to do it:

  1. Open the /etc/fstab file:
sudo nano /etc/fstab
  1. Find the line for your SSD. It will look something like this:
UUID=00000000-0000-0000-0000-000000000000 / ext4 errors=remount-ro 0 1
  1. Add discard to the options:
UUID=00000000-0000-0000-0000-000000000000 / ext4 discard,errors=remount-ro 0 1
  1. Save the file and reboot your system.

Now, TRIM should be enabled and working on your SSD. Remember, TRIM is essential for maintaining the performance of your SSD. It’s recommended to enable it and schedule it to run regularly.

What is the purpose of TRIM for SSDs?

TRIM is a command that allows the operating system to inform the SSD which blocks of data are no longer in use, allowing the drive to clean and manage the storage space. This helps maintain the performance and longevity of the SSD.

How can I check if TRIM is enabled on my Ubuntu system?

You can check the status of the TRIM operation by running the command systemctl status fstrim.timer in the terminal. This will display the status of the fstrim timer responsible for the weekly TRIM operation.

Is TRIM enabled by default in Ubuntu 14.10 and later?

Yes, TRIM is enabled by default in Ubuntu 14.10 and later versions. It runs once a week to perform the TRIM operation.

How can I enable TRIM in Ubuntu 14.04 for SSDs of different brands?

In Ubuntu 14.04, scheduled TRIM is enabled by default for certain SSD brands. If you have a different brand, you can disable the vendor check by editing the /etc/cron.weekly/fstrim file and adding --no-model-check to the line that reads exec fstrim-all.

What are the different ways to perform TRIM in Ubuntu 13.10 and earlier?

In Ubuntu 13.10 and earlier, you can perform TRIM manually, scheduled, or automatically. Manual TRIM can be done using the sudo fstrim / command, scheduled TRIM can be set up by creating a script in the /etc/cron.weekly/ directory, and automatic TRIM can be enabled by adding the discard option to the fstab entry for your SSD.

Is automatic TRIM recommended?

Automatic TRIM is not recommended as it can slow down deletion operations on some drives. It’s better to use scheduled TRIM to ensure regular maintenance of your SSD’s performance.

Leave a Comment

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