This is how I got support for TRIM to work on a Debian GNU/Linux system with ext4 filesystems on LUKS encrypted LVM volumes
- Append
,discardto the fourth column on relevant lines in/etc/crypttabFor me, this meant the fourth column should beluks,discardbut you may have other options in there. - Edit
/etc/lvm/lvm.confand changeissue_discards = 0toissue_discards = 1 - Edit
/etc/default/gruband appendrd.luks.options=discardto theGRUB_CMDLINE_LINUX_DEFAULTvalue. - Run
sudo update-grub - Run
sudo update-initramfs -u - Reboot
Test it
To test it, run:
sudo fstrim -av
Schedule it
When it works you can use systemd to have fstrim run on a regular schedule.
- Copy
/usr/share/doc/util-linux/examples/fstrim.*to/etc/systemd/system - Run
sudo systemctl enable fstrim.timer. systemd will now run fstrim weekly.
A word of caution
Please note that using TRIM on an encrypted volume is discouraged. This is due to the fact that TRIM may leak information about what goes on inside the encrypted volume. For example stuff like how much free space vs. used space there is. Which areas of the volume data is changing frequently, etc. This is all knowledge that an attacker may use to attack the encryption.
From man 5 crypttab:
WARNING: Assess the specific security risks carefully before enabling this option. For example, allowing discards on encrypted devices may lead to the leak of information about the ciphertext device (filesystem type, used space etc.) if the discarded blocks can be located easily on the device later.