for good overview it makes sense to label the harddisk partitions according to functionality (what is their purpose?)

GNU Linux bash – how to label partitions tune2fs (xfs & ext4)

… because maybe one wants to read their smart status.

# tested on:
hostnamectl 
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 5.X
      Architecture: x86-64

# and also:
hostnamectl
   Static hostname: storagepc
  Operating System: Debian GNU/Linux 9 (stretch)
            Kernel: Linux 4.9.0-11-amd64
      Architecture: x86-64

# prepare
# on deb(apt) based systems ubuntu/debian/mint
# install software
apt-get install smartmontools
# rpm based systems fedora/redhat/centos
yum install smartmontools
# enable service
service smartd start ; chkconfig smartd on
# check what harddisks are in your system
lsblk
# enable smart for all
smartctl -s on /dev/sda
smartctl -s on /dev/sdb

vim /scripts/harddisk_iteration.sh
# fill with:

#!/bin/bash

echo "=== iterate over all harddisks in the system: ==="
for x in {a..z}
do
if test $(ls /dev |grep sd$x |wc -l) != 0; then
	echo "------------------- /dev/sd$sd$x --------------------";
	/usr/sbin/smartctl -H /dev/sd$sd$x;
	/usr/sbin/smartctl -i /dev/sd$sd$x;
fi
done

echo "=== print nice overview over all harddisks and filesystems: ==="
lsblk -o "NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID"

warning!

just because “smart” says “passed” (everything okay) does not mean, the harddisk will fail, a few hours or a day after that “passed” message. (predictions based on smart are hard to do… but as soon as smart goes bad, one should swap harddisks immediately… or have spare RAID harddisks already preinstalled (would be best).

also important: simulate raid failure… what will happen if one pulls out one of two harddisks of RAID1?

how long is the rebuild time (multiple hours for 2TB and probably 2-3 Days for 4TB SATA drives).

example output:

(imho most external USB harddisks smart status can not be read)

=== iterate over all harddisks in the system: ===
------------------- /dev/sda --------------------
smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-11-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-11-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model:     LITEONIT LCS-256M6S 2.5 7mm 256GB
Serial Number:    ...
Firmware Version: DC8110D
User Capacity:    256,060,514,304 bytes [256 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ATA8-ACS, ATA/ATAPI-7 T13/1532D revision 4a
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Sat Jan  4 16:14:11 2020 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

------------------- /dev/sdb --------------------
smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-11-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-11-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     SAMSUNG SpinPoint F2 EG
Device Model:     SAMSUNG HD103SI
Serial Number:    ...
LU WWN Device Id: 5 0024e9 00139b5d7
Firmware Version: 1AG01113
User Capacity:    1,000,204,886,016 bytes [1.00 TB]
Sector Size:      512 bytes logical/physical
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA/ATAPI-7, ATA8-ACS T13/1699-D revision 3b
Local Time is:    Sat Jan  4 16:14:11 2020 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

------------------- /dev/sdc --------------------
smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-11-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-11-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Constellation ES.3
Device Model:     ST2000NM0033-9ZM175
Serial Number:    ...
LU WWN Device Id: 5 000c50 07a708a36
Firmware Version: SN04
User Capacity:    2,000,398,934,016 bytes [2.00 TB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2 (minor revision not indicated)
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Sat Jan  4 16:14:11 2020 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

....

more compact output:

just drive letter, smart status and device model

#!/bin/bash

echo "=== iterate over all harddisks in the system: ==="
for x in {a..z}
do
if test $(ls /dev |grep sd$x |wc -l) != 0; then
	echo "------------------- /dev/sd$sd$x --------------------";
	/usr/sbin/smartctl -H /dev/sd$sd$x;
	/usr/sbin/smartctl -i /dev/sd$sd$x | grep Model;
	echo "";
fi
done

qnap tested smart status script:

echo "=== model ==="
/sbin/getsysinfo model
echo ""

echo "=== CPU temperature ==="
/sbin/getsysinfo cputmp
echo ""

echo "=== info about hds ==="
HDNUM=$(/sbin/getsysinfo hdnum)
echo ""

echo "there are $HDNUM harddisks in the system"

for (( i = 1; i <= $HDNUM; i++ ))
do
	echo ""
	echo ""
	echo "== info about harddisk no $i =="
	echo "temp: "
	/sbin/getsysinfo hdtmp $i
	echo ""
	echo "smart: "
	/sbin/getsysinfo hdsmart $i
	echo ""
	echo "hdstatus: "
	/sbin/getsysinfo hdstatus $i
	echo "model: "
	/sbin/getsysinfo hdmodel $i
	echo "capacity: "
	/sbin/getsysinfo hdcapacity $i
done

# === manual ===:
# cputmp : get CPU temperature
# systmp : get system temperature
# sysfan [fan no] : get system fan speed
# sysfannum : get total system fan number
# hdnum : get total system SATA disk number
# hdtmp [disk no] : get SATA disk temperature
# hdstatus [disk no] : get SATA disk status
# hdmodel [disk no] : get SATA disk model
# hdcapacity [disk no] : get SATA disk capacity
# hdsmart [disk no] : get SATA disk SMART summary
# model : get system model name
# sysvolnum : get system volume number
# vol_desc [volume no] : get volume description
# vol_fs [volume no] : get volume file system
# vol_totalsize [volume no] : get volume total size
# vol_freesize [volume no] : get volume free size
# vol_status [volume no] : get volume status

sample output:

./smart.sh  
=== model ===
TS-559 Pro+
=== CPU temperature ===
45 C/113 F
=== info about hds ===

there are 5 harddisks in the system


== info about harddisk no 1 ==
temp: 
35 C/95 F
smart: 
GOOD
hdstatus: 
0
model: 
WD2003FYYS-02W0B
capacity: 
1.82 TB

== info about harddisk no 2 ==
temp: 
29 C/84 F
smart: 
GOOD
hdstatus: 
0
model: 
HD204UI         
capacity: 
1.82 TB

== info about harddisk no 3 ==
temp: 
36 C/96 F
smart: 
GOOD
hdstatus: 
0
model: 
WD2003FYYS-02W0B
capacity: 
1.82 TB

== info about harddisk no 4 ==
temp: 
35 C/95 F
smart: 
GOOD
hdstatus: 
0
model: 
WD2003FYYS-02W0B
capacity: 
1.82 TB

== info about harddisk no 5 ==
temp: 
36 C/96 F
smart: 
GOOD
hdstatus: 
0
model: 
WD2003FYYS-02W0B
capacity: 
1.82 TB[

Links:

https://www.smartmontools.org/

https://dwaves.de/2014/11/25/gnu-linux-bash-script-detailed-info-about-harddisk-and-smart-tests-short-and-long-and-scanning-for-badblocks/

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin