SSD flash hard drives have started to support TRIM in order to avoid the slowdown that occurs after a while.

How do I do something similar on a SD card ?

Like reformating the SD card, but at a lower-level to avoid the automatic wear-leveling.

6 Answers 6


I don't know if this is a bogus, but it seems that in Linux fstrim works. I am bit surprised.

fstrim -v /media/32G_SD/
/media/32G_SD/: 7,2 GiB (7705051136 bytes) trimmed

It's 32GiB card formatted with btrfs and I indeed removed around 8GiB. The label is Kingston model: sd10vg2 (grey SD card)

I have to add that you should be careful with fstrim in SSD. And more careful on sdcards. Too much bugs on firmwares. I trust only Intel enterprise series. I had one meltdown with fstrim and SD-card (inaccessible data). I will not fstrim too often on this sdcard and general on sd's.

  • 8
    This is most probably doing MMC_CAP_ERASE for unused dirty blocks. Works slower than TRIM (which lets the controller schedule the actual erase), but the end result should be the same. Commented Sep 11, 2017 at 14:36
  • Does it need to be unmounted or something? I only got an error: fstrim: <my_mountpoint> : the discard operation is not supported. I've got an SDxC by Kingston. Commented Apr 19, 2018 at 21:48
  • Mounted. The filesystem has to inform the fstrim command about the available free space. In your case, I suppose your SD card does not support TRIM.
    – krg
    Commented May 28, 2018 at 8:12
  • 5
    @DmitryGrigoryev right, fstrim sent to SD Cards may not always be "trim" it's essentially ERASE (CMD38) Commented Jul 2, 2019 at 10:56
  • Is there a Windows tool with the same functionality? Or an fstrim port for Windows that supports the MMC_CAP_ERASE commands?
    – user643011
    Commented Feb 24, 2023 at 1:16

On Linux:

  • blkdiscard on the unmounted block device (e.g. /dev/mmcblk0) to discard all blocks (renders data inaccessible through normal means, but does not promise to securely erase them).
  • fstrim (on the mounted file system) if you want to keep the data but discard the blocks that are unused.

My understanding is that the current SDCARD spec does not include a TRIM command. Although I am not on the committee, Windows 7's support for TRIM will bring it to the attention of many engineers, and it's reasonable to expect that the command will show up in the SD spec within the next few years.

The OS uses the TRIM command to tell the flash device that a sector will not be read again until it is written. This tells the flash device that the sectors do not need to be copied from one page to another before the first page is erased. This can result in significantly improved performance and improved data privacy.

It would be nice if SD cards could give performance similar to SSDs. I don't see any fundamental reason why the small form factor could not support high-speed access. At the moment, though, if you want high-speed performance, you should use an SSD, not a SD card.


The MMC_ERASE low level command allows for TRIM-like functionality on SD cards (and eMMC chips).

Not all SD Cards and eMMC chips support the MMC_ERASE command (and/or newer extensions to it), but most modern (genuine) brand-name and OEM SD cards now support it (e.g. Sasmung EVO brand cards).

USB to SD card adapters ("SD card readers") could support this command by advertising the TRIM or UNMAP commands via the USB storage interface, and translating these to the MMC_ERASE command, but I've yet to find a USB adapter which does this.

This means that to use MMC_ERASE a "direct" mmc interface is likely to be needed, such as the types which are supported by the Linux mmcblk device driver, and implemented by hardware in some laptops and other devices such as the Raspberry Pi.

The example below shows the use of MMC_ERASE on a 2008 1GB SD Card:

~# echo 'some data' > /dev/mmcblk0 
~# dd if=/dev/mmcblk0 count=1 | hd
00000000  73 6f 6d 65 20 64 61 74  61 0a 00 00 00 00 00 00  |some data.......|
1+0 records in
1+0 records out
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
512 bytes copied, 0.0138109 s, 37.1 kB/s
~# lsblk -D /dev/mmcblk0 
mmcblk0        0        4M     2.7G         0
~# blkdiscard -v /dev/mmcblk0
/dev/mmcblk0: Discarded 1019215872 bytes from the offset 0
~# dd if=/dev/mmcblk0 count=1 | hd
1+0 records in
1+0 records out
512 bytes copied, 0.0114608 s, 44.7 kB/s
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

Storage tools claims defragging you SD card increases performance, however they sell the product so they can claim whatever suits them.

Though there are other programs that claim it helps:

Fragmentation refers to the tendency of files, stored in the FAT file system, to become broken into pieces that can end up in very different places within a storage card volume. Fragmentation occurs naturally with time when a storage card is used frequently - creating, deleting, and modifying files. This process is entirely invisible to users.

But PPC Magazine thinks it's a good idea as well. Though not with software:

Werner Ruotsalainen at the PPC Magazine blog shares some good information on whether or not Pocket PC memory cards need to be defragmented, and how to do it.

Some tips:

  • Yes, it's worth defragmenting them every 2-3 months, if there are frequent writes to the card.
  • Never use a Pocket PC utility to do the defragmenting
  • Do consider getting a card reader

If you have a card reader, the process is simple: Copy the files to your hard drive, reformat the card (E.g. "format i: /q /u" but make sure you use the correct drive letter!), and then copy your files back to the card.

But here's some Storage Tools info anyway ;-)

alt text alt text

Storage Tools Description

The most comprehensive storage card management solution, StorageTools is the first product to offer defragmentation functionality for Pocket PC devices, providing dramatic speed improvements by resolving file fragmentations.

With StorageTools you can get detailed device and file system information about your storage cards, analysis of file allocations (slack space) and fragmentation level.

StorageTools works with all media types available on PocketPC/Windows CE devices, including industry standards: ATA compliant memory cards, Compact Flash cards, MicroDrives, Secure Digital (SD) cards, MultiMedia Cards (MMC) and PCMCIA memory cards. You can format storage media with different file system and cluster size.

Scan tool diagnoses and repairs a variety of media problems. It performs several tests, checking everything from the boot sector to its physical surface. If StorageTools finds a problem, it notifies you before making repairs. Optionally allows making all necessary repairs automatically.

With StorageTools defragmenter you achieve maximum performance under Pocket PC/Windows CE with minimum effort! It includes the most professional and user-friendly features ever found in defragmentation software. You must eliminate fragmentation to eliminate the most basic performance bottleneck on your PocketPC device as you can on your powerful desktop computer.

The StorageTools includes full support for all storage/media cards even transparently encrypted volumes by Sentry 2020 for PocketPC, and includes options to choose FAT type and cluster size when formatting, plus the ability to create a backup FAT to improve storage reliability.


  • Display detailed file system statistics
  • Format storage cards with any file system type and any cluster size
  • Verify file system integrity
  • Repair file system errors
  • Supports all Windows CE storage media: MMC/SD, compact flash, etc.
  • Concurrently works with multiple storage cards
  • Automatic card insertion and removal detection
  • Install and Uninstall options
  • Supports FAT and FAT32 file systems
  • Analyze file system fragmentation level
  • Defragment files and free space


  • Format recovers storage card space by using smaller cluster size
  • Defragment dramatically improves storage card performance
  • 11
    What does this have to do with TRIM? Defragging doesn't do anything on an SD card. Even if it did, the OS has no control over where the data on an SD card physically resides, so it wouldn't really be possible. I suppose garbage collection is similar to defragging in some ways, but it's purely up to the SD card's controller. You can't control it. TRIM is a command that notifies the controller when data has been erased. Its purpose is to help garbage collection happen more efficiently. The only say an OS has into what an SD card physically does with data is the TRIM command. Commented Oct 10, 2015 at 22:47
  • It's true that some SD cards contain such a poor controller that defragmenting the SD card really improves future reading performance. This is caused by cheap controllers that cannot queue any commands and after OS as emitted one read command the OS must wait for the full read to complete before another can be send. Whitness the difference for stream reading and random 4K read performance for bad SD cards (there can be easily 100x performance difference). Commented Nov 10, 2016 at 16:43

First backup all your data on the SD card. Then you can use the SD Formatter tool and in options select FULL (Erase): https://www.sdcard.org/downloads/formatter_4/

  • 2
    SDCard Formatter: Quick format deletes all the file/directory entries by initializing file system parameters of the card, but it does not delete the data written in files. Overwrite format deletes file/directory entries by initializing file system parameters of the card (same as with Quick format), and erases all data by overwriting the user data area completely. So what it does at maximum is to overwrite the data, no TRIM/discard/ERASE (CMD38) happens. Commented Jul 2, 2019 at 11:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .