Category: badblocks

Check for bad blocks on a drive with Linux

Sometimes I find here and there some hard disks and this is how I check if they are healthy and bad blocks free.

First I see where the disk is mapped

sudo lshw -c disk

a typical output is like this

  *-disk                  
       description: ATA Disk
       product: IC35L060AVER07-0
       vendor: Hitachi
       physical id: 0.0.0
       bus info: scsi@0:0.0.0
       logical name: /dev/sda
       version: ER6O
       serial: SZPTZTE1022
       size: 57GiB (61GB)
       configuration: ansiversion=5

 

The disk is a Hitachi IC35L060AVER07-0 corresponding to /dev/sda

The command to check for bad blocks is literally “badblocks” and I use it as follow

sudo badblocks -o badblocks_list -s -v -w /dev/sda

where
-o <output_file>

Write the list of bad blocks to the specified file, without this option, badblocks displays the list on its standard output.

-s

Show the progress of the scan by writing out rough percentage completion of the current bad‐blocks pass over the disk

-v

Verbose mode

-w

Use write-mode test. With this option, badblocks scans for bad blocks by writing the patterns 0xaa, 0x55, 0xff, 0x00 on every block of the device, reading every block and  comparing  the  contents.

Badblocks will sequentially write and read back each of the four patterns 0xAA, 0x55, 0xFF, 0x00 and eventually reports on <output_file> which block is bad.

Errors are reported inside brackets and must be interpreted as (read/write/corruption errors). Be careful because this will take lot of time, with a 500GB disk it took around 7 hours. If eventually  you want to speed up the process you might use the switch -t and pass just one pattern:

sudo badblocks -o badblocks_list -s -v -w -t 0xAA  /dev/sda

this will not be reliable but could be enough just to see if the disk is seriously damaged or not. Another useful option is -p <num_passes> where badblocks will repeat scanning the disk until there are no new blocks discovered in  <num_passes>  consecutive scans of the disk. Default is 0, meaning badblocks will exit after the first pass.

If you run and get the message “sda is apparently in use by the system; it’s not safe to run badblocks!“, check if there is any partition mounted with a simple

mount

At the end if no bad blocks are found:

Checking for bad blocks in read-write mode
 From block 0 to 60051599
 Testing with pattern 0xaa: done
 Reading and comparing: done
 Pass completed, 0 bad blocks found.

WordPress Themes