Enable SSD trim (discard) on LVM on LUKS

2025-05-18

The command fstrim tells SSD to discard unused blocks on a mounted filesystem (SSDs may require this to maintain performance over time). You can automate this (e.g. via weekly cron) for periodic TRIM.

By default, discard requests do not pass through LUKS or LVM. You must explicitly enable them.

LVM

Uncomment or add in /etc/lvm/lvm.conf:

issue_discards = 1

This allows discard requests to propagate to the underlying device.

LUKS

Add the discard option in the kernel command line. For example rd.luks.options=discard in /boot/refind_linux.conf:

"amazingname"   "root=/dev/mapper/amazingname-void rd.luks.name=123-456-789=amazingname rd.luks.options=discard rw loglevel=4 net.ifnames=0"

Run:

# cryptsetup --allow-discards --persistent refresh /dev/sdXY amazingname

(sdXY is your encrypted partition and amazingname is the LUKS mapping name)

Test

Regenerate initramfs:

# dracut --force

Reboot.

Test if it works:

# fstrim -v /

When it outputs the discard operation is not supported it does not work. When the output displays number of bytes trimmed, it works.

Do not be confused

The discard option in /etc/fstab does not mean the same as in /etc/crypttab: “allow discard requests to be passed through”.
It means the same as in mount : “causes discard/TRIM commands to be issued to the block device when blocks are freed”.

You can use it on devices that you are not trimming periodically or manually, for example swap:

/dev/mapper/amazingname-swap	none    swap    defaults,discard    0 0