Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have installed one SSD disk (Micron C400-MTFDDAC128MAM) in an external usb 3.0 enclosure. Now I want use this disk as second disk in my laptop with Ubuntu 12.04. Disk is working, but I want to use TRIM suppport which is not working as expected.

Check for trim support:

user@server:~$ sudo hdparm -I /dev/sdc | grep -i TRIM
       *    Data Set Management TRIM supported (limit 8 blocks)
       *    Deterministic read data after TRIM

Disk was mounted with following options:

/dev/sdc1 on /media/MICRON type ext4 (rw,nosuid,nodev,uhelper=udisks)

But when I run the trim command manually I get an error:

user@server:~$ sudo fstrim -v /media/MICRON/
fstrim: /media/MICRON/: FITRIM ioctl failed: Operation not permitted

I used this disk before as an internal disk and trim was working, please assist me thank you.

here some USB details:

[ 1039.248050] usb 4-1: new SuperSpeed USB device number 4 using xhci_hcd
[ 1039.265597] scsi8 : usb-storage 4-1:1.0
[ 1041.547879] scsi 8:0:0:0: Direct-Access     C400-MTF DDAC128MAM       0509 PQ: 0 ANSI: 5
[ 1041.549134] sd 8:0:0:0: Attached scsi generic sg2 type 0
[ 1041.550511] sd 8:0:0:0: [sdc] 250069680 512-byte logical blocks: (128 GB/119 GiB)
[ 1041.550778] sd 8:0:0:0: [sdc] Write Protect is off
[ 1041.550785] sd 8:0:0:0: [sdc] Mode Sense: 23 00 00 00
[ 1041.552520] sd 8:0:0:0: [sdc] No Caching mode page present
[ 1041.552528] sd 8:0:0:0: [sdc] Assuming drive cache: write through
[ 1041.554029] sd 8:0:0:0: [sdc] No Caching mode page present
[ 1041.554035] sd 8:0:0:0: [sdc] Assuming drive cache: write through
[ 1041.678373]  sdc: sdc1
[ 1041.679982] sd 8:0:0:0: [sdc] No Caching mode page present
[ 1041.679991] sd 8:0:0:0: [sdc] Assuming drive cache: write through
[ 1041.679997] sd 8:0:0:0: [sdc] Attached SCSI disk

How to find out if the mass storage device using the UASP (USB Attached SCSI Protocol) which should support TRIM?

Kind regards


share|improve this question
up vote 1 down vote accepted

Your SSD reports to hdparm to support TRIM (hdparm -I = Request identification info directly from the drive).

TRIM however, is controlled by the drive controller.

It is quite likely that the USB3 harddiskcontroller of the external HDD closure doesn't support TRIM (most external controllers don't).

In that case you won't get any TRIM capabilities even if your SSD does support it.

share|improve this answer
USB3 has brought a new protocol: UASP (USB Attached SCSI Protocol) for communication with external mass storage devices over USB. The old protocol BOT (Bulk Only Transport) does not support TRIM. UASP supporting TRIM and NCQ.Question is how can I find out that the OS is using UASP with the external drive? – Luckyrings Mar 8 '13 at 23:37
@Luckyrings Please ask a new question and Link to this question if it helps provide conetxt. – Uri Herrera Mar 8 '13 at 23:48

This is a software issue, Linux does not seem to currently support TRIM through USB. The problem is that USB storage devices employ the SCSI command set, whereas the SSD drive implements the ATA command set. The USB enclosure has to provide a translator between these command sets. The operation called TRIM in ATA is called UNMAP in SCSI and DISCARD in the Linux kernel. When Linux receives the command to trim a device, it looks up the correct command to be sent to the device. As USB storage devices look like SCSI disks, Linux tries to use UNMAP or a couple of other possible SCSI commands. In principle, the translator in the USB enclosure could often translate UNMAP requests to the corresponding ATA TRIM, although there are probably tricky cases. In practice, the enclosures don't do this, and they indicate instead that the device does not support UNMAP. However, many enclosures implement a SCSI command to issue ATA commands directly to the device. It is called ATA passthrough. There is a standard command to do this, but some enclosures have a proprietary command instead. In fact, hdparm -I uses ATA passthrough to get information from the device. The same passthrough could be used to issue TRIMs directly to the device, but the Linux driver does not currently do that. It would have to detect that a SCSI disk is actually a SCSI-to-ATA translator that supports ATA passthrough and use the passthrough for DISCARDs instead of the native SCSI commands.

share|improve this answer

If UNMAP is not translated correctly by your enclosure you can at least manually trim the whole drive using hdparm (this uses the ata-passthrough of the SCSI protocol and works fine on my UASP hdd dock). But you have to calculate the sectors manually because hdparm only supports trimming 65535 sectors at a time. I have written a short script to do the math:

#!/usr/bin/env python3

import sys

remaining = int(sys.argv[1])
i = 0

while remaining > 0:
    add = min(65535, remaining)
    print("%d:%d" % (i, add))
    remaining -= add
    i += add

Save it as and do chmod +x It yields a list of sector-blocks usable with hdparm --trim-sector-ranges-stdin. Now execute hdparm -I /dev/sdX (as root) and hold out for a line that looks like:

LBA48  user addressable sectors:   62533296

This is the devices sector count (as you could calculate this is a ~32 GB SSD I frequently use for testing).

Copy the number to the following command:

./ SECTOR_COUNT | sudo hdparm --trim-sector-ranges-stdin --please-destroy-my-drive /dev/sdX

WARNING: This will erase the WHOLE DRIVE!

After it finished, run sync and wait some seconds. Now you can re-read the partition table with hdparm -z /dev/sdX or simply power-cycle the device. Congratulations, you have a "fresh" SSD now.

share|improve this answer
There is a better way of doing this. It's implemented as part of drive's security feature, called "Secure Erase". hdparm is used with --security-erase option after setting a password with --security-set-pass. After erase, the whole drive is essentially trimmed and zeroed. It's all done in the drive's flash controller. I've written a detailed blog post detailing the steps. – Mansour Dec 21 '15 at 7:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.