Cookie

Check disk health with Linux

Published by TheJoe on

Estimated reading time: 5 minutes

Today we try to understand how to check the health status of any disk connected to a GNU/Linux system using both the terminal, and graphic tools.

Checking the health of your disks from time to time is important to avoid possible system failures, or worse, the loss of important data. Obviously a disk that is healthy today does not mean that it won't fail tomorrow, therefore it is always good to regularly perform incremental backups of important data and keep more than one copy.

As we will see in this article, checking disk health is a rather simple process. Let's see how it's done.

Smartctl

Modern records (and with “modern” I mean most records on the market since 2006 to date) are “S.M.A.R.T.”, acronym for “Self-Monitoring, Analysis and Reporting Technology”: an automatic monitoring system for rotary or solid state disks to detect and provide various reliability indicators, in the hope of anticipating malfunctions. Smartctl reads this data and performs these monitors.

Installing smartmontools

Smartctl is a package included in a collection of packages under the name smartmontools. To install it you will need to start your package manager and install the smartmontools package.

Use smartctl

Smartctl is a software that is rather intuitive to use, although it is a program without a graphical interface. First you need to start it as system administrator, then you will need to log in as root, or type in terminal su - the sudo su and obtain these rights.

Let's check how many and which disks are physically connected to our system. Pay attention that for example /dev/sda indicates a disk, while /dev/sda1 indicates a partition.

# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 465.8G  0 disk
├─sda1   8:1    0     2M  0 part
├─sda2   8:2    0    64M  0 part /boot/efi
├─sda3   8:3    0     2G  0 part [SWAP]
└─sda4   8:4    0 463.7G  0 part /mnt2/home
                                 /mnt2/ROOT
                                 /home
                                 /opt
                                 /tmp
                                 /root
                                 /boot/grub2/x86_64-efi
                                 /boot/grub2/i386-pc
                                 /var
                                 /srv
                                 /usr/local
                                 /.snapshots
                                 /
sdb      8:16   0 465.8G  0 disk
└─sdb1   8:17   0 465.8G  0 part
sdc      8:32   0 465.8G  0 disk
sdd      8:48   0   1.8T  0 disk
└─sdd1   8:49   0   1.8T  0 part
sde      8:64   0   3.6T  0 disk
└─sde1   8:65   0   3.6T  0 part /mnt3/joe/backup_OMV
                                 /mnt2/multimedia
                                 /mnt2/prova
                                 /mnt2/backup_OMV
                                 /mnt2/prova123
                                 /mnt2/7e4dea98-7ee6-4345-8ac7-9bc11fc820e8

In my case I have the following situation:

  • A disc “sda” (of system) mounted with 4 partitions,
  • A disc “sdb” not mounted with 1 partition,
  • A disc “sdc” unmounted apparently without partitions
  • A disc “sdd” not mounted with 1 partition,
  • A disc “sde” mounted with 1 partition.

Let's run smartctl on one of the disks:

# smartctl -a /dev/sda
smartctl 7.2 2021-09-14 r5237 [x86_64-linux-5.14.21-150400.24.100-default] (SUSE RPM)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Blue
Device Model:     WDC WD5000AAKX-00ERMA0
Serial Number:    WD-WMB3G1327290
LU WWN Device Id: 5 0014ee 2b231dd46
Firmware Version: 15.01H15
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Size:      512 bytes logical/physical
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS (minor revision not indicated)
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Sun Feb 11 19:49:11 2024 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

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

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
                                        was completed without error.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                ( 8580) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        General Purpose Logging supported.
Short self-test routine
recommended polling time:        (   2) minutes.
Extended self-test routine
recommended polling time:        (  87) minutes.
Conveyance self-test routine
recommended polling time:        (   5) minutes.
SCT capabilities:              (0x3037) SCT Status supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0027   144   144   021    Pre-fail  Always       -       3766
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       20
  5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x002e   200   200   000    Old_age   Always       -       0
  9 Power_On_Hours          0x0032   097   097   000    Old_age   Always       -       2474
 10 Spin_Retry_Count        0x0032   100   253   000    Old_age   Always       -       0
 11 Calibration_Retry_Count 0x0032   100   253   000    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       20
192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       14
193 Load_Cycle_Count        0x0032   200   200   000    Old_age   Always       -       5
194 Temperature_Celsius     0x0022   115   103   000    Old_age   Always       -       28
196 Reallocated_Event_Count 0x0032   200   200   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0032   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   200   200   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0032   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x0008   200   200   000    Old_age   Offline      -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%      2458         -
# 2  Short offline       Completed without error       00%      2434         -
# 3  Short offline       Completed without error       00%      2410         -
# 4  Short offline       Completed without error       00%      2387         -
# 5  Short offline       Completed without error       00%      2363         -
# 6  Short offline       Completed without error       00%      2339         -
# 7  Short offline       Completed without error       00%      2315         -
# 8  Short offline       Completed without error       00%      2291         -
# 9  Extended offline    Completed without error       00%      2291         -
#10  Short offline       Completed without error       00%      2268         -
#11  Short offline       Completed without error       00%      2244         -
#12  Short offline       Completed without error       00%      2220         -
#13  Short offline       Completed without error       00%      2196         -
#14  Short offline       Completed without error       00%      2172         -
#15  Short offline       Completed without error       00%      2148         -
#16  Short offline       Completed without error       00%      2124         -
#17  Short offline       Completed without error       00%      2100         -
#18  Short offline       Completed without error       00%      2076         -
#19  Short offline       Completed without error       00%      2052         -
#20  Short offline       Completed without error       00%      2028         -
#21  Short offline       Completed without error       00%      2004         -

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

The output will be very long and complete. In case of doubt, I suggest checking the values ​​item by item by comparing them with the official references indicated for example Su Wikipedia. The data can be exported to a text file with the following command:

# smartctl -a /dev/sda >> /home/username/Documenti/drive-report.txt

Gnome disks

Another approach is the one used by the gnome disks software, where the use of the terminal will not be necessary. To use it you will need to install the package gnome-disk-utility with your distribution's package manager. Those who use Gnome will probably already have it installed. To start it, just write in the dashboard (or search among applications) “disks“.

Look here:  Check a Linux desktop from Windows or Linux with VNC

Disc health – gnome disks

We launch the Gnome Disk utility from our dashboard and when it starts it will automatically select the first disk connected to the computer.

We select the disk we want to check and click on the three dots in the column in the title bar next to the close buttons on the right. Then we click on “SMART Data & Self-Tests…” (not a very happy place, but we are satisfied). Or we select the disk and press Ctrl + S on the keyboard.

To perform a “Self-test” just click the button at the bottom left and analyze the result upon completion.


TheJoe

I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.