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

I've been having trouble with a fresh install of Zorin Lite that is probably related to bad sectors on the hard drive (1TB).

Would these tools and techniques be able to allow Zorin to use just the good sectors/blocks of the hard drive? (Maybe that's what you meant with "the non-destructive write test on a bad block should trigger the drive to remap that block" but I'm not sure.)

Trying it now from Zorin Lite live USB.

After changing to the correct letter for my drive ("sda" not "sdf") got the result of 4096. Same for sda1 (the EFI partition) and sda2 (the main partition).

So then I did:
sudo badblocks -b 4096 -svn /dev/sda

Ran for hours, showing ever increasing numbers up to 244190645. Then:

done
Pass completed, 244190646 bad blocks found. (244190646/0/0 errors)

Does that mean every single block is bad???

I would definitely look into getting a hard drive.

This drive isn't shared with windows is it?

1 Like

Well, a 1 terabyte drive is roughly 2147483648 blocks. There may be damage on the tip of the reader armature, rather than the disk itself if this is a spinning hard drive. In which case, it would be unable to read / write even if the disk is good and the blocks are mostly good.
It would read as All Blocks Bad.

2 Likes

Thanks @337harvey & @Aravisian for the feedback. Once I've done some research on replacing HDD and some money comes in, I'll deal with getting a one.