Tuesday 10 November 2015

Checking for bad sectors with badblocks and fsck

Badblocks in a linux utility that scan storage media for bad blocks.

It can be operated in serveral modes:

- Destructive mode: Where block data will be wiped, as each sector is overwritten by random data and read. This mode is potentially very dangerous and should typically be only applied on disks that are brand new or you are not worried about losing the data on them!

- Non-destructive mode: Where block data is checked, although rather than overwriting the original block data (effectively wiping it) the block data is firstly backed up. This mode is useful if you have data on the disks you are testing which you don't want to lose! - Although takes slightly longer than the destructive mode.


To perform a DESTRUCTIVE block data test we can issue the following:
badblocks -wsv -t random /dev/<device>

We can perform a NON-DESTRUCTIVE test with the following:
badblocks -nsv /dev/<device>
(where the 'n' indicates it's a non-destructive test)

We can also tell our filesystem not to include any badblocks with the fsck utility:
fsck -vcck /dev/<device-PARTITION>
This command ends up calling 'badblocks' although will perform a non-destructive test as we have included the '-cc' option.


Post a Comment