Check hard disk for Bad Sectors by command-line in Ubuntu, Linux Mint, and elementary OS

scan bad sectors in hard disk

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 an hard disk drive. Bad sectors is 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 presence of bad sectors and errors in your computer’s hard disk. We had already published GUI method of finding SMART status and errors using ‘Disks’ utility – just FYI.

 

Scan for Bad Sectors and Errors on 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 a 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 fdisk command to find out the hard disk partitions status.

sudo fdisk -l
fdisk command output
fdisk command output

You should see 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 in 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 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

Hi there! I’m Kiran Kumar, founder of FOSSLinux.com. I’m an avid Linux lover, and enjoys hands-on with new promising distros. Currently, I’m using Linux Mint as a daily driver and run several other distros such as Fedora, Solus, Ubuntu, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities especially during Winter ;). When I’m not writing for FOSSLinux, I’m seen biking and hiking on scenic trails. Hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more, and spread my love for Linux. If you find time, drop me an email or feedback from ‘Contact’ page. Or simply leave a comment below if you found this article useful. Have a good day!

Leave a Reply

1 Comment on "Check hard disk for Bad Sectors by command-line in Ubuntu, Linux Mint, and elementary OS"

Notify of
avatar
Sort by:   newest | oldest | most voted
mellatweb
Guest

Thank you update your site

wpDiscuz