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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
This is pretty easy, now that TRIM can pass through LVM to the underlying device(s).
When you install, make sure your filesystems are all set to ext4. TRIM is not supported on ext3.
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
/boot partitions, and any other partitions you created on the SSD.
/dev/mapper/vg_mymachine-lv_root / ext4 discard 1 1 UUID=94b6d32d-ec21-4028-9a89-b1a19849c4ad /boot ext4 discard 1 2
defaults is the only keyword there, it can be replaced with
discard. If other keywords are there, append it with a comma, e.g.
Nothing needs to be done for swap; all swap partitions automatically support TRIM.
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.
Restart the computer.
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
allow-discards option there:
$ cat /etc/crypttab luks-aaaaaaaa-6657-44f4-8297-bbbbbbbb1111 UUID=aaaaaaaa-6657-44f4-8297-a571e02e5492 none allow-discards
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.
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:
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:
It is possible to configure ext4 to send TRIM commands while deleting data.
You can do this by adding
discard option to partitions in
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.
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.