Hard disk failures are just a thing that’s bound to happen to every computer. But, time of complete failure is something that you should estimate based on the scan results. Presence of bad sectors is the beginning of the end of a hard disk drive. Bad sectors are hardware related and can’t be fixed. You can only monitor it and make your OS to not use the bad sectors for writing data.
In this session of Terminal Tuts, let’s learn how to find out the presence of bad sectors and errors in your computer’s hard disk. We had already published the GUI method of finding SMART status and errors using ‘Disks’ utility – just FYI.
Scan for Bad Sectors and Errors on the hard disk in Ubuntu, Linux Mint, and elementary OS
Note that if you want to scan your computer’s internal hard disk which is mounted, you should be using an Ubuntu Live USB drive and boot into it. Then launch ‘Terminal’ from the Live environment and follow these steps. If you are checking an external hard disk, you need to see that it is not mounted.
Step 1: First, let’s use the fdisk command to find out the hard disk partitions status.
sudo fdisk -l
You should see a few entries of RAM. For example, Disk /dev/ram15 seen in my test PC. You can ignore it as this is the RAM disk driver used by main system memory as a block device.
In the above screen-shot example, /dev/sda is the hard disk of size 465.8 GB that I’m interested in scanning.
Step 2: Next, let’s find if there are any Bad Sectors on the hard disk. We shall use badblocks command. Make sure to enter your hard disk info instead of /dev/sda in below command. My test PC has /dev/sda for the hard disk. This command will scan for bad blocks in the hard disk and then export the result to the file badsectors.txt in the ‘scan_result’ directory.
sudo badblocks -v /dev/sda > /scan_result/badsectors.txt
Step 3: Finally we shall use fsck command to tell Ubuntu not to use the bad sectors mentioned in the badsectors.txt file. That way life of the hard disk is increased a bit until you get a new one for replacement.
sudo fsck -l /scan_result/badsectors.txt /dev/sda