TRIM on LVM on LUKS on SSD on Fedora 25

Published on Author admin

How to enable TRIM on LVM on LUKS on SSD on Fedora 25 Linux.
If you have an SSD disk in your computer and you are using LVM virtual volumes together with LUKS disk encryption, below you will find how to activate TRIM for better SSD performance and longer lifetime.

Edit /etc/fstab file and append every filesystem with

discard

option:
Example:

/dev/mapper/vg_laptop-root /                       ext4    defaults,discard,noatime,x-systemd.device-timeout=0 1 1
UUID=XXXX-XXXX-XXXX-XXXX-XXXX /boot                   ext4    defaults,discard,noatime        1 2
/dev/mapper/vg_laptop-home /home                   ext4    defaults,discard,noatime,x-systemd.device-timeout=0 1 2

Edit /etc/lvm/lvm.conf file, set following option:

issue_discards = 1

Edit /etc/crypttab file, append line with

luks,discard

Example:

luks-XXXX-XXXX-XXXX-XXXX UUID=XXXX-XXXX-XXXX-XXXX-XXXX none luks,discard

Edit /etc/default/grub file by adding follwing argument

rd.luks.options=discard

at the end of

GRUB_CMDLINE_LINUX

parameter value.

Update GRUB bootloader configuration.
For system with BIOS:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

For system with UEFI:

sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

Generate initramfs file by applying command:

sudo dracut -f

Reboot your system:

reboot

Test whether TRIM is working:

fstrim -av

Edit /etc/crontab file to schedule automatic start of fstrim command.

0 * * * * root date -Iseconds >> /home/USERNAME/fstrim.log
1 * * * * root fstrim -av >> /home/USERNAME/fstrim.log