What is SmartCTL?
Every modern hard drive has an option to monitor its current status and health via SMART attributes. SMART stands for Self-Monitoring, Analysis, and Reporting Technology. The SMART test can be performed on your HDD to detect any potential problems with the hardware itself. Tests such as these are run using SmartCTL. According to the Linux man page, SmartCTL is a command-line utility designed to perform SMART tasks. Examples of these tasks would be printing error logs or enabling and disabling automatic SMART testing.
So without further ado, let’s dig into the SmartCTL command.
First, let’s check what we need to run the SmartCTL tool and its command on our server.
|Category||Requirements, Conventions or|
Software Version Used
|User Type||Root or user w/ sudo privileges|
|Task Difficulty||Medium (A basic working knowledge |
of the command line is required)
|Other||Internet connection on your server|
*In this article, we used CentOS7, but the installation guide will show you how you can install smartctl on Ubuntu 18.04 as well.
The installation of Smartctl software is pretty straightforward. Let’s review the CentOS 7 installation first.
Step 1. Install
yum install smartmontools
Write the above command into your terminal, yum will check dependencies and available packages. When the installation is complete, you will be prompted with the questions, “is it okay to continue the installation?” Just type “y” and let the installation complete.
============================================================================ Package Arch Version Repository Size ============================================================================ Installing: smartmontools x86_64 1:7.0-2.el7 base 546 k Installing for dependencies: mailx x86_64 12.5-19.el7 base 245 k Transaction Summary ============================================================================ Install 1 Package (+1 Dependent package) Total download size: 791 k Installed size: 2.4 M Is this ok [y/d/N]: y Installed: smartmontools.x86_64 1:7.0-2.el7 Dependency Installed: mailx.x86_64 0:12.5-19.el7 Complete!
Step 2. Enable smartctl
Now that smartctl is installed, let’s start it and make sure that it always starts when the server is rebooted. We can accomplish this by running the following commands.
systemctl enable smartd
This command will make sure that the smartctl daemon is up and running at every system startup. No output will be displayed when you use this command.
systemctl start smartd
This command will start smartctl, and this one also will not provide any output. You can use the “status” flag instead of the start flag to see if the smartctl service is running or not.
The installation of smartctl on Ubuntu is the same as it is on CentOS. There is only one minor detail that is different. The first command that we should run on a Ubuntu OS is this.
Step 1. Install
apt-get install smartmontools
The rest of the process to enable smartctl and the user commands are the same as they are on CentOS.
Smartctl should now be installed. Next, let’s go through some basic usage examples where smartctl comes in handy.
As stated above, smartctl can perform various hard drive tests. We can analyze a faulty drive or perform an ATA/SCSI test based on our HDD type. Generally, tests like these are divided into two types. The ATA/SCSI test and the ATA specified test.
ATA/SCSI tests are divided into two test types: short and long tests. The ATA specified tests are divided into two types of tests: a Conveyance Test and Select Tests. Before running any of these tests, we must make sure that SMART is enabled on our HDD. Here is a command with which we can check to ensure it is enabled.
smartctl -i /dev/vda
Keep in mind that the vda drive type is only used as an example. That is the HDD label on the test server that I used for this article. It will be different in your case, most likely. The easiest way to find out your HDD label is to run the df -h command.
The output of the above command will look like this.
smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-1127.19.1.el7.x86_64] (local build) Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Vendor: QEMU Product: Vz HARDDISK0 Revision: 2.5+ Compliance: SPC-3 User Capacity: 42,949,672,960 bytes [42.9 GB] Logical block size: 512 bytes LU is thin provisioned, LBPRZ=0 Serial number: e603b97ac34343e582bb Device type: disk Local Time is: Tue Oct 6 15:37:02 2020 EEST SMART support is: Available - device has SMART capability. SMART support is: Enabled
The last two lines are the most important as they tell you if the hard drive is capable of running the SMART test. When you see that SMART support is available, but not enabled, you can run this command to enable it.
smartctl -s on -o on -S on /dev/vda
The output of the command above will look like this.
=== START OF ENABLE/DISABLE COMMANDS SECTION === SMART Enabled. SMART Attribute Autosave Enabled. SMART Automatic Offline Testing Enabled every four hours.
Now that we are sure SMART is available and enabled on our device, let’s check some examples of smartctl commands. We will review how to use them and their purpose.
We want to point out one thing before we check some common examples of smartctl commands. Each test that you can perform can run in two modes: a background and a foreground mode. When you run them in the background, priority on the test is low, and all the operations on the server will generally run as expected.
If the HDD suddenly gets busy and I/O goes sky-high, the test will be paused until things return to normal. The Foreground mode will not lower the tests' priority, and no matter what happens, tests will continue to run. The foreground mode is only recommended for use when HDD is not being used by anything else.
Now that we cleared that out of the way, let’s check commands.
If you want to disable SMART capabilities on your hard drive, you can use this:
smartctl -s off /dev/vda
Check Drive Health
To display the overall health of your hard drive, you can use this one:
smartctl -H /dev/vda
Our output will look like this:
smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-1127.19.1.el7.x86_64] (local build) Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org === START OF READ SMART DATA SECTION === SMART Health Status: OK
Verify Test Mode
If you want to make sure that drive is capable of running tests on its own, you can use this one:
smartctl -H /dev/vda
Run Long/Short Test
When you want to run a short or long test on your HDD, you can use these two commands:
smartctl –test=short /dev/vda smartctl –test=long /dev/vda
For any of the tests to run in the background, you can use -t flag:
smartctl -t short /dev/vda smartctl -t long /dev/vda smartctl -t conveyance /dev/vda smartctl -t select /dev/vda
For the Foreground mode, the "-C" flag has to be added. Remember, run this only if the hard drive is not used by anything else!
smartctl -t short -C /dev/vda smartctl -t long -C /dev/vda smartctl -t conveyance -C /dev/vda smartctl -t select -C /dev/vda
View Full Results
Let’s check how we can view the results of our tests.
smartctl -a /dev/vda
Here is an example of the output that you will get, just a part of it because the whole output will be quite lengthy.
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
View Limited Results
If you need a shorter output that will display just the results of the test, you can use this command.
smartctl -l selftest /dev/vda
When you are aware of your hard drive's errors, and you want to display them, use this command.
smartctl -l error /dev/sdb
In the end, we hope that this article served as an introduction to this useful utility and that you will explore it on your own. In this article, we covered the very basics of the smartctl commands. If further information is needed, the smartctl man page can provide additional knowledge about this utility and all the available flags. We can type man smartd into our terminal to open the man pages for smartctl.
Want More Information?
We pride ourselves on being The Most Helpful Humans In Hosting™!
Our experienced Hosting Solutions advisors are always available to show you how you can take advantage of these techniques today!
We are available 24 hours a day, 7 days a week 365 days a year, via our ticketing systems at email@example.com, by phone (at 800-580-4986) or via a LiveChat or whatever method you prefer.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.