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.