Enabling TRIM on external SSD with LUKS

I am attempting to enable TRIM on my main install to extend the life of my SSD. I'm using an external drive (plugged in with USB) because I just had one lying around. The drive has TRIM support. I've looked through the Arch wiki and elsewhere, but just can't get it to work.

Output of inxi -Faz:

System:    Kernel: 5.14.8-zen1-1-zen x86_64 bits: 64 compiler: gcc v: 11.1.0
           parameters: BOOT_IMAGE=/@/boot/vmlinuz-linux-zen root=UUID=f1edd825-d641-4954-8d0d-f00f63da3389 rw rootflags=subvol=@ quiet cryptdevice=UUID=0f3bffe8-12fe-4da3-b170-086236fd31ee:luks-0f3bffe8-12fe-4da3-b170-086236fd31ee:allow-discards root=/dev/mapper/luks-0f3bffe8-12fe-4da3-b170-086236fd31ee splash nvidia-drm.modeset=1 rd.udev.log_priority=3 vt.global_cursor_default=0 systemd.unified_cgroup_hierarchy=1 loglevel=3
           Desktop: KDE Plasma 5.22.5 tk: Qt 5.15.2 info: latte-dock wm: kwin_x11 vt: 1 dm: SDDM Distro: Garuda Linux 
           base: Arch Linux
Machine:   Type: Desktop Mobo: Micro-Star model: B550-A PRO (MS-7C56) v: 2.0 serial: <filter> UEFI: American Megatrends LLC. 
           v: A.72 date: 06/22/2021 
CPU:       Info: 8-Core model: AMD Ryzen 7 3700X bits: 64 type: MT MCP arch: Zen 2 family: 17 (23) model-id: 71 (113) 
           stepping: 0 microcode: 8701021 cache: L2: 4 MiB 
           flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 115202 
           Speed: 2313 MHz min/max: 2200/3600 MHz boost: enabled Core speeds (MHz): 1: 2313 2: 2102 3: 2056 4: 2054 5: 2054 
           6: 3600 7: 2053 8: 2056 9: 2120 10: 2173 11: 2056 12: 3599 13: 2051 14: 2055 15: 3606 16: 2054 
           Vulnerabilities: Type: itlb_multihit status: Not affected 
           Type: l1tf status: Not affected 
           Type: mds status: Not affected 
           Type: meltdown status: Not affected 
           Type: spec_store_bypass mitigation: Speculative Store Bypass disabled via prctl and seccomp 
           Type: spectre_v1 mitigation: usercopy/swapgs barriers and __user pointer sanitization 
           Type: spectre_v2 mitigation: Full AMD retpoline, IBPB: conditional, STIBP: conditional, RSB filling 
           Type: srbds status: Not affected 
           Type: tsx_async_abort status: Not affected 
Graphics:  Device-1: NVIDIA GP108 [GeForce GT 1030] vendor: Micro-Star MSI driver: nvidia v: 470.74 
           alternate: nouveau,nvidia_drm bus-ID: 2b:00.0 chip-ID: 10de:1d01 class-ID: 0300 
           Device-2: Razer USA Razer Kiyo Pro type: USB driver: snd-usb-audio,uvcvideo bus-ID: 4-1:2 chip-ID: 1532:0e05 
           class-ID: 0102 
           Display: x11 server: X.Org 1.20.13 compositor: kwin_x11 driver: loaded: nvidia display-ID: :0 screens: 1 
           Screen-1: 0 s-res: 3840x2160 s-dpi: 162 s-size: 602x341mm (23.7x13.4") s-diag: 692mm (27.2") 
           Monitor-1: DP-0 res: 3840x2160 hz: 60 dpi: 163 size: 597x336mm (23.5x13.2") diag: 685mm (27") 
           OpenGL: renderer: NVIDIA GeForce GT 1030/PCIe/SSE2 v: 4.6.0 NVIDIA 470.74 direct render: Yes 
Audio:     Device-1: NVIDIA GP108 High Definition Audio vendor: Micro-Star MSI driver: snd_hda_intel v: kernel bus-ID: 2b:00.1 
           chip-ID: 10de:0fb8 class-ID: 0403 
           Device-2: Advanced Micro Devices [AMD] Starship/Matisse HD Audio vendor: Micro-Star MSI driver: snd_hda_intel 
           v: kernel bus-ID: 2d:00.4 chip-ID: 1022:1487 class-ID: 0403 
           Device-3: Razer USA Razer Kiyo Pro type: USB driver: snd-usb-audio,uvcvideo bus-ID: 4-1:2 chip-ID: 1532:0e05 
           class-ID: 0102 
           Sound Server-1: ALSA v: k5.14.8-zen1-1-zen running: yes 
           Sound Server-2: JACK v: 1.9.19 running: no 
           Sound Server-3: PulseAudio v: 15.0 running: no 
           Sound Server-4: PipeWire v: 0.3.38 running: yes 
Network:   Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet vendor: Micro-Star MSI driver: r8169 v: kernel 
           port: f000 bus-ID: 2a:00.0 chip-ID: 10ec:8168 class-ID: 0200 
           IF: enp42s0 state: up speed: 1000 Mbps duplex: full mac: <filter> 
Bluetooth: Device-1: ASUSTek ASUS USB-BT500 type: USB driver: btusb v: 0.8 bus-ID: 3-2.1:4 chip-ID: 0b05:190e class-ID: e001 
           serial: <filter> 
           Report: bt-adapter ID: hci0 rfk-id: 0 state: up address: <filter> 
Drives:    Local Storage: total: 704.24 GiB used: 71.5 GiB (10.2%) 
           SMART Message: Unable to run smartctl. Root privileges required. 
           ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Samsung model: SSD 970 EVO 500GB size: 465.76 GiB block-size: 
           physical: 512 B logical: 512 B speed: 31.6 Gb/s lanes: 4 type: SSD serial: <filter> rev: 2B2QEXE7 temp: 28.9 C 
           scheme: GPT 
           ID-2: /dev/sda maj-min: 8:0 type: USB vendor: Silicon Power model: SPCC Sol id State Dis size: 238.47 GiB 
           block-size: physical: 512 B logical: 512 B type: N/A serial: <filter> rev: T091 scheme: GPT 
Partition: ID-1: / raw-size: 238.18 GiB size: 238.18 GiB (100.00%) used: 53.06 GiB (22.3%) fs: btrfs dev: /dev/dm-0 
           maj-min: 254:0 mapped: luks-0f3bffe8-12fe-4da3-b170-086236fd31ee 
           ID-2: /home raw-size: 238.18 GiB size: 238.18 GiB (100.00%) used: 53.06 GiB (22.3%) fs: btrfs dev: /dev/dm-0 
           maj-min: 254:0 mapped: luks-0f3bffe8-12fe-4da3-b170-086236fd31ee 
           ID-3: /var/log raw-size: 238.18 GiB size: 238.18 GiB (100.00%) used: 53.06 GiB (22.3%) fs: btrfs dev: /dev/dm-0 
           maj-min: 254:0 mapped: luks-0f3bffe8-12fe-4da3-b170-086236fd31ee 
           ID-4: /var/tmp raw-size: 238.18 GiB size: 238.18 GiB (100.00%) used: 53.06 GiB (22.3%) fs: btrfs dev: /dev/dm-0 
           maj-min: 254:0 mapped: luks-0f3bffe8-12fe-4da3-b170-086236fd31ee 
Swap:      Kernel: swappiness: 133 (default 60) cache-pressure: 100 (default) 
           ID-1: swap-1 type: zram size: 15.55 GiB used: 2 MiB (0.0%) priority: 100 dev: /dev/zram0 
Sensors:   System Temperatures: cpu: 50.1 C mobo: N/A gpu: nvidia temp: 43 C 
           Fan Speeds (RPM): N/A gpu: nvidia fan: 35% 
Info:      Processes: 409 Uptime: 13m wakeups: 0 Memory: 15.55 GiB used: 4.75 GiB (30.6%) Init: systemd v: 249 tool: systemctl 
           Compilers: gcc: 11.1.0 clang: 12.0.1 Packages: pacman: 1559 lib: 471 Shell: fish v: 3.3.1 default: Bash v: 5.1.8 
           running-in: code inxi: 3.3.06

As you can see allow-discards is set as a kernel parameter. The discard option is also in fstab, crypttab, and I've enabled it in /etc/lvm/lvm.conf.

Output of lsblk --discard /dev/sda:

NAME                                          DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                                                  0      512B       4G         0
|-sda2                                               0      512B       4G         0
`-sda3                                               0      512B       4G         0
  `-luks-0f3bffe8-12fe-4da3-b170-086236fd31ee        0        0B       0B         0

As you can see discard is in fact working on every partition except the LUKS mapper, I don't have anything else to try at this point so I came to the forums.

Bad practice. Better to enable & start fstrim.timer in systemd? (It’s what I do, but does it work the same with LUKS?)

2 Likes

I'm just trying to get it to work before going the optimal route

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