8

I try to reallocate a bad sector. After reading this Question my understanding is, that the hard-drive tries to reallocate automatically. To trigger the process I tried to write to the sector with dd but nothing changed at all.

$ smartctl -a /dev/sda
...
5 Reallocated_Sector_Ct   ...       0
197 Current_Pending_Sector  ...       1
...

The bad sector is: 215040

$ dd if=/dev/sda of=/dev/null bs=512 count=1 skip=215040
io-error on reading

Why is the sector not allocated when I write to it?

$ dd if=/dev/zero of=/dev/sda bs=512 count=1 seek=215040
io-error on writing

How can I cause the sector to be rewritten?

1 Answer 1

9

Try a low-level write using hdparm:

sudo hdparm --yes-i-know-what-i-am-doing --write-sector 215040 /dev/sda

… where 215040 is the sector number you want to overwrite (and possibly remap) and /dev/sda is the device to which you want to write.

From the hdparm man page:

--write-sector

Writes zeros to the specified sector number. VERY DANGEROUS. The sector number must be given (base10) after this flag. hdparm will issue a low-level write (completely bypassing the usual block layer read/write mechanisms) to the specified sector. This can be used to force a drive to repair a bad sector (media error).

12
  • Hi. I was currently editing my question. You solution works fine. I think (I can't test it anymore) the problem with my dd command was the sector size of 512 which is logical. The physical size is 4096.
    – testo
    Sep 29, 2015 at 9:10
  • 1
    @doev: Most drives emulate 512-byte sectors regardless of the physical sector size. You can confirm the sector size (in bytes) that the operating system sees using this command: cat /sys/block/sda/queue/hw_sector_size
    – Deltik
    Sep 29, 2015 at 9:13
  • 2
    @doev: You seem to have a different version of dd from what I'm familiar with. I've never seen dd output "io-error on writing" before, and that string doesn't show up anywhere in the GNU coreutils source code.
    – Deltik
    Sep 29, 2015 at 9:20
  • 1
    The correct error message is: "dd: Fehler beim Lesen von »/dev/sda“: Eingabe-/Ausgabefehler" - dd (coreutils) 8.21
    – testo
    Sep 29, 2015 at 9:27
  • 1
    @Evi1M4chine: This command turns the hdparm sector output to binary: sudo hdparm --read-sector SECTOR /dev/YOUR_DISK | grep -Eo '([0-9a-f]{4} ){7}[0-9a-f]{4}' | xxd -r -p
    – Deltik
    Sep 8, 2016 at 20:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .