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 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
fdisk command output
fdisk command output

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
Previous articleHow to install Antergos 2016 in your PC
Next articleVidCutter – Free video cutting app for Ubuntu, Linux Mint, and elementary OS
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 Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, 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 Linux love!. 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!

7
Leave a Reply

avatar
5 Comment threads
2 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
6 Comment authors
AliIngoRajarshi PaulKiran Kumarparity n Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
mellatweb
Guest
mellatweb

Thank you update your site

parity n
Guest
parity n

how long did it take to scan your 465.8 GB drive? i.e.run step 2 from start to finish.

I started it on a 1.5Tb external drive and it ran for over 30 minutes (without any clue how long was left), so killed it. Can we run it with the ‘-s’ option (to show progress bar)?, if so, does it give a good indication of progress?

Rajarshi Paul
Guest
Rajarshi Paul

Hello Sir,
I cannot access my hard drive partitions on my Ubuntu OS. I have a 500Gb Hard disk size which is not accessible or rather even visible with the Ubuntu OS. Any suggestions?

Ingo
Guest
Ingo

sudo fsck -l < /scan_result/badsectors.txt /dev/sda

Ali
Guest
Ali

Dear Kiran, Thank you for this article. it’s really helpful. there’s only one problem (maybe 2) . When I run the fsck command, I receive the following error messages:
fsck: the -l option can be used with one device only — ignore
e2fsck: need terminal for interactive repairs
any idea what can be done about them?