smartctl Command in Linux



The smartctl command is a powerful tool that comes with the smartmontools package, designed to interact with and manage the Self-Monitoring, Analysis, and Reporting Technology (SMART) system of your hard drives and solid-state drives.

SMART technology enables drives to monitor their own health, predict potential failures, and report any problems. Let's dive into the detailed explanation of the smartctl command along with various examples.

Table of Contents

Here is a comprehensive guide to the options available with the smartctl command −

Understanding the smartctl Command

Before using the smartctl command, you need to install the smartmontools package. The installation commands vary depending on your Linux distribution −

Debian / Ubuntu

sudo apt-get install smartmontools

Red Hat / Fedora

sudo yum install smartmontools

Arch Linux

sudo pacman -S smartmontools

OpenSUSE

sudo zypper install smartmontools

Syntax of smartctl Command

The basic syntax of the smartctl command is as follows −

sudo smartctl [options] [device]

Here, [options] refers to the various command-line options you can use with smartctl, and [device] refers to the specific storage device you want to interact with (e.g., /dev/sda).

smartctl Command Options

Let's explore some commonly used options with smartctl

Check Overall Health Status

sudo smartctl -H /dev/sda
smartctl Command in Linux1

This command checks and reports the overall health status of the specified device. It returns "PASSED" if the device is healthy.

Retrieve Detailed SMART Information

sudo smartctl -a /dev/sda
smartctl Command in Linux2

This command retrieves and displays detailed SMART information, including health status, SMART attributes, error logs, and more.

Enable SMART on a Device

sudo smartctl -s on /dev/sda
smartctl Command in Linux3

This command enables SMART monitoring and data collection on the specified device.

Disable SMART on a Device

sudo smartctl -s off /dev/sda
smartctl Command in Linux4

This command disables SMART monitoring and data collection on the specified device.

Display SMART Capabilities

sudo smartctl -c /dev/sda
smartctl Command in Linux5

This command displays the SMART capabilities and settings of the specified device.

Run a Short Self-Test

sudo smartctl -t short /dev/sda
smartctl Command in Linux6

This command initiates a short self-test on the specified device. Short self-tests typically take a few minutes to complete.

Run a Long Self-Test

sudo smartctl -t long /dev/sda
smartctl Command in Linux7

This command initiates a long self-test on the specified device. Long self-tests can take several hours to complete.

Display Self-Test Results

sudo smartctl -l selftest /dev/sda
smartctl Command in Linux8

This command displays the results of previously run self-tests on the specified device.

Examples of smartctl Command in Linux

  • Checking Overall Health Status
  • Enabling SMART on a Device
  • Retrieving Detailed SMART Information
  • Running a Short Self-Test
  • Running a Long Self-Test
  • Displaying Self-Test Results
  • Displaying SMART Attributes
  • Displaying Error Logs
  • Checking SMART Capabilities
  • Displaying Device Information
  • Saving SMART Data to a File

Checking Overall Health Status

To check the overall health status of the device /dev/sda, you can use the -H option −

sudo smartctl -H /dev/sda
smartctl Command in Linux9

This command will output a health status message, such as "PASSED" if the device is healthy or "FAILED" if there are issues. This is a quick way to determine the general condition of your drive.

Enabling SMART on a Device

Before you can use other smartctl commands, you need to ensure that SMART is enabled on the device. You can enable SMART using the -s on option −

sudo smartctl -s on /dev/sda
smartctl Command in Linux10

This command enables SMART monitoring and data collection, allowing you to access detailed health information and perform tests on the device.

Retrieving Detailed SMART Information

To get a comprehensive view of the SMART data for a device, you can use the -a option −

sudo smartctl -a /dev/sda

This command provides detailed information about the device, including −

  • Overall health status
  • SMART attributes (e.g., read error rate, temperature)
  • Error logs
  • Self-test logs

The output can help you diagnose and monitor the health of your drive.

Running a Short Self-Test

A short self-test is a quick diagnostic test that checks for issues without performing an exhaustive scan. You can initiate a short self-test using the -t short option −

sudo smartctl -t short /dev/sda
smartctl Command in Linux11

This command starts a short self-test, which typically completes in a few minutes. You can monitor the progress and results using the -a option −

sudo smartctl -a /dev/sda
smartctl Command in Linux12

Look for the "Self-test execution status" section in the output to see the test progress and results.

Running a Long Self-Test

A long self-test performs a thorough scan of the entire device, checking for potential issues. You can start a long self-test using the -t long option −

sudo smartctl -t long /dev/sda
smartctl Command in Linux13

Long self-tests can take several hours to complete, depending on the size and speed of the drive. You can monitor the progress and results using the -a option −

sudo smartctl -a /dev/sda
smartctl Command in Linux14

Look for the "Self-test execution status" section in the output to see the test progress and results.

Displaying Self-Test Results

To view the results of previously run self-tests, you can use the -l selftest option −

sudo smartctl -l selftest /dev/sda
smartctl Command in Linux15

This command displays a log of self-tests, including the test type, status, and any errors detected during the tests. Reviewing self-test logs can help you identify recurring issues and track the health of your drive over time.

Displaying SMART Attributes

SMART attributes are key metrics that provide insight into the health and performance of your drive. To display SMART attributes, you can use the -A option −

sudo smartctl -A /dev/sda
smartctl Command in Linux16

This command outputs a table of SMART attributes, including −

  • ID − Attribute ID number
  • ATTRIBUTE_NAME − Name of the attribute
  • VALUE − Current normalized value
  • WORST − Worst normalized value recorded
  • THRESH − Threshold value
  • TYPE − Attribute type (e.g., Pre-fail, Old_age)
  • UPDATED − Frequency of attribute updates
  • WHEN_FAILED − Status indicating if the attribute has failed
  • RAW_VALUE − Raw data value

Each SMART attribute provides valuable information about the drive's health. For example, the "Reallocated_Sector_Ct" attribute indicates the number of bad sectors that have been reallocated.

Displaying Error Logs

Error logs contain records of errors encountered by the drive. To display error logs, you can use the -l error option −

sudo smartctl -l error /dev/sda

This command outputs a list of recent errors, including details about each error such as the error number, time, and description. Analyzing error logs can help you identify and troubleshoot issues with your drive.

Checking SMART Capabilities

To check the SMART capabilities and settings of a device, you can use the -c option −

sudo smartctl -c /dev/sda

Understanding the SMART capabilities of your drive can help you make informed decisions about monitoring and maintenance.

Displaying Device Information

To display detailed information about the device, including model number, serial number, and firmware version, you can use the -i option −

sudo smartctl -i /dev/sda

This command outputs device identification information, which can be useful for inventory and documentation purposes.

Saving SMART Data to a File

To save the SMART data to a file for later analysis, you can use the -x option along with redirection −

sudo smartctl -x /dev/sda > smart_data.txt

This command saves the detailed SMART data to the smart_data.txt file, allowing you to review and analyze it later.

Conclusion

The smartctl command allows you to retrieve detailed information about your drives, perform tests, and configure SMART features. It provides information about the device's SMART support, including: whether SMART is supported and enabled, available SMART features (e.g., self-tests, error logging), threshold values for various attributes

Advertisements