How to check an hard drive health in Linux using smartctl

The smartmontools package is generally available in the default repositories of all the major Linux distributions. It contains two utilities useful to check the status of storage with S.M.A.R.T support (Self Monitoring Analysis and Reporting Technology): smartcl and smartd.

The former is the utility we use directly to check S.M.A.R.T attributes, run tests, or perform other actions; the latter is the daemon which can be used to schedule operations in the background.

Tu install smartmontools use command:

sudo apt install smartmontools

Checking if SMART is enabled

Let’s become familiar with the smartctl utility. The first thing we want to check is if S.M.A.R.T support is active on the device. To perform this operation we can run the smartctl utility with the -i option (short for –info):

sudo smartctl -i /dev/sda

If SMART support is disabled we need to enable it:

sudo smartctl -s on /dev/sda

Getting S.M.A.R.T information with smartctl

To get information about hard drive /dev/sda use command:

sudo smartctl -a /dev/sda

Very important parameters to check are, among the others, “Reallocated_Sector_Ct” and “Current_Pending_Sector”. In both cases if the RAW_VALUE is something other than 0, we should be very careful and start to backup data on the hard drive. The Reallocated_Sector_Ct is the count of sectors on the block device which cannot be used correctly.

When such a sector is found it is remapped to one of the available spare sectors of the storage device, and data contained in it is relocated. The Current_Pending_Sector attribute, instead, is the count of bad sectors that are still waiting to be remapped. If you want to know more about the S.M.A.R.T attributes and their meaning, you can begin to take a look at the Wikipedia S.M.A.R.T page.