07.05.2019 15:27

Finding a file the bad sector belongs to

If you start to have those unpleasant errors from ata kernel driver you may consider finding out what is wrong. Here is a brief howto find where the bad sector is used. Beware that most disks today have 4096B sectors while they report 512 sector number.

 Log messages

May  7 15:17:32 m kernel: ata1.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out
May 7 15:17:32 m kernel: ata1.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out
May 7 15:17:32 m kernel: ata1.00: configured for UDMA/133
May 7 15:17:32 m kernel: sd 0:0:0:0: [sda] tag#11 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
May 7 15:17:32 m kernel: sd 0:0:0:0: [sda] tag#11 Sense Key : Medium Error [current]
May 7 15:17:32 m kernel: sd 0:0:0:0: [sda] tag#11 Add. Sense: Unrecovered read error - auto reallocate failed
May 7 15:17:32 m kernel: sd 0:0:0:0: [sda] tag#11 CDB: Read(10) 28 00 0b 81 41 58 00 00 08 00
May 7 15:17:32 m kernel: print_req_error: I/O error, dev sda, sector 193020252 flags 0
May 7 15:17:32 m kernel: Buffer I/O error on dev sda, logical block 24127531, async page read
May 7 15:17:32 m kernel: ata1: EH complete

Howto find it

193020252
fdisk -l
/dev/sda5 62918656 398 462 975 335544320 160G 83 Linux

130101596 * (512/4096) = 16262699

# debugfs /dev/sda5
debugfs 1.44.6 (5-Mar-2019)
debugfs: icheck 16262699
Block Inode number
16262699 553176
debugfs: ncheck 553176
Inode Pathname
553176 /covex/.mozilla/firefox/4qqff0n0.default/favicons.sqlite


1033 hdparm --yes-i-know-what-i-am-doing --write-sector 193020252 /dev/sda
1038 hdparm --yes-i-know-what-i-am-doing --write-sector 193020253 /dev/sda
1045 hdparm --yes-i-know-what-i-am-doing --write-sector 193020254 /dev/sda
1055 hdparm --yes-i-know-what-i-am-doing --write-sector 193020255 /dev/sda

now dd like

dd if=/dev/sda of=/dev/null bs=512 count=1 skip=193020255

should finally succeed.

Email comment