Monday, September 8, 2008

Checking File Systems using badblocks

In Linux, instead of just having the scandisk utility you have in Windows, you can scan a physical device for bad blocks at a physical level with the badblocks command and scan a file system for errors at the logical level with the fsck command. Here’s how to scan for bad blocks:

$ sudo badblocks /dev/sda1 Physically scan hard disk for bad blocks
$ sudo badblocks -v /dev/sda1 Add verbosity to hard disk scan
Checking blocks 0 to 200781
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found.

By default, badblock does a safe read-only test of the blocks. You can also perform a
non-destructive read/write test. This is the slowest test, but the best one you can per-
form without destroying the data on the device. Add -s to see the ongoing progress:

$ sudo badblocks -vsn /dev/sda1 Check bad blocks, non-destructive
Checking for bad blocks in non-destructive read-write mode
From block 0 to 200781
Testing with random pattern: Pass completed, 0 bad blocks found.

The following command performs a faster, destructive read-write test:

WARNING! This will erase all the data on the partition.

$ sudo badblocks -vsw /dev/sda1 Check bad blocks, destructive
Checking for bad blocks in read-write mode
From block 0 to 200781
Testing with pattern 0xaa: done
Reading and comparing: done
Testing with pattern 0x55: done
Reading and comparing: done
Testing with pattern 0xff: done
Reading and comparing: done
Testing with pattern 0x00: done
Reading and comparing: done
Pass completed, 0 bad blocks found.

You can perform multiple badblocks passes; for example, this command line can be used to
burn in a drive and screen for hard drive infant mortality:

$ sudo badblocks -vswp 2 /dev/sda1

No comments:

Post a Comment