How To: Check your hard drives for errors

Do this while booted into the Zorin OS boot USB.

This should work for any file system. I know it works for exFAT, NTFS and ZFS, as I've used it on drives with those file systems.

To check a drive:

Get the block size:

sudo blockdev --getbsz /dev/sdf <-- The entire drive
sudo blockdev --getbsz /dev/sdf1 <-- The drive's partitions
sudo blockdev --getbsz /dev/sdf2 <-- The drive's partitions

That shows my drive uses 4096 bytes.

Then run badblocks:

sudo badblocks -b 4096 -svn /dev/sdf
... where:
b = block size (badblocks defaults to 1024)
s = show the progress of the scan
v = verbose mode
n = non-destructive read/write mode
/dev/sdf or /dev/sdf3 = drive or partition

As regards the '/dev/sdf' blurb... if all the partitions on the drive use the same block size, then you can just check the entire drive. If the partitions have different block sizes, you have to scan the partitions individually, with the block size of each partition.

Some drives also lie. For instance, I have one drive that mimics 4096 bytes for the entire drive, but each partition is actually 512 bytes block size, so I use 512 bytes when scanning that drive.

That should do it... the non-destructive write test on a bad block should trigger the drive to remap that block. A drive can only remap a bad sector if there is an attempt to write to that sector which fails... the non-destructive write test is what triggers it.

If you want to manually remap a bad block... let's say it finds block 903137 bad. Read from and write to that block only to trigger the drive to mark it bad:

sudo badblocks -w -b 4096 /dev/sdf 903137 903137
... where:
w = destructive write mode
b = block size
/dev/sdf = drive or partition
'903137 903137' = starting and ending blocks

It doesn't matter in this case that you're doing a destructive write to the drive, as you're only writing to the one sector you know to be bad. "Destructive" in this context means it destroys any saved data on that sector... but that sector's bad, that data is already destroyed.

1 Like