Dying hard disk : getting my data back (GNU/Linux)

Five years ago I made backups of my data to three hard drives. When my desktop died, I used a small laptop where I could not copy the 1+Tb of data stored on the backups.

Last week, I tried to copy back all the data from my laptop and the old data from my Backups onto a new computer.
Of the three backup disks, one was completely dead (it did not even power up), the second one worked but contained only a partial backup (it was a smaller disk), and the last one was apparently unreadable.

When this disk was plugged in, ‘dmesg’ was printing ‘Read errors’ all over the place, and Linux did not detect any partition on the disk. I thought I had lost 1Tb of data…

Then I found this, this and this.

And here is how I got almost everything back :

  1. Plug in the dying disk (/dev/sdi)
  2. In dmesg, I had hundreds of lines such as :
    [200135.764454] Buffer I/O error on device sdi, logical block 9464
    [200160.490454] sd 9:0:0:0: [sdi] Unhandled sense code
    [200160.490457] sd 9:0:0:0: [sdi]  
    [200160.490458] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
    [200160.490460] sd 9:0:0:0: [sdi]  
    [200160.490461] Sense Key : Medium Error [current] 
    [200160.490463] sd 9:0:0:0: [sdi]  
    [200160.490465] Add. Sense: Data phase error
    [200160.490466] sd 9:0:0:0: [sdi] CDB: 
    [200160.490467] Read(10): 28 00 00 01 27 c0 00 00 08 00
    [200160.490472] end_request: I/O error, dev sdi, sector 75712
  3. Make an image of the disk, ignoring read errors (replaced by 0’s in the file). This took 5 days for 1Tb.
    sudo dd if=/dev/sdi of=/home/myself/backupdisk.bin conv=noerror,sync
  4. Repair the partition table using testdisk (sudo apt-get install testdisk)
    It found one Linux (Ext3fs) partition filling up the disk image, asked to rewrite the partition table and saved the result.

    testdisk /home/myself/backupdisk.bin
  5. Display the partition table in the disk image
    sudo fdisk -lu /home/myself/backupdisk.bin
    Disk /home/myself/backupdisk.bin: 1000.2 GB, 1000204886016 bytes
    255 têtes, 63 secteurs/piste, 121601 cylindres, total 1953525168 secteurs
    Unités = secteurs de 1 * 512 = 512 octets
    Taille de secteur (logique / physique) : 512 octets / 512 octets
    taille d'E/S (minimale / optimale) : 512 octets / 512 octets
    Identifiant de disque : 0x00000000
    Périphérique Amorçage  Début         Fin      Blocs    Id. Système
    /home/myself/backupdisk.bin1   *          63  1953520064   976760001   83  Linux
  6. Set up the partition using the loopback device
    From the partition table, the partition begins at block 63 and units are 512 bytes. So the offset of the partition in the image is 32256 = 63*512. We can now set the /dev/loop0 partition as the first partition of the disk image

    sudo losetup -o 32256 /dev/loop0  /home/myself/backupdisk.bin
  7. Check and repair the partition
    Option -y is used to force fsck to correct errors (without it, it asked for confirmation thousands of times, such as “Free inodes count is wrong for group n°7230 (16384, should be=16378). Correct ?)

    sudo fsck  -y /dev/loop0
    
    #  This ends with :
    /dev/loop0: ***** FILE SYSTEM WAS MODIFIED *****
    /dev/loop0 : 968660/122109952 files (3.9% non contiguous), 234454083/244190000 blocks
  8. Mount the partition and access files
    sudo mkdir /mnt/backupdisk
    sudo mount /dev/loop0 /mnt/backupdisk
  9. Explore files and copy them from /mnt/backupdisk
  10. Unmount the partition et free the loopack device
    sudo umount /mnt/backupdisk
    sudo losetup -d /dev/loop0
This entry was posted in TechTips. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

*