Card/USB flash storage: how to trim/discard/reset after heavy usage

memory-cardtrimusbusb-flash-drive

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)?

Follow-Up

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.

Best Answer

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.

Related Question