THE FOLLOWING DISK SECTORS COULD NOT BE READ

Oliver Fromme olli at lurza.secnetix.de
Thu Aug 21 14:05:07 UTC 2008


Marcel Grandemange <> wrote:
 > On a different dilemma, I have a FreeBSD proxy server with what looks like a
 > failing drive.
 > 
 > The drive ONLY holds cache so is not critical for system operation however
 > id still like to try something.
 > 
 > It seem that no matter how many times I run fsck it still comes up with same
 > result, is there a way to isolate the bad sectors and use the replacement
 > ones on drive? Or even just isolate so that I can continue using the drive
 > for now.

The drive's firmware will only remap the bad sectors with
spare sectors when you _write_ to it.

When a read error is encountered while reading a sector,
the drive's firmware will record the sector number, but it
won't remap it yet because it doesn't have any "known good"
contents for that sector.  So it must report the failure to
the OS.

When the sector is written to by the OS, the firmware will
remember that it had a read error, and now it knows the
(new) contents of the sector, so it will make a remapping
entry, use the new sector and report success to the OS.

Therefore, the easiest way to enforce remapping is to first
read the whole disk with dd (so all bad blocks are known to
the firmware), and then write to the whole disk so the
actual remapping will occur:

# dd if=/dev/ad1 of=/dev/null bs=512 conv=sync,noerror
# dd if=/dev/zero of=/dev/ad1 bs=1m

Note that this will take a long time, possibly several
hours, depending on the size of the disk.  You can press
Ctrl-T to see a progress report on the dd(1) command.
Note that "bs=512 conv=sync,noerror" is important for
the first pass, in order to make sure that dd(1) handles
every single sector and continues correctly on errors.

Needless to say, that will ERASE all data on the disk.
You will have to fdisk + bsdlabel + newfs afterwards.

If you have done all of that and you _still_ continue to
get bad sector messages, it most probably means that the
disk drive has run out of spare sectors.  In that case
you should replace the drive immediately.

Remember that disks are pretty cheap these days, and it
might not be worth going through all that hassle in the
first place.  I'd recommend you buy a new drive and
save you some hours of work, a bunch of hairs turning
grey, and some swearing.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"In My Egoistical Opinion, most people's C programs should be indented
six feet downward and covered with dirt."
        -- Blair P. Houghton


More information about the freebsd-questions mailing list