在 Linux 系统中查看 SSD 的 SMART 信息

查看机器内置硬盘信息

1
sudo smartctl -i /dev/sdX

或者,用 -a 参数查看所有信息 sudo smartctl -a /dev/sdX

或者,用 -A 参数SMART参数信息 sudo smartctl -A /dev/sdX

查看移动固态硬盘(pssd)信息

1
2
3
4
5
sudo smartctl -d sat -i /dev/sdb

sudo smartctl -d sat -A /dev/sdb

sudo smartctl -d sat -a /dev/sdb

三星

已写数据量

1
echo "GB Written: $(echo "scale=3; $(sudo /usr/sbin/smartctl -d sat -A /dev/sdb | grep "Total_LBAs_Written" | awk '{print $10}') * 512 / 1073741824" | bc | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"

P/E Cycles / ID # 177 Wear Leveling Count

For Samsung SSDs, check SMART attribute 177 (Wear Leveling Count).

1
2
3
ID # 177 Wear Leveling Count

This attribute represents the number of media program and erase operations (the number of times a block has been erased). This value is directly related to the lifetime of the SSD. The raw value of this attribute shows the total count of P/E Cycles.

samsung_ssd_get_lifetime_writes.bash

  • 用之前改下 “SSD_DEVICE” 变量

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

SSD_DEVICE="/dev/sdb"

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 -d sat -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 "------------------------------"

执行效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ ./samsung_ssd_get_lifetime_writes.bash 
------------------------------
 SSD Status:   /dev/sdb
------------------------------
 On time:      3 hr
------------------------------
 Data written:
           MB: 14,081.572
           GB: 13.751
           TB: .013
------------------------------
 Mean write rate:
        MB/hr: 4,693.857
------------------------------
 Drive health: 100 %
------------------------------

西部数据

1
2
3
4
5
6
7
8
9
=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 4
Vendor Specific SMART Attributes with Thresholds:

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
233 Media_Wearout_Indicator 0x0032   100   100   ---    Old_age   Always       -       1204
234 Unknown_Attribute       0x0032   100   100   ---    Old_age   Always       -       1717
241 Total_LBAs_Written      0x0030   253   253   ---    Old_age   Offline      -       1482
242 Total_LBAs_Read         0x0030   253   253   ---    Old_age   Offline      -       2528

这四个参数,都是以G为单位。写入在前3个参数 233,234,241 的值同步增加,读取在 242 参数值增加。