As is common knowledge, SSDs have a limited number of PE (Program-Erase) cycles before the NAND cells die.

Therefore, it is very helpful to know how much data has been written to your SSD, in order to determine how much longer it will last before the NAND dies.

I have a Samsung 850 Pro 512GB SSD, and I am running Ubuntu 14.04.

How can I get the TBW (Total-Bytes-Written) for my drive?

up vote 7 down vote accepted

FULL DISCLOSURE: The scipt/commands present in this answer are not my own, but rather the work of J. D. G. Leaver. They were sourced from a blog post on his website.


NB:

  • This will only report accurate numbers for Samsung SSDs
  • You need to have smartctl installed

Method 1:

Here's a handy little script that will allow you to monitor the TBW of your SSD, along with some other information:

#!/bin/bash

#######################################
# Variables                           #
#######################################

SSD_DEVICE="/dev/sda"

ON_TIME_TAG="Power_On_Hours"
WEAR_COUNT_TAG="Wear_Leveling_Count"
LBAS_WRITTEN_TAG="Total_LBAs_Written"
LBA_SIZE=512 # Value in bytes

BYTES_PER_MB=1048576
BYTES_PER_GB=1073741824
BYTES_PER_TB=1099511627776

#######################################
# Get total data written...           #
#######################################

# Get SMART attributes
SMART_INFO=$(sudo /usr/sbin/smartctl -A "$SSD_DEVICE")

# Extract required attributes
ON_TIME=$(echo "$SMART_INFO" | grep "$ON_TIME_TAG" | awk '{print $10}')
WEAR_COUNT=$(echo "$SMART_INFO" | grep "$WEAR_COUNT_TAG" | awk '{print $4}' | sed 's/^0*//')
LBAS_WRITTEN=$(echo "$SMART_INFO" | grep "$LBAS_WRITTEN_TAG" | awk '{print $10}')

# Convert LBAs -> bytes
BYTES_WRITTEN=$(echo "$LBAS_WRITTEN * $LBA_SIZE" | bc)
MB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_MB" | bc)
GB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_GB" | bc)
TB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_TB" | bc)

# Output results...
echo "------------------------------"
echo " SSD Status:   $SSD_DEVICE"
echo "------------------------------"
echo " On time:      $(echo $ON_TIME | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') hr"
echo "------------------------------"
echo " Data written:"
echo "           MB: $(echo $MB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "           GB: $(echo $GB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "           TB: $(echo $TB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "------------------------------"
echo " Mean write rate:"
echo "        MB/hr: $(echo "scale=3; $MB_WRITTEN / $ON_TIME" | bc | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "------------------------------"
echo " Drive health: ${WEAR_COUNT} %"
echo "------------------------------"

Here's the a sample of the output:

------------------------------
 SSD Status:   /dev/sda
------------------------------
 On time:      2 hr
------------------------------
 Data written:
           MB: 25,098.917
           GB: 24.510
           TB: .023
------------------------------
 Mean write rate:
        MB/hr: 12,549.458
------------------------------
 Drive health: 100 %
------------------------------

This data is accurate, as I only just installed my new 850 Pro.


Method 2:

Alternatively, here's a one-liner to get the TBW only:

echo "GB Written: $(echo "scale=3; $(sudo /usr/sbin/smartctl -A /dev/sda | grep "Total_LBAs_Written" | awk '{print $10}') * 512 / 1073741824" | bc | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
  • This doesn't work for my SAMSUNG MZ7LN512HMJP-000L7 SSD. smartctl reports Total_LBAs_Written to be 2268 and this produces 1.1 MB written -- clearly incorrect for a drive that's over a year old and is my primary system drive :( – Icydog Jul 22 at 18:40
  • @Icydog :( what version of Ubuntu are you running? – Android Dev Jul 22 at 19:21
  • I'm on Fedora 27. I think my SSD is probably just not reporting the numbers correctly. – Icydog Jul 23 at 20:33

Crucial SSD Lifetime remaining

For Crucial SSD (made by Micron) the question of remaining lifetime is made a little easier.

https://www.micron.com/~/media/documents/products/technical-note/solid-state-storage/tnfd22_client_ssd_smart_attributes.pdf

This doc identifies 202 as Percent Lifetime Remaining. As an example on Ubuntu 16.04 (sudo smartctl /dev/sda1 -a) reports 202 as unknown, but the value of 90 (in my case) matches the description in the pdf, and indicates 90% life remaining. This can be appropriately scaled by the TBW that is given in the crucial.com literature on the drive that you have. Actually, lifetime remaining is rather more useful.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.