Copy files from a failing disk

From Leo's Notes
Last edited on 9 October 2022, at 00:55.

Reading or copying files affected by bad sectors will fail with a 'input/output' error. These files may still be partially read out using dd with the conv=noerror option.

Symptoms[edit | edit source]

In rsync, you'll get a 'failed verification' warning. Rsync will then continue on with the remaining files before attempting to copy the file again.

file.mkv
        982.58M 100%   30.80MB/s    0:00:30 (xfr#4, to-chk=176/344)
WARNING: file.mkv failed verification -- update discarded (will try again).
file.mkv
        982.58M 100%   31.08MB/s    0:00:30 (xfr#5, to-chk=176/344)
rsync: read errors mapping "/mnt/sda/file.mkv": Input/output error (5)
ERROR: file.mkv failed verification -- update discarded.
total: matches=0  hash_hits=0  false_alarms=0 data=1965159605

sent 1.97G bytes  received 29.97K bytes  30.96M bytes/sec
total size is 73.14G  speedup is 37.21
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1189) [sender=3.1.3]

In dmesg, you'll likely see some messages about the failed reads:

[Sun Mar 20 17:36:39 2022] ata1.00: exception Emask 0x0 SAct 0x1800000 SErr 0x0 action 0x0
[Sun Mar 20 17:36:39 2022] ata1.00: irq_stat 0x40000008
[Sun Mar 20 17:36:39 2022] ata1.00: failed command: READ FPDMA QUEUED
[Sun Mar 20 17:36:39 2022] ata1.00: cmd 60/00:b8:00:f5:36/01:00:07:00:00/40 tag 23 ncq dma 131072 in
                                    res 41/40:00:c8:f5:36/00:00:07:00:00/40 Emask 0x409 (media error) <F>
[Sun Mar 20 17:36:39 2022] ata1.00: status: { DRDY ERR }
[Sun Mar 20 17:36:39 2022] ata1.00: error: { UNC }
[Sun Mar 20 17:36:39 2022] ata1.00: configured for UDMA/133
[Sun Mar 20 17:36:39 2022] sd 1:0:0:0: [sda] tag#23 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE cmd_age=2s
[Sun Mar 20 17:36:39 2022] sd 1:0:0:0: [sda] tag#23 Sense Key : Medium Error [current]
[Sun Mar 20 17:36:39 2022] sd 1:0:0:0: [sda] tag#23 Add. Sense: Unrecovered read error - auto reallocate failed
[Sun Mar 20 17:36:39 2022] sd 1:0:0:0: [sda] tag#23 CDB: Read(10) 28 00 07 36 f5 00 00 01 00 00
[Sun Mar 20 17:36:39 2022] blk_update_request: I/O error, dev sda, sector 121042376 op 0x0:(READ) flags 0x80700 phys_seg 2 prio class 0
[Sun Mar 20 17:36:39 2022] ata1: EH complete
[Sun Mar 20 17:36:41 2022] ata1.00: exception Emask 0x0 SAct 0x100 SErr 0x0 action 0x0
[Sun Mar 20 17:36:41 2022] ata1.00: irq_stat 0x40000008
[Sun Mar 20 17:36:41 2022] ata1.00: failed command: READ FPDMA QUEUED
[Sun Mar 20 17:36:41 2022] ata1.00: cmd 60/08:40:c8:f5:36/00:00:07:00:00/40 tag 8 ncq dma 4096 in
                                    res 41/40:00:c8:f5:36/00:00:07:00:00/40 Emask 0x409 (media error) <F>
[Sun Mar 20 17:36:41 2022] ata1.00: status: { DRDY ERR }
[Sun Mar 20 17:36:41 2022] ata1.00: error: { UNC }
[Sun Mar 20 17:36:41 2022] ata1.00: configured for UDMA/133
[Sun Mar 20 17:36:41 2022] sd 1:0:0:0: [sda] tag#8 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE cmd_age=1s
[Sun Mar 20 17:36:41 2022] sd 1:0:0:0: [sda] tag#8 Sense Key : Medium Error [current]
[Sun Mar 20 17:36:41 2022] sd 1:0:0:0: [sda] tag#8 Add. Sense: Unrecovered read error - auto reallocate failed
[Sun Mar 20 17:36:41 2022] sd 1:0:0:0: [sda] tag#8 CDB: Read(10) 28 00 07 36 f5 c8 00 00 08 00
[Sun Mar 20 17:36:41 2022] blk_update_request: I/O error, dev sda, sector 121042376 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
[Sun Mar 20 17:36:41 2022] ata1: EH complete

Solutions[edit | edit source]

dd[edit | edit source]

If you need to recover the file despite the read errors, you can use dd using the conv=noerror option. The output file will have the problematic sections be padded with zeros.

# dd if=broken_file.dat of=/recovery/broken_file.dat conv=noerror,sync status=progress

rsync[edit | edit source]

If you don't care about the file, you may skip the file with the --exclude option in rsync. Eg: rsync --exclude='path/to/file.dat'.

testdisk[edit | edit source]

Testdisk is a file recovery utility that can be used to recover data from a bad disk.