Skip to content

Instantly share code, notes, and snippets.

@adityatelange
Created October 10, 2024 06:41
Show Gist options
  • Save adityatelange/825d134d0d3f5fbd3c6547b52cc3a07a to your computer and use it in GitHub Desktop.
Save adityatelange/825d134d0d3f5fbd3c6547b52cc3a07a to your computer and use it in GitHub Desktop.
How to check entire hard disk for errors and bad sectors
smartctl -t long -d sat /dev/sda
smartctl -t offline -d sat /dev/sda
smartctl -x -d sat /dev/sda

https://unix.stackexchange.com/a/562895


The commands you've provided are related to the smartctl utility, which is part of the Smartmontools package. This utility is used to monitor and control storage devices that support the Self-Monitoring, Analysis, and Reporting Technology (SMART) system. Here's a breakdown of each command:

  1. smartctl -t long -d sat /dev/sda:

    • This command initiates a long self-test on the specified device (/dev/sda). The -t long option specifies that a long test should be performed, which typically takes a significant amount of time and checks the entire surface of the disk for errors. The -d sat option indicates that the device is a SATA drive.
  2. smartctl -t offline -d sat /dev/sda:

    • This command initiates an offline self-test on the specified device. The -t offline option starts a test that runs in the background and does not require the drive to be unmounted. Like the long test, it checks for errors but may not be as thorough as the long test.
  3. smartctl -x -d sat /dev/sda:

    • This command retrieves and displays detailed SMART information about the specified device. The -x option provides an extended output, which includes various attributes, error logs, and test results. This is useful for diagnosing the health and performance of the drive.

Important Notes:

  • Before running these commands, ensure you have the necessary permissions (you may need to run them as root or with sudo).
  • Running tests can impact the performance of the drive, especially if it's in use, so it's advisable to schedule them during maintenance windows or when the system is under low load.
  • After initiating a test, you can check the status and results using the smartctl -a -d sat /dev/sda command to get a comprehensive overview of the drive's health and the results of the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment