0

I have a drive where I want to copy data from but cp fails every time and prints:

cp: error reading 'path/to/always/same/file': Input/output error

The output of dmesg contains:

[72481.869510] ata2.00: configured for UDMA/133
[72481.874133] ata2.01: configured for UDMA/133
[72481.874145] sd 1:0:1:0: [sdc] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[72481.874147] sd 1:0:1:0: [sdc] tag#0 Sense Key : Medium Error [current] 
[72481.874149] sd 1:0:1:0: [sdc] tag#0 Add. Sense: Unrecovered read error - auto reallocate failed
[72481.874152] sd 1:0:1:0: [sdc] tag#0 CDB: Read(16) 88 00 00 00 00 00 f7 9f 4c 00 00 00 02 00 00 00
[72481.874154] print_req_error: I/O error, dev sdc, sector 4154412112
[72481.879316] ata2: EH complete
[72484.819205] ata2.01: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0
[72484.824273] ata2.01: failed command: READ DMA EXT
[72484.829346] ata2.01: cmd 25/00:08:50:4c:9f/00:00:f7:00:00/f0 tag 0 dma 4096 in
                        res 51/40:00:50:4c:9f/40:00:f7:00:00/10 Emask 0x9 (media error)                                             
[72484.849742] ata2.01: status: { DRDY ERR }
[72484.854836] ata2.01: error: { UNC }

After reading up on the problem online, I learned that this means that I manually have to mark a bad block as such. But issuing read command does not return "fail":

$ sudo hdparm --read-sector 4154412112 /dev/sdc

/dev/sdc:
reading sector 4154412112: SG_IO: bad/missing sense data, sb[]:  70 00 03 00 00 00 00 0a 40 51 10 00 11 04 00 00 a0 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00
succeeded
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000

What's going on here?

  • Have you tried ddrescue? – Rafael Kitover Aug 18 '19 at 4:20
  • 1
    The hdparm output looks like an failure ("bad sense data"), even if you see "succeeded". Try the sg tools discussed here – meuh Aug 18 '19 at 17:05
  • @RafaelKitover I have no run dd and ddrescue on it. However, I'm unsure as to how to interpret the output. Anyway, here it is: pastebin.com/k9XRqW3d – UTF-8 Aug 18 '19 at 19:21
  • @meuh I took the number of bytes where dd aborted (not the original broken region but there seem to be more than one), divided it by 512, and got the number 4154412112. Then I ran the following: pastebin.com/e6uMDZzC Google apparently does not know anything about the error message "READ DEFECT DATA(10): Illegal request, invalid opcode". Do you think that it means my hard drive does not support marking bad blocks as such? – UTF-8 Aug 18 '19 at 19:33
  • I'm not sure about the exact meaning of the messages, but the ddrescue shows there were 3 clusters of unreadable data, and there is no way to replace the bad blocks with spare blocks on the disk. I'm not even sure that you would be able to overwrite the bad sectors, which can fix some read errors. – meuh Aug 18 '19 at 20:15
2

hdparm succeeded in talking with the drive¹. That's all “succeeded” indicates. The drive said “SG_IO: bad/missing sense data”. I don't know exactly what this means², but it's definitely not a good thing. hdparm did not succeed in reading the sector.

hdparm went ahead and displayed the memory buffer which is supposed to contain the sector content, but that's all zeros. It's clearly not something that was read from the drive.

Marking that block as bad may help to continue working with the drive for a bit, although of course you should replace it as soon as possible. (However the bad block should have been marked as such automatically. I don't see why you'd do that manually.) But it isn't going to let you read the data from that block.

¹ Specifically, it means that the HDIO_DRIVE_TASKFILE ioctl returned 0.
² Reading the source code of hdparm shows that this particular message is displayed when sb[0] != 0x72 || sb[7] < 14 || desc[0] != 0x09 || desc[1] < 0x0c. I have no idea what those numbers mean.

| improve this answer | |
  • I don't care about the data on the disk. Is there something I can do so that I can read from anywhere on the "disk" again (after new data has been written, ofc)? Does a simple writing dd over the entire disk / the affected parts suffice? (I'm not sure whether you mean that it's likely that the bad blocks have been marked or that that should've happened but didn't.) – UTF-8 Aug 18 '19 at 21:46
  • @UTF-8 I think once you remove the file you won't ”see“ the bad block again. But I wouldn't use a disk that's developed unreadable blocks. – Gilles 'SO- stop being evil' Aug 19 '19 at 8:51
1

Refer to

https://www.smartmontools.org/wiki/BadBlockHowto

and

https://wiki.archlinux.org/index.php/Identify_damaged_files

for more information.

In a nutshell, after using tools like debugfs or sleuthkit to identify which file is damaged, and after hdparm --read-sector, you may try to use --repair-sector (alias of --write-sector) which "writes zeros to the specified sector number" and "force the drive to repair a bad sector (media error)" See the hdparm man page for details.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.