I wonder, if it is possible to 'reset' the controller of an USB drive or a memory card to treat as 'unused' on Linux (Fedora 24)?

Background: I have overwritten an USB drive from /dev/urandom. I.e., I assume that all blocks have been written to, since (as far as I understood) most USB drive and memory card controllers do not keep any spare blocks. The drive (how to check, if the storage controller supports ATA trim or if the USB controller passes the ATA trim through to the device?)does not support trim - fstrim throws an error and hdparm does not see trim support, i.e.,

hdparm -I /dev/sdX | grep -i TRIM

Is it generically possible to mark all blocks on thus an USB flash storage as earasable and run a garbage collection on all cells? Or is it, if possible, only limited to certain controllers (USB as well as storage controller)?


Following After an SD card is erased, what value is read from the card? All bits clear or all bits set? at least SD-cards should support a CMD38, which as a quick format would reset the blocks.

However I have found so far only an official Win/Mac software for sending this command to a device https://www.sdcard.org/downloads/formatter_4/

Presumably (not tried) this also depends on the USB controller to pass-through the command and may only work on SD cards but not necessarily with USB drives?

So far, I have not found a Linux program for easily sending this CMD38 command to a device.

  • “Is it generically possible” – no. In fact, one might even go so far as to say it’s generically impossible. I very much doubt that any USB/SD flash controller would be able to do this. They are much less sophisticated than SSD controllers. Unfortunately, I cannot research now. – Daniel B Aug 30 '16 at 14:32
  • yes, I have tried the SD association's formatter under Windows, However, I have not managed to get it access the low-level functions of several SD cards through various USB-readers. Apparently, the USB-controllers in most readers do not pass through the commands/are addressing cards to the PC as other storage types than mmcblk – THX Aug 31 '16 at 13:35

The command you want is blkdiscard. It completely erases an entire partition or block device by means of trimming it. However, it will only work on SD cards, not USB thumb drives, as I don't think the latter support trim.

  • ah, thanks - that is in principle what I am looking for. Unfortunately, all my card readers (internal as external) are identifying themselves as mass storages of one or the other kind (i.e., thumb drives). I guess with a directly attached card reader, blkdiscard should be my tool for SDs! – THX Jan 31 '17 at 8:52
  • If the underlying device does support trim, then try using the shell script wiper.sh, that comes with hdparm. For some reason that script (which is scarier because it uses hdparm on lists of blocks) can actually work across USB. – user3188445 May 6 at 22:07

You need fstrim, in the util-linux package:


fstrim - discard unused blocks on a mounted filesystem


  fstrim [-a] [-o offset] [-l length] [-m minimum-size] [-v] mountpoint


fstrim is used on a mounted filesystem to discard (or "trim") blocks which are not in use by the filesystem. This is useful for solid-state drives (SSDs) and thinly-provisioned storage.

By default, fstrim will discard all unused blocks in the filesystem. Options may be used to modify this behavior based on range or size, as explained below.

The mountpoint argument is the pathname of the directory where the filesystem is mounted.

Running fstrim frequently, or even using mount -o discard, might negatively affect the lifetime of poor-quality SSD devices. For most desktop and server systems a sufficient trimming frequency is once a week. Note that not all devices support a queued trim, so each trim command incurs a performance penalty on whatever else might be trying to use the disk at the time.

This does depend on the ability of the drive or card slot to accept the TRIM command, of course. Cheap USB mass-storage tend not to; newer UAS (USB-attatched SCSI) can usually accept TRIM. You can tell whether it's supported using hdparm -i - look for "Data Set Management TRIM supported" under the "Commands/features" heading.

  • Hi, as mentioned fstrim throws an error (I have added the OS/Fedroa 24) since the device does not support trim, i.e., hdparm -I /dev/sdX | grep -i TRIM. I would assume, that trim support is controller depenend, i.e., if the storage controller supports ATA trim, the USB controller would have to pass it through as well. – THX Aug 30 '16 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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