How to check hard drive power on hours in Linux

In this how to check hard drive power on hours in Linux you will see how you might prevent disaster, by knowing details about system’s storage device in terms of “power on” hours (runtime), number of read and writes, or bad blocks, to determine the overall hard drive’s health and ageing.

The most helpful tool for this task is the smartctl command found and made available for installation via smartmontools package on Linux. In this tutorial, we’ll go over a few command examples on how to determine current hard drive’s state and overall health. You’ll also see how to install the smartmontools package on major Linux distros.

In this tutorial you will learn:

  • How to install smartmontools on major Linux distros
  • How to view a hard disk’s power on hours (total runtime)
  • How to check the overall health of a hard disk with smartctl
How to check total running time of a hard disk in Linux
How to check total running time of a hard disk in Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software smartmontools
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Install smartmontools on major Linux distros



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!


To use the smartctl command on Linux, you’ll first need to install the smartmontools software package. You can use the appropriate command below to install the program with your system’s package manager.

To install smartmontools on Ubuntu, Debian, and Linux Mint:

$ sudo apt install smartmontools

To install smartmontools on CentOS, Fedora, AlmaLinux, and Red Hat:

$ sudo dnf install smartmontools

To install smartmontools on Arch Linux and Manjaro:

$ sudo pacman -S smartmontools

After the package is installed, move on to the section below to see how to use the smartctl command.

View hard drive statistics and health

In these examples, we are using /dev/sda as hard disk drive. You can substitute this device file with that of any disk you wish to test.

  1. To view the “power on” hours (the total runtime) of a hard drive, use the following command.
    # smartctl --attributes "${disk}" | grep Power_On_Hours
    Power_On_Hours          0x0032   087   087   000    Old_age   Always       -       12131
    

    In this example, the hard drive has been powered on for 12,131 hours. By omitting the grep portion of this command, you can also find other information such as age of the hard drive.

  2. To check a hard drive’s overall health, we can use the -H option.
    # smartctl -H /dev/sda
    === START OF READ SMART DATA SECTION ===
    SMART overall-health self-assessment test result: PASSED
    
  3. The smartctl command also allows a system administrator to run a self-test to determine the hard drive’s condition. To initiate a health self-test, run the following command using one of the below arguments:
    offline, short, long, conveyance, force, vendor,N, select,M-N, pending,N, afterselect,[on|off]
    


    # smartctl -t short /dev/sda
    Please wait 1 minutes for test to complete.
    
  4. After running the above command the smartctl command will indicate how long you need to wait for test to be finished. The self-test results can be later retrieved by:
    # smartctl -l selftest /dev/sda
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.14.8-200.fc20.x86_64] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF READ SMART DATA SECTION ===
    SMART Self-test log structure revision number 1
    Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
    # 1  Vendor (0x50)       Completed without error       00%      5007         -
    # 2  Offline             Completed without error       00%      5006         -
    
  5. The most comprehensive health status information about your hard drive can be obtained by:
    # smartctl --xall /dev/sda
    

    which will print out general device statistics table and physical event counters table:

    Device Statistics (GP Log 0x04)
    Page Offset Size         Value  Description
      1  =====  =                =  == General Statistics (rev 2) ==
      1  0x008  4             3878  Lifetime Power-On Resets
      1  0x010  4             5007  Power-on Hours
      1  0x018  6      13095790289  Logical Sectors Written
      1  0x020  6        677113980  Number of Write Commands
      1  0x028  6       6489046492  Logical Sectors Read
      1  0x030  6         74059526  Number of Read Commands
      4  =====  =                =  == General Errors Statistics (rev 1) ==
      4  0x008  4                0  Number of Reported Uncorrectable Errors
      4  0x010  4                0  Resets Between Cmd Acceptance and Completion
      6  =====  =                =  == Transport Statistics (rev 1) ==
      6  0x008  4            23933  Number of Hardware Resets
      6  0x010  4            10275  Number of ASR Events
      6  0x018  4                0  Number of Interface CRC Errors
      7  =====  =                =  == Solid State Device Statistics (rev 1) ==
      7  0x008  1                0  Percentage Used Endurance Indicator
    
    SATA Phy Event Counters (GP Log 0x11)
    ID      Size     Value  Description
    0x0001  4            0  Command failed due to ICRC error
    0x0004  4            0  R_ERR response for host-to-device data FIS
    0x0007  4            0  R_ERR response for host-to-device non-data FIS
    0x0008  4            0  Device-to-host non-data FIS retries
    0x0009  4            1  Transition from drive PhyRdy to drive PhyNRdy
    0x000a  4            2  Device-to-host register FISes sent due to a COMRESET
    0x000b  4            0  CRC errors within host-to-device FIS
    0x000d  4            0  Non-CRC errors within host-to-device FIS
    0x000f  4            0  R_ERR response for host-to-device data FIS, CRC
    0x0010  4            0  R_ERR response for host-to-device data FIS, non-CRC
    0x0012  4            0  R_ERR response for host-to-device non-data FIS, CRC
    0x0013  4            0  R_ERR response for host-to-device non-data FIS, non-CRC
    

Closing Thoughts

In this how to check hard drive power on hours tutorial, we learned how to see the power on hours for a hard drive, its age, and overall health. We also saw how to perform different types of tests on hard disks using the smartctl on any major Linux distro. Monitoring the health of your hard drives is an important part of system administration and can help to predict impending failure.



Comments and Discussions
Linux Forum