5
1
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?
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 – 2015-09-29T09:10:06.050
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 – 2015-09-29T09:13:18.763interesting, hdparm --read-sector ... can read the sector now but the dd command is still failing with io-error. – testo – 2015-09-29T09:16:30.307
2
@doev: You seem to have a different version of
– Deltik – 2015-09-29T09:20:56.937dd
from what I'm familiar with. I've never seendd
output "io-error on writing
" before, and that string doesn't show up anywhere in the GNU coreutils source code.1The correct error message is: "dd: Fehler beim Lesen von »/dev/sda“: Eingabe-/Ausgabefehler" - dd (coreutils) 8.21 – testo – 2015-09-29T09:27:49.193
How can I do the same, but write the data that a successful
--read-sector
gave me? – Evi1M4chine – 2016-09-06T15:17:49.500@Evi1M4chine: Why do you need to do this? The data was read. If your data is valuable, you should be backing up more than just individual sectors. – Deltik – 2016-09-06T15:28:46.273
@Deltik: Because it only reads about every 10th time, and the last time it did, I kept the data, as it may never read again. Why would I not do this? The data is not valuable, but I’m not the type of careless lazy ignorant loser undividual who would just accept it as being unable to do it. It is clearly a useful tool to have for many useful cases. – Evi1M4chine – 2016-09-07T16:16:21.690
@Evi1M4chine: You can take the hex values, convert them into a sector of data, then write them back to the same logical place with
dd if=SECTOR_DUMP of=/dev/YOUR_DISK bs=SECTOR_SIZE seek=ORIGINAL_SECTOR
. – Deltik – 2016-09-07T16:34:08.277@Deltik: Yeah, that’s the thing…They have a weird byte order and when I use some tool like
xxd
to convert them back to binary, and then use a hex editor on them, I get different values. – Evi1M4chine – 2016-09-08T20:03:22.9001@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 – 2016-09-08T20:11:05.133