Solid State Drives (SSD) and Linux

As most people know by now, Solid State Drive (SSD) drives are rapidly dropping in price and increasing in size, much like we saw with hard drives (HDD).

If you work in IT, you will not need to read this article. I am presenting it here to help people who are considering moving over to Linux to replace their desktop PC, or even building a Linux home server.

SSDs come in many configurations and each has inherent benefits and weaknesses. I will not bore you with the details. If you are interested, you look them up here.

Linux is an operating system that has always been designed to be extremely fast, even on old hardware. One of the reasons for this is that most of the hard work is done with both applications and data being accessed via the PC RAM, rather than reading from the storage medium, such as a HDD. The program code is read once from the storage device and any persistent data is eventually written to another storage area. The way the file system is divided up in a typical Linux installation is as follows:

  • the root ”/” directory
  • the “/usr” directory reserved for the programs
  • the “/var” directory contains persistent temporary data
  • the “/home” contains personal data

When you look at this and you know that weakness that SSD drives have, is a limit to the total number of “write” operations (endurance), it should become clear, that one could benefit from installing up to 3 SSD drives in a basic server and by doing this, you could potentially limit the “write” operations to predominantly only 2 drives. In addition, if the total write operations on each of the installed drives could be monitored, you potentially decide that replacing a drive may be prudent option, if the write count is approaching the manufacturer’s specified maximum.

The table below shows how the location of the core Linux directories on, one or more SSD drives, can direct the read and write operations, so that failure due to drives reaching their total number of writes is limited to only one device. In the table, “service” simply refers to a service you are offering outside of your home.

Home PC ApplicationSSDsDirectories
A laptop, or mini computer, not running any services. Space is the issue here in that the PC is able to house more than one drive. In this case, I would recommend the largest capacity drive that you can afford, to ensure that that Linux has the ability to distribute the write operations over a much larger disc space.1Drive 1
/,/usr,/var,/home
A budget server with a few services. Nearly all motherboards support the installation of at least 4 SATA drives, so any are suitable for this.2Drive 1
/,/usr,/home
Drive 2
/var
A medium sized server, with lot’s of applications and a number of services. You can still use a standard desktop PC, as it will support at least 4 SATA drives, or you may consider a small server chassis. The logic detailed in this post still applies.3Drive 1
/,/usr
Drive 2
/var
Drive 3
/home

Linux has a standard application called “smartd” which allows the operating system to monitor any disk drive in real-time. The statistics that this application collects can be automatically displayed using this simple bash script. I use this script on all of my machines, with a large variety of SSD drives and it works well, displaying the result in human readable form.

#!/bin/bash
# This script will use the utilities smartctl and lsblk to
# see have many writes have been made to installed SSD drives
#
# Get a list of unique physical drives
drives=$(lsblk -d -n -o NAME | sort -u)
# Iterate through the physical drives
for drive in $drives; do
  # Check if the device is an SSD
  if sudo smartctl -i /dev/$drive | grep -q "Solid State Device"; then
    # Extract the manufacturer's model number
    model_number=$(sudo smartctl -i /dev/$drive | awk -F ': ' '/Device Model/ { print $2 }' | sed 's/^[ \t]*//;s/[ \t]*$//')
    # Extract the total writes using smartctl
    total_writes=$(sudo smartctl -a /dev/$drive | awk '/Total_LBAs_Written/ { print $10 }')
    # Check if total_writes is not empty (SSD supports this attribute)
    if [ -n "$total_writes" ]; then
      # Calculate the total writes in TiB
      total_writes_tib=$(echo "scale=3; ($total_writes * 512) / 1024 / 1024 / 1024 / 1024" | bc -l)
      echo "/dev/$drive ($model_number): $total_writes_tib TiB written in total"
    else
      echo "/dev/$drive ($model_number): Not supported on your storage drive."
    fi
  fi
done

Here is a sample output from this script on one of my servers:

/dev/sda (Samsung SSD 860 EVO 1TB): 10.600 TiB written in total
/dev/sdb (Samsung SSD 870 EVO 2TB): 2.119 TiB written in total
/dev/sdc (Samsung SSD 870 EVO 2TB): 1.929 TiB written in total
/dev/sdd (Samsung SSD 870 EVO 2TB): .298 TiB written in total

If you install an immutable Linux distribution, such as Fedora Silverblue, you have even tighter control over the write operations, as the core operating system is read-only, by definition (hence immutable). These distributions put user installed applications in another well defined directory and the variable data in another well defined directory. If you look at the documentation that comes with this type of distribution, you will easily be able to decide how to split up the directories over multiple SSDs to limit the total writes.

Remember that disk failure is only one of many things that can break over time. Using multiple SSD drives does not avoid the necessity of doing backups, however, if your configuration is set up as shown above, it also become a lot easier to decide what needs to be backed up more often. The general backup strategy that I use is, if it is data that changes, then back it often. If it is read-only Linux applications, then don’t bother. Remember that this is a home environment where re-downloading a distribution of Linux and installing it on a replacement SSD is a practical proposition. We have no licences to contend with when doing this.

Similar Posts