How to enable TRIM on an XFS partition managed by LVM on an external USB SSD

I have an external USB SSD. I have configured:

cat /etc/udev/rules.d/10-trim.rules
ACTION==“add|change”, ATTRS{idVendor}==“04e8”, ATTRS{idProduct}==“61f5”, SUBSYSTEM==‘scsi_disk’, ATTR{provisioning_mode}=“unmap”
lsblk -D /dev/sdb
NAME         DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sdb                 0      512B       4G         0
└─lisa-study        0        0B       0B         0
dmsetup table --showkeys lisa-study
0 3906961408 linear 8:16 65535
fstrim -v /mnt/study
fstrim: /mnt/study: the discard operation is not supported

my fedora kernel version and lvm version

uname -a
Linux home 6.17.4-300.fc43.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Oct 19 17:36:51 UTC 2025 x86_64 GNU/Linux


lvm version
  LVM version:     2.03.34(2) (2025-07-30)
  Library version: 1.02.208 (2025-07-30)
  Driver version:  4.50.0
  Configuration:   ./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/bin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --runstatedir=/run --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-default-dm-run-dir=/run --with-default-run-dir=/run/lvm --with-default-pid-dir=/run --with-default-locking-dir=/run/lock/lvm --with-usrlibdir=/usr/lib64 --enable-fsadm --enable-write_install --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-cmdlib --enable-dmeventd --enable-blkid_wiping --with-udevdir=/usr/lib/udev/rules.d --enable-udev_sync --with-thin=internal --with-cache=internal --enable-lvmpolld --enable-lvmlockd-dlm --enable-lvmlockd-dlmcontrol --enable-lvmlockd-sanlock --enable-dbus-service --enable-notify-dbus --enable-dmfilemapd --with-writecache=internal --with-vdo=internal --with-vdo-format=/usr/bin/vdoformat --with-integrity=internal --with-default-use-devices-file=1 --disable-silent-rules --enable-app-machineid --enable-editline --disable-readline

Currently, my SSD device supports TRIM, but the partition within the SSD does not. I manage this drive using LVM, without encryption or RAID.
However, for some reason, I cannot use fstrim at this partition’s mount point. I’m not sure what to do.

TRIM is part of the interface the a disk drive and the disk drive firmware does not know about file systems or partitions.

Try running TRIM against the drive not a partition.

Can I use fstrim to trim the entire disk? I have an LVM volume group, and this disk is a physical volume within that LVM group. This LVM group has only one logical volume, but this logical volume cannot execute trim.

Yes you can, but I’m not sure you know what TRIM does.
You might find this helpful to undertstand what TRIM does: Trim (computing) - Wikipedia

$ apropos fstrim 
fstrim (8)           - discard unused blocks on a mounted filesystem

While trimming must be supported by the block device the information which blocks are subject of trimming is gathered by examining the affected filesystems.

For filesystems hosted on USB devices trimming is often not supported resp. must be enabled first. See also

1 Like

I have enabled TRIM support for my device through these steps, but under LVM, I am unable to perform TRIM operations on the partitions of this hard drive.

You have checked the USB device for unmap support using the sg_readcap and sg_vpd commands described in the ArchWiki article? According to the device ID the drive is a Samsung TP5 drive. For all my Samsung T7 devices the lsblk -D output looks similar. Based on the sg_readcap and sg_vpd output their unmap support is at least unsufficient for current kernel.

Yes, I checked them. from the doc Solid state drive - ArchWiki
I can not found content about

Unmap command supported (LBPU): 1
Write same (16) with unmap bit supported (LBPWS): 0
Write same (10) with unmap bit supported (LBPWS10): 0

but i found output from sudo sg_vpd -a /dev/sdb,LBPU=1 This also seems to indicate that my device supports TRIM.

Logical block provisioning VPD page (SBC)
  LBPU=1
  LBPWS=0
  LBPWS10=0
  LBPRZ=0x0
  ANC_SUP=0
  DP=0
  Minimum percentage: 0 [not reported]
  Provisioning type: not known or fully provisioned
  Threshold percentage: 0 [percentages not supported]
sudo sg_readcap -l /dev/sdb
[sudo] password for paomian:
Read Capacity results:
   Protection: prot_en=0, p_type=0, p_i_exponent=0
   Logical block provisioning: lbpme=0, lbprz=0
   Last LBA=3907029167 (0xe8e088af), Number of logical blocks=3907029168
   Logical block length=512 bytes
   Logical blocks per physical block exponent=0
   Lowest aligned LBA=0
Hence:
   Device size: 2000398934016 bytes, 1907729.1 MiB, 2000.40 GB, 2.00 TB