R.I.P. All my pictures … almost

I’ve kept all of my digital photos on an external hard drive. And that hard drive crashed – Linux just wouldn’t mount it. I let out an audible gasp after realizing the drive won’t come back.

Luckily I had dejadup running and I was able to restore the photos. Phew. But I didn’t backup everything on that drive and so I was wondering if I could get back all the other miscellaneous files I had on there. I don’t know what they were but now I was curious.

The error message in /var/log/syslog was:

Jul 17 23:56:33 tower kernel: [ 10.374777] sd 12:0:0:0: [sdf] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Jul 17 23:56:33 tower kernel: [ 10.374781] sd 12:0:0:0: [sdf] tag#0 Sense Key : Medium Error [current]
Jul 17 23:56:33 tower kernel: [ 10.374784] sd 12:0:0:0: [sdf] tag#0 Add. Sense: Unrecovered read error
Jul 17 23:56:33 tower kernel: [ 10.374788] sd 12:0:0:0: [sdf] tag#0 CDB: Read(10) 28 00 00 00 00 38 00 00 08 00
Jul 17 23:56:33 tower kernel: [ 10.374791] blk_update_request: critical medium error, dev sdf, sector 56 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0
Jul 17 23:56:33 tower kernel: [ 13.730496] sd 12:0:0:0: [sdf] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Jul 17 23:56:33 tower kernel: [ 13.730500] sd 12:0:0:0: [sdf] tag#0 Sense Key : Medium Error [current]
Jul 17 23:56:33 tower kernel: [ 13.730503] sd 12:0:0:0: [sdf] tag#0 Add. Sense: Unrecovered read error
Jul 17 23:56:33 tower kernel: [ 13.730506] sd 12:0:0:0: [sdf] tag#0 CDB: Read(10) 28 00 00 00 00 38 00 00 01 00
Jul 17 23:56:33 tower kernel: [ 13.730509] blk_update_request: critical medium error, dev sdf, sector 56 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
Jul 17 23:56:33 tower kernel: [ 13.730574] Buffer I/O error on dev sdf, logical block 56, async page read
Jul 17 23:56:33 tower kernel: [ 17.086792] sd 12:0:0:0: [sdf] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Jul 17 23:56:33 tower kernel: [ 17.086796] sd 12:0:0:0: [sdf] tag#0 Sense Key : Medium Error [current]
Jul 17 23:56:33 tower kernel: [ 17.086798] sd 12:0:0:0: [sdf] tag#0 Add. Sense: Unrecovered read error
Jul 17 23:56:33 tower kernel: [ 17.086801] sd 12:0:0:0: [sdf] tag#0 CDB: Read(10) 28 00 00 00 00 39 00 00 07 00
Jul 17 23:56:33 tower kernel: [ 17.086805] blk_update_request: critical medium error, dev sdf, sector 57 op 0x0:(READ) flags 0x0 phys_seg 7 prio class 0
Jul 17 23:56:33 tower kernel: [ 17.086867] Buffer I/O error on dev sdf, logical block 57, async page read
Jul 17 23:56:33 tower kernel: [ 17.086883] Buffer I/O error on dev sdf, logical block 58, async page read
Jul 17 23:56:33 tower kernel: [ 17.086899] Buffer I/O error on dev sdf, logical block 59, async page read
Jul 17 23:56:33 tower kernel: [ 17.086914] Buffer I/O error on dev sdf, logical block 60, async page read
Jul 17 23:56:33 tower kernel: [ 17.086929] Buffer I/O error on dev sdf, logical block 61, async page read
Jul 17 23:56:33 tower kernel: [ 17.086945] Buffer I/O error on dev sdf, logical block 62, async page read
Jul 17 23:56:33 tower kernel: [ 17.086960] Buffer I/O error on dev sdf, logical block 63, async page read
Jul 17 23:56:33 tower kernel: [ 20.485982] sd 12:0:0:0: [sdf] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Jul 17 23:56:33 tower kernel: [ 20.485986] sd 12:0:0:0: [sdf] tag#0 Sense Key : Medium Error [current]
Jul 17 23:56:33 tower kernel: [ 20.485989] sd 12:0:0:0: [sdf] tag#0 Add. Sense: Unrecovered read error
Jul 17 23:56:33 tower kernel: [ 20.485992] sd 12:0:0:0: [sdf] tag#0 CDB: Read(10) 28 00 00 00 00 3f 00 00 08 00
Jul 17 23:56:33 tower kernel: [ 20.485996] blk_update_request: critical medium error, dev sdf, sector 63 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0
Jul 17 23:56:33 tower kernel: [ 23.842040] sd 12:0:0:0: [sdf] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Jul 17 23:56:33 tower kernel: [ 23.842043] sd 12:0:0:0: [sdf] tag#0 Sense Key : Medium Error [current]
Jul 17 23:56:33 tower kernel: [ 23.842046] sd 12:0:0:0: [sdf] tag#0 Add. Sense: Unrecovered read error
Jul 17 23:56:33 tower kernel: [ 23.842049] sd 12:0:0:0: [sdf] tag#0 CDB: Read(10) 28 00 00 00 00 3f 00 00 02 00
Jul 17 23:56:33 tower kernel: [ 23.842052] blk_update_request: critical medium error, dev sdf, sector 63 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
Jul 17 23:56:33 tower kernel: [ 23.842117] Buffer I/O error on dev sdf1, logical block 0, async page read
Jul 17 23:56:33 tower kernel: [ 27.241768] sd 12:0:0:0: [sdf] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Jul 17 23:56:33 tower kernel: [ 27.241772] sd 12:0:0:0: [sdf] tag#0 Sense Key : Medium Error [current]
Jul 17 23:56:33 tower kernel: [ 27.241775] sd 12:0:0:0: [sdf] tag#0 Add. Sense: Unrecovered read error
Jul 17 23:56:33 tower kernel: [ 27.241778] sd 12:0:0:0: [sdf] tag#0 CDB: Read(10) 28 00 00 00 00 00 00 00 f0 00
Jul 17 23:56:33 tower kernel: [ 27.241782] blk_update_request: critical medium error, dev sdf, sector 0 op 0x0:(READ) flags 0x4000 phys_seg 16 prio class 0
Jul 17 23:56:33 tower kernel: [ 30.619864] sd 12:0:0:0: [sdf] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Jul 17 23:56:33 tower kernel: [ 30.619868] sd 12:0:0:0: [sdf] tag#0 Sense Key : Medium Error [current]
Jul 17 23:56:33 tower kernel: [ 30.619871] sd 12:0:0:0: [sdf] tag#0 Add. Sense: Unrecovered read error
Jul 17 23:56:33 tower kernel: [ 30.619874] sd 12:0:0:0: [sdf] tag#0 CDB: Read(10) 28 00 00 00 00 3f 00 00 f0 00
Jul 17 23:56:33 tower kernel: [ 30.619878] blk_update_request: critical medium error, dev sdf, sector 63 op 0x0:(READ) flags 0x4000 phys_seg 15 prio class 0

The messages indicate that sectors 56 – 63 were bad but I was hoping the rest of the drive was ok. Since this was an older drive with no SMART capabilities, I couldn’t use any of those diagnostics. Since I couldn’t mount it, I couldn’t run any of the command-line tools. But I did have a lot of other HDD space free and so I attempted to create an image of the disk and repair the image.

After some Googling, I found these two sites:

https://forums.unraid.net/topic/51819-solved-disk-disappeared-then-reappeared-empty-how-i-recovered-my-data-xfs/

https://major.io/2010/12/14/mounting-a-raw-partition-file-made-with-dd-or-dd_rescue-in-linux/

Using a combination of ddrescue, losetup, and xfs_repair, I was able to remount the image. Success!

ddrescue -f -n /dev/sdf /mnt/external_hdd/bad_hdd.img ~/ddrescue.log
sudo losetup –offset 32256 /dev/loop2 /mnt/external_hdd/bad_hdd.img
sudo xfs_repair /dev/loop2
sudo mount -v -t xfs -o ro,loop,offset=32256 /mnt/external_hdd/bad_hdd.img /mnt/img