LVM Fstab – Where to Enable Discard Option

btrfsfstablukslvmssd

I'm installing a system on SSD with LUKS and Btrfs, where should I enable discard option for TRIM support? Only /etc/crypttab, only /etc/fstab, everywhere, or nowhere since Btrfs detects SSDs and enables TRIM support?

I also use LVM, shoud I somehow change configs to activate TRIM support for LVM too?

P.S. I know about security implications on LUKS with TRIM and I'm fine with it.

Best Answer

For TRIM to work, it has to be enabled on all layers. The first step therefore is to enable it in LUKS as LUKS normally disables TRIM due to the security implications. For some distributions you do this in the crypttab, for others you need to edit the cmdline. Since LVM is the next layer on top of LUKS it needs to pass TRIM, which it does per default if the underlying device supports it. Additionally you can set issue_discards = 1 in your lvm.conf, which will bulk-TRIM on lvremove and vgremove. With this in place you can either use fstrim or enable btrfs' native discard (set discard in fstab, see here). If everything works successfully, btrfs will print

BTRFS info (device <something>): turning on discard

to syslog.