Linux

Make the solid state drive (SSD) plunge with Linux

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

Linux-SSD.jpg

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.


About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

11 comments
CFWhitman
CFWhitman

Going SSD is a great way to improve performance.

I wonder, however, why you would use a standard distribution with PulseAudio enabled for audio production.  I would use a media aimed distribution with low latency kernel options enabled, and I would most likely disable PulseAudio (at least while I was recording) in favor of JACK.  Taking steps to lower your latency will also make playback better.  In fact, the ability to do this is the one big advantage of Linux for audio production use.

henk
henk

Works excellent, but I have used the crontab variant on my server with fstrim command.

@Shay_Ginsbourg
@Shay_Ginsbourg

While testing TRIM, i get the following error:


shay@Satellite:~$ sudo dd if=/dev/urandom of=tempfile count=100 bs=512k oflag=direct

dd: opening ‘tempfile’: Invalid argument


Can anybody please advise on that error? many thanks ;-) 

lnxguit
lnxguit

 My understanding is that the "discard" option is inferior to doing a daily cron job of fstrim.

cromero
cromero

Nice article.  Short, sweet, informative!

Regulus
Regulus

I have an older Lenovo Laptop.  I was going to upgrade the 2g mem to get some more performance when I found out that the unit could only handle 2g.  Similar issue as with a Netbook but also with a similar solution - go SSD!  I partitioned my HD to about 120g and disc cloned my Win7 Pro to the (256g) SSD.  After insuring that my Win 7 was ok, I partitioned the remaining space and loaded UBUNTU 13.4 on the new partition.  I get a Grub menu on boot and can go Linux or Win.  Yes, the speed of the SSD seems to overcome the lack of memory.  Linux is my OS of choice.  HOWEVER, I have serious issues with Audio since upgrading to 13.10 (contrary to your experience).  I also get system time (clock) jumps of (usually) 6 hours when booting back and forth between Win and Linux (only since upgrading to 13.10).    Audio issues are most prominent using Skype and camera recognition is also kind of so-so.  These are OS issues, however and have noting to do with the SSD performance - which I am very pleased with.  Check also, downloading about a g of family photo's on a Win 7 OS with a 5400 drive.  Then do the same down load on Linux with an SSD.  You're going to be amazed!  Have a good day !  ---  and I'll be tinkering with your suggestions later!

mitchloftus
mitchloftus

I've also been using Intel SSDs in a RAID on a Fedora 11 server for a couple of years now.  Of course, I'm using an Adaptec controller so there isn't much 'tuning' really required.... it just runs. Honestly, I don't notice a whole lot of performance improvement over the SCSI Raid I was previously running with 15K RPM drives, but in either case, it's fast enough that you would need a stopwatch and good reflexes to figure out which was faster, and by how much. If the difference in performance isn't noticeable, it can't be that important. Now, the difference in durability I don't (yet) know about. I did have an HD failure or two, but have not (yet) had an SSD fail in this application.

janitorman
janitorman

LOL Cylon technology.  I'm waiting for HP to perfect that "Analog storage" device or whatever they were touting a few years ago that didn't use ones and zeros, rather millions of bits of information per "dot" something like a pixel on a CRT screen. They were also touting that it could be memory, storage, and run the OS all in one postage stamp device.

Of course I'm also awaiting the 3D holographic screen so we can get rid of these tiny little "portable screens" with the stupid touch screen stuff on it.

Buck Rogers? Star Trek? Get Smart?  Who envisioned we'd all be carrying a cel phone in our pockets, even 20 years ago, and be able to do things like look up a Google map on it?

hondeman
hondeman

Hi Jack, nice article. I'm now using an SSD with an HDD in a raid1 in an asymetrical way, using "writemostly' on the HDD. Linux is the only OS I know of that can be tuned so efficient for SSDs.

jlwallen
jlwallen

@sginsbourg try this: replace "tempfile" with /home/USERNAME/tempfile where USERNAME is the actual username of your account.