Bad blocks is the utility in Linux framework which can scan or test our hard disk and external drives for awful sectors. Bad segments or bad blocks is the space of the disk which can’t be utilized because of the lasting harm or OS is not able to get to it.
Badblocks command will distinguish all terrible blocks(bad areas) on our hard disk and spare them in a text file so we can utilize it with e2fsck to configure Operating System to not store our information on these harmed sectors.
First use fdisk command to identify your hard drive info:
sudo fdisk -l
Scan your hard drive for Bad Sectors or Bad Blocks:
sudo badblocks -v /dev/sdb > /tmp/bad-blocks.txt
Don’t forget to replace “/dev/sdb” with your own hard disk / partition. When you execute above command a text file “bad-blocks” will be created under /tmp , which will contains all bad blocks.
Inform OS not to use bad blocks for storing data:
When the scanning is finished , if the bad sectors are reported , then utilize “bad-blocks.txt” with e2fsck command and force OS not to use these bad sectors for storing data.
sudo e2fsck -l /tmp/bad-blocks.txt /dev/sdb