Enable fstrim / TRIM / discard support especially for USB SATA disks in Linux

If fstrim tells you "discard operation is not supported" on a usb disk then you may want to try this tip. I'm assuming you're using /dev/sdb below, please adjust.

Check if this commands
sg_readcap -l /dev/sdb | grep unmap
shows "Unmap command supported (LBPU): 1". It must be  a 1 at some point or you're out of luck.

If that works. Try unmounting the drive. Then try this command as root:
umount /media/disk
echo unmap > /sys/block/sdb/device/scsi_disk/*/provisioning_mode

Now try again to see if it works:
mount /dev/sdb2 /media/disk
fstrim -v /media/diskidea

If that works for you, find out the device ID for the usb device with:
lsusb

and then post the IDs into a udev rule (exampe ID is the StarTech USB 3.0 to 2,5" SATA cable, which I've bought for my Raspberry Pi 4):
echo 'ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"' > /etc/udev/rules.d/99-trim-ssd-discard.rules

Hope this works for you! Thanks to the original idea!