Keeping your disks healthy is the number one method to prevent data loss. The commands below will assist with ensuring this does not happen.
As always, taking backups, or at least having backups available is important to ensure your data is kept secure.
Which tools are available?
You can check for badblocks running the command
$sudo badblocks -nsv /dev/[yourpartision] > badblocks-results.txt
Explanation of the above:
- -n = Use non-destructive read-write mode. By default only a non-destructive read-only test is done.
- -s = Show the progress of the scan by writing out rough percentage
- -v = Verbose mode
- badblocks-results.txt = Will generate a file with the sectors which are damaged.
fsck - file system check
fsck should be used with caution and invoked at system bootup.
smartctl is a command-line tool that "controls the Self-Monitoring, Analysis and Reporting Technology (SMART) system built into most ATA/SATA and SCSI/SAS hard drives and solid-state drives."
You will more than likely need to install
smartctl, as it is not available by default.
sudo apt-get install smartmontools
Once installed you can then run the following commands
# Print drive hearth data, attributes and available tests
$ sudo smartctl -a /dev/sda | less
# To quit less
# Just to print health data
$ sudo smartctl -H /dev/sda
# Start a new short/long term test in the background
$ sudo smartctl -t [short|long]
For more in-depth information into
smartctl, click here.