Haw to use smartctl command.

What is smartctl command:

The smartctl command in Linux is a tool that allows you to monitor and control SMART (Self-Monitoring, Analysis, and Reporting Technology) enabled devices such as hard disk drives, solid-state drives, and some USB/eSATA hard disk enclosures. SMART is a system built into hard drives, SSDs, and other storage devices that monitors the health of the drive and can alert you to potential problems.

Common uses of the smartctl command:

  • Checking Drive Health: You can use smartctl to check the overall health of a storage device, view its SMART attributes, and assess its overall condition.

  • Testing: The tool allows you to perform different types of tests on the drive, such as short or long self-tests, to check for potential issues.

  • Error Logging: smartctl can display the error log maintained by the drive, which can provide insight into past issues and errors.

  • Temperature Monitoring: It can also display the current temperature of the drive, helping you monitor its operating conditions.

  • Control Features: Some advanced features of the tool allow you to modify certain parameters of the drive, though this should be done with caution.

Prerequisites

Before you jump into smartctl, a fundamental grasp of Linux terminal interactions and command functions is essential. Knowledge of file system setups and data storage devices can be quite helpful. Moreover, you need root or sudo privileges on the system where you intend to install and operate smartctl, as most of its features demand escalated rights.

Installation

  1. Ubuntu/Debian:

    • Update the system packages by running the command: sudo apt update.

    • Install smartmontools package by running the command: sudo apt install smartmontools.

    • Verify that smartctl is installed by running the command: smartctl --version.

  2. CentOS/RHEL:

    • Update the system packages by running the command: sudo yum update.

    • Install smartmontools package by running the command: sudo yum install smartmontools.

    • Start the service of smartctl by running the command: sudo systemctl start smartd.

    • Verify that smartctl is installed by running the command: smartctl --version.

  3. Fedora:

    • Update the system packages by running the command: sudo dnf update.

    • Install smartmontools package by running the command: sudo dnf install smartmontools.

    • Start the service of smartctl by running the command: sudo systemctl start smartd.

    • Verify that smartctl is installed by running the command: smartctl --version.

Usage

The smartctl tool designed to perform SMART tasks. You can use it to print the SMART self-test and error logs, enable and disable SMART automatic testing, and initiate device self-tests. To use smartctl, you’ll first need to open a terminal.

The general syntax for the smartctl command is as follows:

smartctl [options] device

Here, options refers to the various commands and parameters you can pass to the smartctl, and device refers to the hard drive or SSD you want to examine. Here are some key options you might use:

Short Option

Long Option

Description

-i

–info

This option displays hard drive information.

-t

–test

This option runs a self-test on the hard drive.

-x

–xall

This option displays extended comprehensive SMART information.

-a

–-all

This option displays all SMART information for a hard drive.

-H

–health

This option summarizes the hard drive’s health.

Remember to replace dev/sda with the path of your own device. If you’re not sure what your device’s path is, you can use the commands df -h and lsblk:

df -h

[root@host ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        2.9G     0  2.9G   0% /dev
tmpfs           2.9G     0  2.9G   0% /dev/shm
tmpfs           2.9G  305M  2.6G  11% /run
tmpfs           2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/vda1        23G   11G   11G  51% /
tmpfs           581M     0  581M   0% /run/user/0

lsblk

[root@host ~]# lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    253:0    0  25G  0 disk
├─vda1 253:1    0  23G  0 part /
└─vda2 253:2    0   2G  0 part [SWAP]

Disable smartctl

This command would turn off the automatic offline data collection for the specified hard drive. If you want to disable SMART capabilities on your hard drive, you can use this command:

smartctl -o off device

This might be used if you believe the testing is causing performance issues or otherwise interfering with normal operation.

Check drive health

This command checks the health status of the specified hard drive. If the drive is healthy according to its SMART self-tests, it will report that the health check passed. If there are problems, it will indicate that the health check failed, and you check the details to understand the problem.

smartctl -H device

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. It will show you what SMART can do on the specified hard drive, giving you an idea of what kinds of health checks and error checks you can do with it:

smartctl -c device

Run long/short test

When you want to run a short or long test on your HDD, you can use these two commands. The first one, the short device command starts a short test. It’ll take a few minutes to complete and check only major components:

smartctl short device

The second one, the long device command initiates an extensive test that will require a significant amount of time to complete, but it will comprehensively scan all elements.

It’s also recommended to use background testing with tests; please continue reading the background testing section for more information:

smartctl long device

Background testing

For any of the tests to run in the background, you can use -t flag. In smartctl, the -t flag allows you to initiate self-tests on your storage device that run in the background. Background testing lets you continue using the system while the test is ongoing. So, it’s recommended to use one of the following commands:

smartctl -t short device
smartctl -t long device
smartctl -t conveyance device
smartctl -t select device

Running these tests in the background is particularly useful for long tests, allowing uninterrupted system use during the testing period.

To check the test progress or results, use the below command:

smartctl -l selftest device

Foreground Testing

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 device
smartctl -t long -C device
smartctl -t conveyance -C device
smartctl -t select -C device

The -C option, also known as –captive, is used with the -t option to run the short, long, selective, or conveyance self-tests in a mode known as captive or foreground mode. This mode is unique because it commands the drive to conduct the test immediately and continuously, monopolizing the hard drive’s resources for the test duration.

It can be helpful in certain situations where you want to get the test results as quickly as possible and if you’re okay with the hard drive being temporarily unavailable for other tasks. Foreground tests often complete faster than background tests because other tasks do not slow down the hard drive.

View full results

Let’s check how we can view the results of our tests:

smartctl -a device

This command prints a comprehensive SMART report, including the device model, serial number, firmware version, SMART attributes, error log, self-test log, and more. 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:

sudo smartctl -A device

This displays a table of the hard drive’s SMART attributes, including their raw and normalized values and details, such as the worst value recorded and the threshold value for each attribute. This information can help you assess the health of the hard drive and identify potential issues.

When you are aware of your hard drive’s errors, and you want to display them, use this command:

smartctl -l error device

Conclusion

This guide has offered an in-depth look at installing and using a powerful tool, smartctl, including various example commands. Whether running a basic health check, enabling or disabling SMART features, or performing comprehensive self-tests, smartctl offers you the options you need. Remember, it’s essential to regularly check the health of your driver and act swiftly, or contact your hosting provider, if you notice any sign of failure.

Leave A Comment

What’s happening in your mind about this post !

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