Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Check Hard drive for bad sectors or bad blocks in linux  (Read 2088 times)

0 Members and 2 Guests are viewing this topic.

akhilt

  • Guest
Check Hard drive for bad sectors or bad blocks in linux
« on: August 11, 2018, 04:18:33 pm »
Check Hard drive for bad sectors or bad blocks in Linux

badblocks is the command or utility in linux like operating system which can scan or test our hard disk and external drive for bad sectors. Bad sectors or bad blocks is the space of the disk which can’t be used due to the permanent damage or OS is unable to access it.

Badblocks  command will detect all bad blocks(bad sectors)  on our hard disk and save them in a text file so that we can use it with e2fsck to configure  Operating System(OS) to not store our data on these damaged sectors.

Step:1 Use fdisk command to identify your hard drive info

Code: [Select]
# sudo fdisk -l
Step:2  Scan your hard drive for Bad Sectors or Bad Blocks

Code: [Select]
# sudo badblocks -v /dev/sdb > /tmp/bad-blocks.txt
Just replace “/dev/sdb” with your own hard disk / partition. When we execute above command  a text file “bad-blocks” will be created under /tmp , which will contains all bad blocks.

Step:3 Inform OS not to use bad blocks  for storing data

Once the scanning is completed , if the bad sectors are reported , then use file “bad-blocks.txt” with e2fsck command  and force OS not to use these bad blocks for storing data.

Code: [Select]
# sudo e2fsck -l /tmp/bad-blocks.txt  /dev/sdb
Note : Before running e2fsck command , you just make sure the drive is not mounted.

For any futher help on badblocks & e2fsck command , read their man pages

Code: [Select]
# man badblocks
# man e2fsck

Hope this was a useful piece of information, Thank you! 8)