[Linux] Check disk integrity

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
gilthanaz
Site Admin
Posts: 444
Joined: Fri Aug 29, 2003 9:29 pm
Contact:

[Linux] Check disk integrity

Post by gilthanaz »

Use badblocks to do a full disk check (each sector):



Non-destructive method:

Code: Select all

# badblocks -vs /dev/hda
Checking for bad blocks in read-only mode
Arguments:
  • -v: verbose
  • -s: show progress in rough percentage

DESTRUCTIVE METHOD:

Code: Select all

# badblocks -ws /dev/hda
Tests each block by first writing in, than reading from it. Do not use this on an existing filesystem, it WILL DESTROY all data!
Arguments:
  • -w: write-mode test
  • -s: show progress in rough percentage
If you want also a write test on an existing filesystem without destruction of data, use the -n option. Its way slower that way, but keeps the data intact.
Last edited by ^rooker on Sun Dec 29, 2013 1:59 am, edited 1 time in total.
Reason: Added infos about used badblocks arguments.
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

store badblocks in textfile

Post by ^rooker »

Other useful options for badblocks are the ability to store/read a list of bad blocks in/from a file.

1) Store list of bad blocks in file:
Run badblocks and store the list of broken blocks in a file:

Code: Select all

badblocks -o bad_list.txt -vs /dev/hda
2) Speed up scanning for bad blocks:
If you run badblocks again, you might want to skip testing blocks you already know to be broken:

Code: Select all

badblocks -i bad_list.txt -vs /dev/hda
3) Format partition and mark bad blocks:
If you have bad blocks, you might want to tell the format tool about them.
Example for ext3:

Code: Select all

mkfs.ext3 -l bad_list.txt /dev/hda
Example for fat32 (=vfat):

Code: Select all

mkfs.vfat -l bad_list.txt /dev/hda
4) Compare different runs:
If you run badblocks on the same device in the future, you can compare the list with previous runs to see if the number of bad blocks is increasing (which usually means that your harddisk is about to die)
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply