I know that the Linux kernel supports TRIM as of version 2.6.33, so there should be TRIM support in ubuntu 10.10.

Is TRIM enabled by default or do I need to change some settings or install additional software for it to work? If so, how?

link|improve this question

The SSD I want to use TRIM with is a OCZ Vertex 2 btw – Uli Dec 26 '10 at 12:45
feedback

2 Answers

up vote 49 down vote accepted

There are two forms of TRIM, manual (wiper.sh) and automatic:

1) Manual TRIM

In ubuntu this can be performed with fstrim, but is not needed when automatic TRIM is enabled. fstrim first appeared in 11.10, on earlier systems you have to use wiper.sh which can be found at /usr/share/doc/hdparm/contrib/wiper.sh.gz

2) Automatic TRIM

Automatic TRIM is supported since kernel 2.6.33 with the EXT4 file system

For automatic TRIM to work, the drive needs to be mounted with the "discard" option in fstab. To add this option run:

sudo cp /etc/fstab ~/fstab-backup
gksudo gedit /etc/fstab

add discard to options on the entry for the SSD; the line should read similar to this:

UUID=ed586ab8-08c5-4bae-b118-d191b716b4a4 /               ext4    discard,errors=remount-ro 0       1

reboot, automatic TRIM should now be working.

Testing automatic TRIM:

To Test if Trim is working issue the following commands (adapted from here):

cd  / #or whatever part of the file system is on the SSD
sudo dd if=/dev/urandom of=tempfile count=100 bs=512k oflag=direct # you will not need sudo for these to work, if your SSD is in /home for example
sudo hdparm --fibmap tempfile    

From the output copy the number under "begin_LBA" and use it in the next command. Also check the system name of your SSD: System->Administration->Disk Utility (sda, sdb, or sdc ...)

sudo hdparm --read-sector 2638848 /dev/sda #replace 2638848 with the number obtained before and /sda with your SSD drive

you should receive a a long string of characters for those sectors

sudo rm tempfile
sync
sudo hdparm --read-sector 2638848 /dev/sda

even after removing the file the sectors are still not empty. Wait a while then run the command again

sudo hdparm --read-sector 2638848 /dev/sda

if you get only zeros, then automatic TRIM is working.

link|improve this answer
Nice work! If you could leave an answer in the other ssd/trim question linking to this one it'll help people find it, thanks! – Jorge Castro Dec 30 '10 at 22:25
Sure, I added links at these 2 questions: askubuntu.com/questions/256/… askubuntu.com/questions/1400/optimize-for-ssd/19495#19495 – Uli Dec 30 '10 at 23:39
Got it working, thanks, but there are 2 typos here: Says: /dev/sdd when in fact it should be /dev/sda: sudo hdparm --read-sector 2638848 /dev/sdd even after removing the file the sectors are still not empty. Wait a while then run the command again sudo hdparm --read-sector 2638848 /dev/sdd if you get only zeros, then automatic TRIM is working. – J Bryan Jan 25 '11 at 2:17
I did say to replace with the name of the drive. But you are right that it is inconsistent, I'll try and make it simpler to understand. Stuff like this should be a comment not an answer btw – Uli Jan 25 '11 at 2:17
1  
@Gerry: I think that just means its working really well. You could try removing the discard option and then rebooting. You should then see that sectors do not empty themselves. – Uli May 19 at 17:31
show 11 more comments
feedback

Note that if you are using encryption the solutions posted here so far won't help you, because you need to enable TRIM support in the encryption layer as well. This can be done with kernel versions 3.1+ and cryptsetup versions 1.4+, both of which are included in Ubuntu 12.04.

Find my guide on setting TRIM up for LUKS encrypted partitions here:

http://worldsmostsecret.blogspot.com/2012/04/how-to-activate-trim-on-luks-encrypted.html

Feel free to comment / enhance / copy / share.

link|improve this answer
feedback

protected by Community Jul 8 '11 at 14:11

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.