How to check TRIM is working on your SSD running Linux

来源:互联网 发布:python gui qt pdf 编辑:程序博客网 时间:2024/05/19 23:02

Does your drive need a trim?

SSDs really spank traditional disks. But due to a quirk of how they work, they can lose some speed over time. To make sure your disk stays at the same blazing speeds as when you first got it you need to have TRIM enabled. TRIM is a slight optimisation that allows the disk to do some housekeeping behind the scenes.

What you need for TRIM:

  1. An SSD with firmware that supports TRIM
  2. Linux kernel version 2.6.33 or higher. That means Ubuntu 10.10, Fedora 13 or better.
  3. The “discard” option in your /etc/fstab

If you haven’t already done this you can find out how here.

To check that TRIM is working the way it should we’ll create a small file on your SSD, inspect it, then delete it and make sure TRIM has zeroed all the data out.

Open a root terminal, or if on an Ubuntu-based system become root with:

sudo -i

Create a small file in /root (this is all one line):

dd if=/dev/urandom of=tempfile bs=1M count=3

Find the start of the file:

hdparm --fibmap tempfile

Note the address that the file starts at and then inspect that address (if you have more than one disk you should substitute sda for the disk you are checking):

hdparm --read-sector [ADDRESS] /dev/sda

You should see random data. Now delete the file, sync the filesystem, and wait a couple of minutes for the disk to do it’s thing:

rm tempfile && sync && sleep 120

Now let’s inspect that piece of the drive again to make sure the data is gone:

hdparm --read-sector [ADDRESS] /dev/sda

If TRIM is working, you should see all zeros. If you see anything except a sea of zeros then try updating the drive’s firmware. That’s pretty straightforward on recent drives. On Intel SSDs you just burn a small utility to a CD and boot up from it. Make sure you back up your data before you do that, just in case.