[HowTo] TRIM an external SSD

Difficulty: ★☆☆☆☆

Do you get the following message when you try to TRIM your external SSD?

the discard operation is not supported

We can easily overcome this by creating a udev rule in /etc/udev/rules.d

How to do it

  • Identify the VendorID and ProductID of your device.

    Type:

    lsusb
    

    in your terminal and locate your external SSD. In my case:

    Bus 002 Device 005: ID 04e8:61f5 Samsung Electronics Co., Ltd Portable SSD T5
    

    You’ll see an ID value, mine is 04e8:61f5 The VendorID is the first part and the second part is the ProductID.

  • Create a udev rule

    sudo nano /etc/udev/rules.d/10-uas-discard.rules
    

    And enter this rule:

    ACTION=="add|change", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="61f5", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"`
    

    Ensure to use your VendorID and ProductID! Save and exit the editor.

    The next time you plug in your device you can Trim it manually using the fstrim command:

    sudo fstrim -v /path/to/SSD/mountpoint
    

Once a week/month should suffice, depending on your usage.

6 Likes