Intro

When a disk gets older, there may be some bad sectors on it. In fact every disk has bad sectors. They are just marked as bad and not used by the disk. Every disk has spare sectors to use if some will fail and the disk will remap the corrupted parts to the good ones as soon as we try to write to a bad sector. So this is how we can trigger the remap by hand.

Even if this fix works, consider replacing the failing disk. It may still be ok for a long time bud then suddendly fail in a moment of Murphy’s law. If the disk is brand new, send it back for a warranty replacement.

My code snippets are not new and I found them on dekoder.wordpress.com

BACKUP - Allways have one

If you don’t have… Create one as long as the problem does not hit you by removing a disk from the array. ZFS ensures correct data as long as you have some redundancies left!

Really, do a backup!

Do you have a backup? Create one! Don’t ask, just do it!

Here are the steps

Locate the start LBA value of the bad area

smartctl -t long /dev/ada2
smartctl -a /dev/ada2

Look for the sector that failed. The line should look like 1 Extended offline Completed: read failure 90% 25166 892134344.

Set debugmode to overwrite the sectors

sysctl kern.geom.debugflags=16

Overrite some sectors

I usually overwrite not just one sector because in my cases I allways had multiple corrupted sectors near the same position! Again: Backup your data!!!

dd if=/dev/zero of=/dev/ada2 bs=512 count=10000 seek=<startsector> conv=noerror,sync

set mode back to original

sysctl kern.geom.debugflags=0

start a scrub to restore the data

zpool scrub poolname
zpool status -v poolname