You are not logged in.

#1 2026-01-17 15:33:13

Ashark
Member
Registered: 2017-06-01
Posts: 35

Enabling TRIM for LVM logical volumes on UGreen sata-usb adapter

Hello.

I am having a problem with enabling TRIM on usb-sata adapter.

I have bought UGreen SATA-USB 3.0 adapter, model "CM308". The marketing screenshot has a picture of a chip with label "ASM1153E".
The marketing materials and manual says that it supports TRIM.

The Arch Linux is installed on that ssd, and I am booting into it (via that UGreen adapter).

I am following Arch Wiki page https://wiki.archlinux.org/title/Solid_state_drive

It says:

To verify TRIM support, run:
$ lsblk --discard
And check the values of DISC-GRAN (discard granularity) and DISC-MAX (discard max bytes) columns. Non-zero values indicate TRIM support.

I checked the original value (before doing anything):

# lsblk -D
NAME               DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                       0        4K       2G         0
sdb                       0        0B       0B         0  # <- the ugreen sata-usb attached ssd, before doing anything
├─sdb1                    0        0B       0B         0
└─sdb2                    0        0B       0B         0
  ├─myVolGr03-root        0        0B       0B         0
  ├─myVolGr03-var         0        0B       0B         0
  └─myVolGr03-home        0        0B       0B         0
nvme0n1                   0      512B       2T         0
├─nvme0n1p1               0      512B       2T         0
└─nvme0n1p2               0      512B       2T         0

Now, as can be seen, trim is not enabled there automatically.

A side question is - Why this is not done automatically? I see Arch Wiki text:

Several USB-to-SATA bridge chips (like VL715, VL716 etc.) and also USB-to-PCIe bridge chips (like the JMicron JMS583 used in external NVMe enclosures like IB-1817M-C31) support TRIM-like commands that can be sent through the USB Attached SCSI driver (named "uas" under Linux).
But the kernel may not automatically detect this capability, and therefore might not use it.

It does not explain why the kernel "may not detect this capability".

Ok, now I am following the External SSD with TRIM support section to enable trim:

I am running the command

# echo "unmap" >/sys/block/sdb/device/scsi_disk/*/provisioning_mode

and then rechecking the trim support status:

❯ lsblk --discard
NAME               DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                       0        4K       2G         0
sdb                       0      512B       4G         0  # <- the ugreen sata-usb attached ssd, after setting "unmap" provisioning, trim is now supported
├─sdb1                    0      512B       4G         0
└─sdb2                    0      512B       4G         0  # <- the partition device now also supports trim
  ├─myVolGr03-root        0        0B       0B         0  # <- but the LVM logical volumes (all of them) do not for some reason
  ├─myVolGr03-var         0        0B       0B         0
  └─myVolGr03-home        0        0B       0B         0
nvme0n1                   0      512B       2T         0
├─nvme0n1p1               0      512B       2T         0
└─nvme0n1p2               0      512B       2T         0

As can be seen, the TRIM support appeared for the /dev/sdb, also for /dev/sdb1, /deb/sdb2.
But not for the logical volumes on that partition.

And when I am trying to run trim manually, I get the error:

❯ sudo fstrim -v /boot  # /boot is my /dev/sdb1
/boot: 712 MiB (746627072 bytes) trimmed

❯ sudo fstrim -v /home  # /home is my /dev/mapper/myVolGr03-home
fstrim: /home: the discard operation is not supported

I read the LVM section, and it says:

TRIM requests that get passed from the file system to the logical volume are automatically passed to the physical volume(s). No additional configuration is necessary.

So, issue_discards in /etc/lvm/lvm.conf is not needed and unrelated.

But what I am doing wrong? Why the TRIM is not enabling for LVM logical volumes? And how to fix it?

Offline

#2 2026-01-17 20:39:06

topcat01
Member
Registered: 2019-09-17
Posts: 273

Re: Enabling TRIM for LVM logical volumes on UGreen sata-usb adapter

Maybe you need to enable trim in a udev rule, so that it happens before LVM. You can use lvchange and vgchange to deactivate and reactivate on the fly to test after enabling trim.

Last edited by topcat01 (2026-01-17 20:43:19)

Offline

#3 2026-01-17 20:45:03

Ashark
Member
Registered: 2017-06-01
Posts: 35

Re: Enabling TRIM for LVM logical volumes on UGreen sata-usb adapter

topcat01 wrote:

Maybe you need to enable trim in a udev rule, so that it happens before LVM.

I had not mentioned in the first post, but I already did that. Following the Arch Wiki article, I created the udev rule file:

❯ cat /etc/udev/rules.d/10-uas-discard.rules
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="1153", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"

That works in that sense that it does enable the trim for the /dev/sdb, /dev/sdb1, /deb/sdb2 after reboot automatically. But not in the sense like it fixes the trim for logical volume.

topcat01 wrote:

You can use lvchange and vgchange to deactivate and reactivate on the fly to test after enabling trim.

My lv is on the boot device. I think it is not possible to deactivate lv that the current system has mounted.

Last edited by Ashark (2026-01-17 20:49:29)

Offline

#4 2026-01-17 20:53:14

topcat01
Member
Registered: 2019-09-17
Posts: 273

Re: Enabling TRIM for LVM logical volumes on UGreen sata-usb adapter

You probably need to do that in the initramfs, otherwise it's too late.

Offline

#5 2026-01-18 00:14:54

Ashark
Member
Registered: 2017-06-01
Posts: 35

Re: Enabling TRIM for LVM logical volumes on UGreen sata-usb adapter

topcat01 wrote:

You probably need to do that in the initramfs, otherwise it's too late.

Thanks for the idea. Unfortunately, it did not help.

I have read here how to do it. I opened /etc/mkinitcpio.conf, and added the path to FILES:

...
FILES=( "/etc/udev/rules.d/10-uas-discard.rules" )
...

Then I run "mkinitcpio -P". Then rebooted.
I also ensured that the file was added to initramfs correctly:

❯ lsinitcpio /boot/initramfs-linux.img | grep 10-uas-discard.rules
etc/udev/rules.d/10-uas-discard.rules

But still, LVM lvs have disabled trim:

❯ lsblk -D
NAME               DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
...
sdb                       0      512B       4G         0
├─sdb1                    0      512B       4G         0
└─sdb2                    0      512B       4G         0
  ├─myVolGr03-root        0        0B       0B         0  # <- still no trim
  ├─myVolGr03-var         0        0B       0B         0
  └─myVolGr03-home        0        0B       0B         0
...

Offline

Board footer

Powered by FluxBB