How to enable SSD TRIM support on Fedora 17?

7,921

Solution 1

This is pretty easy, now that TRIM can pass through LVM to the underlying device(s).

  1. When you install, make sure your filesystems are all set to ext4. TRIM is not supported on ext3.

  2. After you install, login as root and edit /etc/fstab. In the fourth column (that usually reads defaults) add the keyword discard. Do this for both the / and /boot partitions, and any other partitions you created on the SSD.

    An example:

    /dev/mapper/vg_mymachine-lv_root /                       ext4    discard         1 1
    UUID=94b6d32d-ec21-4028-9a89-b1a19849c4ad /boot                   ext4    discard         1 2
    

    (If defaults is the only keyword there, it can be replaced with discard. If other keywords are there, append it with a comma, e.g. whatever,discard.)

    Nothing needs to be done for swap; all swap partitions automatically support TRIM.

  3. LVM support for discard is disabled by default. Enable it by editing /etc/lvm/lvm.conf and changing issue_discards = 0 to issue_discards = 1.

  4. Restart the computer.

Solution 2

There were some problems in Fedora 18 with LUKS not propagating TRIM commands, but this was fixed in Fedora 19. On my system, TRIM commands propagate successfully. One just needs to make few changes in the configuration. First of all, we need to check if TRIM propagates for all partitions to the end device:

[lzap@lzapx ~]$ lsblk -D
NAME                                            DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                                                    0      512B       2G         1
├─sda1                                                 0      512B       2G         1
└─sda2                                                 0      512B       2G         1
  ├─fedora_lzapx-root                                  0      512B       2G         1
  ├─fedora_lzapx-swap                                  0      512B       2G         1
  └─fedora_lzapx-home                                  0      512B       2G         1
    └─luks-aaaaaaaa-6657-44f4-8297-bbbbbbbb1111        0      512B       2G         0

The last column shows if TRIM commands do propagate. We can see all is set, except the encrypted home (the last line). To get full TRIM support on LUKS-encrypted devices, we need to allow TRIM commands. Note that this can decrease encryption strengh. This is the Fedora 19 default crypttab file:

$ cat /etc/crypttab
luks-aaaaaaaa-6657-44f4-8297-bbbbbbbb1111 UUID=aaaaaaaa-6657-44f4-8297-a571e02e5492 none

I added allow-discards option there:

$ cat /etc/crypttab
luks-aaaaaaaa-6657-44f4-8297-bbbbbbbb1111 UUID=aaaaaaaa-6657-44f4-8297-a571e02e5492 none allow-discards

Optional LVM configuration

If you modify your LVM logical volumes often (e.g. shrinking, deleting), you want to set issue_discards to 1 in `/etc/lvm/lvm.conf. Then you need to do the next optional step described bellow.

Optional init RAM disk regeneration

If you have root partition encrypted by LUKS (not my case) or if you have your root partition on LVM and you want LVM trimming when shrinking or deleting (see above optional step), initial RAM disk needs to be regenerated using the following command:

dracut -f

You will need to reboot to make this change effective of course.

Now, to enable TRIM and take advantage of it, there are two options:

TRIM when deleting files

It is possible to configure ext4 to send TRIM commands while deleting data. You can do this by adding discard option to partitions in /etc/fstab. Note that this slows down deleting a bit. It depends on the SSD drive, but this can slow down quite significantly on some drives.

Do not put discard option to swap devices as this is not required (and perhaps it will not work either). Swap is SSD friendly by default and propagates TRIM command.

TRIM from cron

This is the preferred option because it can be scheduled daily, weekly or during night if you do not turn off your laptop/server:

cat /etc/cron.weekly/01-fstrim
#!/bin/sh
fstrim /
fstrim /home

chmod +x /etc/cron.weekly/01-fstrim

Try to run the script now, it should not print any error message. If you changed LUKS configuration, you might need restart before doing that.

http://lukas.zapletalovi.com/2013/11/how-to-trim-your-ssd-in-fedora-19.html

Share:
7,921

Related videos on Youtube

CodeSun
Author by

CodeSun

Updated on September 18, 2022

Comments

  • CodeSun
    CodeSun almost 2 years

    I used to install Linux on HDD. It's easy. But now I have a SSD, and I want to install Fedora 17 on it.

    What should I do to make Fedora 17 issue TRIM commands to the SSD?

    • Mikel
      Mikel almost 12 years
      How big is your SSD? It should work fine. Did you try installing it already?
    • CodeSun
      CodeSun almost 12 years
      128GB. It's on my notebook computer.
    • Mikel
      Mikel almost 12 years
      So what problem are you having? Do you need help partitioning? Help with the bootloader? What exactly are you asking?
    • sr_
      sr_ almost 12 years
      The Fedora Guide (for 14) has a chapter on deployment on SSD, is it helpful?
    • daisy
      daisy almost 12 years
      I don't see any difference on installation, what you expecting, tuning ?
    • CodeSun
      CodeSun almost 12 years
      Well,just like "trim" in windows. How to set "trim" in the Fedora17?
    • cedbeu
      cedbeu almost 12 years
      So your original question should be modified, maybe (note: maybe this article could help en.wikipedia.org/wiki/TRIM#Operating_system_support).
    • phemmer
      phemmer almost 12 years
      First make sure you even need trim and aren't just wasting time. Some SSDs don't use it at all, and instead wear-level the entire device whether blocks are in use or not.
  • Amitav Pajni
    Amitav Pajni over 10 years
    If your root filesystem is encrypted, you must do this and then rebuild your initramfs by rerunning dracut before it will take effect for the root filesystem.
  • lzap
    lzap over 10 years
    Yes, it is not as you can see from the above lsblk command. I made a note in my blogpost tho. And also changed the answer not to confuse googlers - thanks!