Knowing how your system’s hardware is doing can help solve many performance problems and can also prevent dangerous situations with your data. For example, one of the most sensitive components of the computer is the hard disk because that is where we store data. Therefore, today you will learn how to install Smartctl in Ubuntu 20.04. Thanks to this command, you will learn how to monitor the health of the hard disk.
What is Smartctl and is it worth using?
Smartctl is part of the smartmontools which are tools that allow you to monitor storage devices.
These utilities are available in all GNU/Linux distros. With them, we can obtain information about the status of our hard disks, helping to prevent an imminent failure that could lead to the loss of information.
Some main features of these tools are:
- Schedule S.M.A.R.T. testing of your drive regularly with smartd
- smartd prints log messages and triggers alert mails when a failure of your drive is predictable.
Within them, we have the
smartctl command that allows us to monitor the operation and health of the system hard disk.
Let’s get started.
Install Smartctl in Ubuntu 20.04
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 comadno 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
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.
It is always a good idea to keep an eye on the health of your hard drive. That’s why today you learned how to install smartctl in Ubuntu 20.04 and use it to know the status of your hard drive.
I hope you liked this post and can continue to help us grow.