Monday, December 11, 2017

Be Careful With Your SSD On Linux

My laptop has an SSD instead of a spinning hard disk.  The first laptop I had with an SSD was a company-issued ThinkPad with either a 32GB or 64GB SSD.  It was entirely too small for what I was doing at the time.  After that, I always chose capacity over speed for my laptop hard disk.

Skip to now and SSDs for laptops are entirely usable capacity-wise.  So my ThinkPad now has a 1TB SSD in it.  It came with one when I bought it, but I recently had to replace it because it failed.  SSDs are great, but you can beat them up rather quickly if you're not careful.

On my laptop I also use the LUKS encryption for my /home volume.  I don't encrypt the entire laptop because I don't really care that my man pages are encrypted or my cups configuration file is encrypted.  Just the stuff in /home is important to me.  What I failed to do was make sure I open the LUKS device with --allow-discards on the cryptsetup(8) command.

The --allow-discards option enables TRIM or UNMAP on the underlying device, though it's probably TRIM in nearly every case.  Without getting in to the technical details, this enables the kernel to handle unused blocks differently on an SSD than on a spinning hard disk.  TL;DR, this is important to not wear out the flash memory quickly.

So that's what happened to me.  And the failure was interesting too because the laptop just started acting very strangely until eventually write operations failed and then it started lying and saying the device was full.

Make sure you're unlocking LUKS volumes on SSDs with --allow-discards.  Every distribution is a little different, but a common method us defining the device in /etc/crypttab with the options you need to use.

No comments: