Trimming a usb-attached ssd

I am just seeking confirmation that the fstrim.service is automatically trimminng an ssd I have attched via usb? Could someone please direct me to logs to check, or any documentation on how the service is configured, eg frequency?

systemctl status fstrim.service
systemctl status fstrim.timer

it runs once a week.

1 Like

Thank you for that. It does show what I expected, that the trim has not been working. When I use systemctl status fstrim.service I get the following response:


â—‹ fstrim.service - Discard unused blocks on all filesystems
     Loaded: loaded (/usr/lib/systemd/system/fstrim.service; static)
     Active: inactive (dead) since Mon 2025-07-14 09:15:30 NZST; 3h 34min ago
TriggeredBy: â—Ź fstrim.timer
    Process: 4190 ExecStartPre=/usr/bin/sleep 20 (code=exited, status=0/SUCCESS)
    Process: 4254 ExecStart=/usr/sbin/fstrim --all --verbose --quiet-unsupported (code=exited, status=64)
    Process: 4572 ExecStart=/usr/bin/touch /storage/.cache/fstrim.run (code=exited, status=0/SUCCESS)
   Main PID: 4572 (code=exited, status=0/SUCCESS)

Jul 14 09:14:11 X88 systemd[1]: Starting fstrim.service...
Jul 14 09:14:31 X88 fstrim[4254]: fstrim: /var/media/SharedStuff: FITRIM ioctl failed: Remote I/O error
Jul 14 09:15:30 X88 fstrim[4254]: /storage: 98.9 GiB (106181840896 bytes) trimmed on /dev/CE_STORAGE
Jul 14 09:15:30 X88 systemd[1]: fstrim.service: Deactivated successfully.
Jul 14 09:15:30 X88 systemd[1]: Finished fstrim.service.

The disk is being accessed regularly for other purposes and there are no i/o error. Also, e2fsck -f -y -v /dev/sda1 resonds with this:

e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

       52711 inodes used (0.09%, out of 61048832)
       38042 non-contiguous files (72.2%)
          10 non-contiguous directories (0.0%)
             # of inodes with ind/dind/tind blocks: 0/0/0
             Extent depth histogram: 48779/3924
   873796425 blocks used (89.46%, out of 976754126)
           0 bad blocks
          93 large files

       49091 regular files
        3611 directories
           0 character device files
           0 block device files
           0 fifos
           0 links
           0 symbolic links (0 fast symbolic links)
           0 sockets
------------
       52702 files

Any thoughts on what might be the problem?

As you can see trim service IS working. Just not on your USB device mounted under /var/media/SharedStuff. Because you didn’t provide any info about this device or enclosure, you need to figure out yourself the issue.

The SSD is a Netac 4TB purchased from AliExpress

The enclosure is a USB-A 3.0 enclosure also from AliExpress

I’ll jjust mention again that there has been no other issue accessing this SSD in this enclosure and that e2fsck shows clean file system.

Furthermore this device in this enclosure has been trimmed succsfullty when attached to a Raspberry Pi4B.

So does anyone have idea what might be wrong, or whatever logs I can look for or diagnostics I can run?

I don’t see which chipset is used in enclosure. Maybe not supporting trim.

but trims ok on raspberry pi4B

What is the result of commands

mount | paste
lsblk -D | paste
fstrim -v /var/media/SharedStuff | paste

I tried the commands as you requested with mixed results, spcifically the lsblk responds with command not found

So did this instead, hoping it is useful:

X88:~ # mount
devtmpfs on /dev type devtmpfs (rw,relatime,size=1898920k,nr_inodes=474730,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,size=761968k,nr_inodes=819200,mode=755)
/dev/CE_FLASH on /flash type vfat (ro,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
/flash/SYSTEM on / type squashfs (ro,relatime)
/dev/CE_STORAGE on /storage type ext4 (rw,noatime,resgid=1065,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755)
cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/debug type cgroup (rw,nosuid,nodev,noexec,relatime,debug)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /var type tmpfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,nr_inodes=1048576)
sunrpc on /run/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
/dev/sda1 on /var/media/SharedStuff type ext4 (rw,relatime,discard,data=ordered)

X88:~ # blkid
/dev/sda1: LABEL="SharedStuff" UUID="8c16535e-7430-4920-991d-f0a2b08e53a0" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="4c2622e5-afb5-42c2-b911-351c88ba78fa"
/dev/vendor: LABEL="vendor" UUID="c06b64d3-6b3a-523d-aa95-45b2a8bc8f1c" BLOCK_SIZE="4096" TYPE="ext4"
/dev/param: UUID="c40629da-04db-4f7b-aaa0-6a8fe98b178f" BLOCK_SIZE="4096" TYPE="ext4"
/dev/CE_FLASH: LABEL_FATBOOT="CE_FLASH" LABEL="CE_FLASH" UUID="D9E3-D1F7" BLOCK_SIZE="512" TYPE="vfat"
/dev/tee: UUID="8e7a8e0f-10d3-4bba-b529-01af6d8f133d" BLOCK_SIZE="4096" TYPE="ext4"
/dev/system: LABEL="/" UUID="9e1a6815-8b50-55e2-89b4-2108799a7de9" BLOCK_SIZE="4096" TYPE="ext4"
/dev/product: LABEL="product" UUID="bb388c0a-fef8-56cd-8b91-4afcb7d532e0" BLOCK_SIZE="4096" TYPE="ext4"
/dev/metadata: UUID="d13d6996-72a2-41d1-aaa4-5917a11a047e" BLOCK_SIZE="4096" TYPE="ext4"
/dev/odm: LABEL="odm" UUID="e5ce4c19-5095-4a8b-9f5f-d6fd2fcd14f4" BLOCK_SIZE="4096" TYPE="ext4"
/dev/cache: UUID="4d8ec171-2e74-46d9-9883-c1ba522af834" BLOCK_SIZE="4096" TYPE="ext4"
/dev/CE_STORAGE: UUID="416ba13f-3038-4842-882a-f7b7b6a8952a" BLOCK_SIZE="4096" TYPE="ext4"
/dev/data: UUID="416ba13f-3038-4842-882a-f7b7b6a8952a" BLOCK_SIZE="4096" TYPE="ext4"
/dev/loop0: BLOCK_SIZE="524288" TYPE="squashfs"

X88:~ # fstrim -v /var/media/SharedStuff
fstrim: /var/media/SharedStuff: the discard operation is not supported

Thanks for your continued help withj\ this.

Make file /storage/.config/udev.rules.d/50-usb-ssd-trim.rules with content

ACTION=="add|change", ATTRS{idVendor}=="152d", ATTRS{idProduct}=="0583", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"

To get vid and pid use command lsusb.

More info here: https://askubuntu.com/questions/1073894/fstrim-fails-with-thediscard-operation-is-not-supported

Success!

X88:~ # fstrim -v /var/media/SharedStuff
/var/media/SharedStuff: 545.5 GiB (585709793280 bytes) trimmed

Thanks very much for your help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.