fstrim requires the Linux block device to be mounted, and it is not very verbose. blkdiscard could tell, but also that would require a write operation.

Can I somehow tell if a block device supports trimming/discarding, without actually trying to trim/discard something on it?


You can check the device’s maximum discard sizes, e.g.

$ cat /sys/block/X/queue/discard_max_bytes

(replacing X as appropriate).

If this shows a value greater than 0, the device supports discards. Strictly speaking, discard_max_hw_bytes indicates what the hardware supports; discard_max_bytes indicates what the software supports, and the latter is usually what‘s relevant:

A discard_max_bytes value of 0 means that the device does not support discard functionality.

(This is in the discard_max_hw_bytes section, but it’s effectively true for both. The references will be fixed in 5.15.)

This works on many different block devices, not just disks: loop devices, device mapper devices, etc.


Utilize the hdparm command, which lets you perform low level commands on a disk device.

The option hdparm -I /dev/sda (or insert block device instead of sda), will query the drive for information. There is a section that lists the supported operations of the drive.

Running hdparm -I /dev/sda | grep TRIM on a TRIM supporting drive will output something like:

    *    Data Set Management TRIM supported (limit 1 block)

There is also a lot of other useful information in the output, the hdparm command is very useful.

Note this will only work on SATA and some SCSI devices, since hdparm is designed to run SATA commands on devices.

  • So why does fstrim only trim mounted "devices"? Sep 9 at 18:11
  • 4
    @Jeremy because fstrim trims file systems, not block devices — it asks the file system to trim itself, so the file system has to be mounted. If you want to discard blocks from a block device, without mounting it, use blkdiscard; you’ll have to figure out which blocks to discard. Sep 9 at 19:05
  • 3
    Note that hdparm only really works for ATA devices (and possibly some SCSI devices). NVMe, MMC/SD, some USB devices, device-mapper targets, ramdisks, and plenty of other device types do not return any useful information when you run hdparm -I against them. Sep 10 at 6:00

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.