Unable to Write Zeros to Bad Sectors/Hard Disk Not Counting Reallocated Sectors

Solution 1:

The WD15EARS drive (and most other recently produced drives) uses Advanced Format, which means that the real physical sector size of this drive is 4 KiB, and the traditional 512-byte sector size is just emulated. Because of this, if a single 4 KiB physical sector goes bad, all 8 corresponding emulated 512-byte sectors become unreadable at once.

(The Sector Size: 512 bytes logical/physical output from smartctl is not correct, because some WD15EARS drives report wrong physical sector size — apparently your drive has a firmware version which is broken in that respect.)

Moreover, when a single emulated 512-byte sector is written, the Advanced Format drive actually needs to read the whole 4 KiB physical sector, change the corresponding 512-byte part of it, then write the whole physical sector to the media. If the media is good, this read-modify-write operation just causes a significant slowdown compared to a drive with real 512-byte physical sectors. However, if the 4 KiB physical sector is bad and cannot be read, any write operation which does not rewrite the sector completely will fail. Because of this, you cannot force sector reallocation on such drives using dd with bs=512 count=1 — you must use at least bs=512 count=8 and make sure that the sector number in the seek= option is a multiple of 8. (This assumes that the “Windows XP Compatible” jumper is not installed, otherwise the alignment offset added by this jumper must also be taken into account.)

Another reason why forcing the reallocation with dd might fail is that by default Linux uses a cache in the block layer to access block devices, and this may cause read-modify-write operations in software, which would also fail when an unreadable sector is encountered. You can add the oflag=direct option to bypass this cache for the device specified by of=... (there is also the iflag=direct option, which applies to the input device).