Make the solid state drive (SSD) plunge with Linux

Jack Wallen explains how you can optimize your Linux operating system for SSD.


Many TechRepublic readers have followed my difficulties with audio in Linux. For the longest time, PulseAudio was a tragedy to work with (on certain hardware -- my production recording studio machine being one of them). Things were starting to steer me toward making the leap to OS X, if only for just audio production, but then things took a turn for the slightly improved. What happened? I upgraded to Ubuntu 13.10.

The improvements for audio productions are marked, especially recording. I no longer experience random stops in the input stream, so I don't have to punch sections to fix sound loss. I still notice skipping during playback, which isn't a deal breaker as much as it is an annoyance. However, as with everything, I have a plan.

Solid state drive

That's right, I'm going to migrate my machine into modern times and use a solid state drive (SSD). Why? The drastic performance gain with these devices should, at least in theory, fix the last issue I have with Linux and audio.

But wait! Isn't Linux rumored to not be ready for prime time SSD usage? At one point, that was the case... but actually, it was more the hardware not truly being ready for prime time. Every platform had to deal with write aheads causing fast degradation of the hardware. However, there was a recent article on StorageSearch that went into great detail on why you shouldn't worry about the lifespan of an SSD. Effectively, they ran tests that concluded, even when an SSD receives writes at a continuous rate of 80M/s, the life span of said drive is 51 years. Those tests were based on 2007 SSD firmware. Things have changed quite a lot since then.

That doesn't mean that you should just throw a Linux distribution on an SSD and be done with it. In fact, there's at least one optimization that should be done before you “set it and forget it.” That optimization is TRIM, which effectively tells an operating system which blocks of data on an SSD are no longer considered in use and should be wiped internally. 

You can either configure Linux to handle TRIM automatically or you can run the TRIM command manually. I highly recommend setting this up to be automated. Here's how you do it:

  1. Open a terminal window
  2. Issue the command (you'll need root access or sudo): cp /etc/fstab ~/fstab
  3. Open /etc/fstab for editing in your favorite editor (such as nano)
  4. Add the “discard” option (no quotes) to the SSD drive entry (example below)
  5. Save the file

UUID=00000000-0000-0000-0000-000000000000  /  ext4  discard,errors=remount-ro  0  1

Note: The file system type is ext4. It's very important that your SSD be formatted to ext4, because that particular journaling system is best suited for SSDs.

Now, let's test the automatic TRIM. Follow these steps (updated on 11/13/13):

  1. Open a terminal window
  2. Change to the root directory of your SSD (if it's the only drive on the machine, it will be “/” -- no quotes)
  3. Issue the command (you'll need sudo or root): sudo dd if=/dev/urandom of=/home/USERNAME/tempfile count=100 bs=512k oflag=direct (where USERNAME is the actual name of your user account)
  4. Issue the command: sudo hdparm --fibmap tempfile
  5. From the output of the hdparm command, copy the number under the begin_LBA section
  6. Verify the device name of your SSD (sda, sdb, sdg, etc)
  7. Issue the command: sudo hdparm --read-sector [ADDRESS] /dev/sdX (where ADDRESS is the number you copied from the begin_LBA section and sdX is the SSD device name)
  8. Remove the tempfile created from the output of the sudo hdparm --fibmap tempfile command
  9. Issue the command: sync
  10. Repeat the hdparm command from above

At this point, the output of the hdparm command should be nothing but zeroes. If that's the case, automatic TRIM is working. If you do not get only zeroes, give the system an hour or so and rerun the hdparm command. Hopefully, at that point, you should only see zeroes. This method of testing isn't flawless, because sometimes the TRIM does take longer.

Congratulations, your Linux operating system should be optimized for your SSD. Of course, not everything is created equal or perfect. Everyone will find varying results with Linux and SSDs, but the performance increase you receive with these devices is so significant that the trouble you might have to go through is well worth the time involved. 

Most importantly, as always, back up your data! It doesn't matter if you are using an HDD, SDD, or some newer drive based on Cylon technology -- be sure to back up your data!

Have you optimized your Linux operating system for SSD? Share your experience in the discussion thread below.

By Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic, The New Stack, and Linux New Media. He's covered a variety of topics for over twenty years and is an avid promoter of open source. For more news about Jack Wallen, visit his website jackwallen....