How to Install Smartctl on Ubuntu 20.04 – Monitor the health of your hard disks

How to Install Smartctl on Ubuntu 20.04 – Monitor the health of your hard disks

As mentioned above, the smartctl command belongs to the smartmontools utilities that we can install from the official repositories of Ubuntu 20.04. To achieve this, open a terminal or SSH session.

Then, you can update the system

sudo apt update

sudo apt upgrade

Now you can install all the tools with the command

sudo apt install smartmontools

Then we have the commando available for us to use.

 

Using the Smartctl command on Ubuntu and check the health of the hard drive

The first thing we have to do is to run the command as root user. Either you do the commands as root user or using sudo.

To use it, you have to run this command

sudo smartctl -i [disk]

So, you have to replace [disk] with the path of the hard disk. For example:

sudo smartctl -i /dev/sda

From this screen output, pay attention to the last two that indicate if SMART support is enabled.

SMART support is: Available – device has SMART capability.

SMART support is: Enabled

In case the support is not enabled, you have to enable it with the following command:

sudo smartctl -s on -d ata /dev/sda

Remember to replace /dev/sda/ with the path of your device.

Now we can start a test to the hard disk. This can be long or short, depending on us. For a long test, run.

smartctl -t long /dev/sda

And for a short one

smartctl -t short /dev/sda

The same command will tell us how long we have to wait to verify the test, for example, this is the output I got:

smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.13.0-44-generic] (local build)

Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===

Sending command: “Execute SMART Short self-test routine immediately in off-line mode”.

Drive command “Execute SMART Short self-test routine immediately in off-line mode” successful.

Testing has begun.

Please wait 2 minutes for test to complete.

Test will complete after Wed Jun 1 16:28:30 2022 -04

Use smartctl -X to abort test.

Then, verify the test result with the following command:

sudo smartctl -l selftest /dev/sda

In my case, the disk has no error:

# 1 Short offline Completed without error 00% 1143 –

If there are errors, you can see them, and you will be given some recommendations.

 

Uninstalling the smartctl command

If you no longer want to use it, the best thing to do is to uninstall it from the system. To achieve this, just run.

sudo apt remove smartmontools

And that’s it.