Check Hard drive for bad sectors or bad blocks in Linux

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

 

 

2 thoughts on “Check Hard drive for bad sectors or bad blocks in Linux

  1. doesn’t works.
    we need to pass correct hdd block-size to badblocks.

    1. get the hdd block size
    dumpe2fs -h /dev/sdb1 | grep -ie “Block size:”
    e.g. 4096

    2. pass this value to badblocks (avoiding the default 1024)
    badblocks -v -b 4096 /dev/sdb > /tmp/bad-blocks.txt

    3. run fsck for the PARTITION
    e2fsck -l /tmp/bad-blocks.txt /dev/sdb1

Leave a Reply

Your email address will not be published. Required fields are marked *