How to copy directories and files from a corrupted harddrive?
First of all, if your drive is experiencing I/O errors you should check if your drive is healthy enough. I/O errors might be localized only on a/some specific bad block/bad blocks, but having one/some is how a drive failure usually starts.
You can use smartctl
to check your drive's S.M.A.R.T.
status, which provides many informations about the drive's overall conditions, most interestingly about the reallocated / current pending sectors count. You can install smartctl
by installing the package smartmontools
:
sudo apt-get update && sudo apt-get install smartmontools
For SATA
drives, you can check your drive's S.M.A.R.T.
status by running:
sudo smartctl -a -d <device_file>
*<device_file> = device file to which your drive is mapped to (in the form of /dev/sdX
; you can check this by running lsblk
);
For IDE
drives, you can check your drive's S.M.A.R.T.
status by running:
sudo smartctl -a <device_file>
*<device_file> = device file to which your drive is mapped to (in the form of /dev/sdX
; you can check this by running lsblk
);
The most important indexes to be checked are Reallocated sector count
and Current pending sector count
. The former provides the number of the drive's "dead" sectors, while the latter provides the number of the drive's "almost dead" sectors which will be reallocated if a further read attempt on them fails.
If the disk is a little aged, those numbers are not likely to be 0, which is the ideal condition. How alarming those numbers actually are it depends, expecially on the drive's age and size; consider that each "dead" sector on most hard drives equals to 512 B
worth of storage space lost already, but most of all an already high number is usually prone to increase more quickly and it's usually an indicator of a close fail.
Aside from that, you can try with ddrescue
. If the partition containing the file(s) you're trying to recover is the root
partition, do this from a Live DVD, since the target filesystem must be mounted read-only.
Also beware that reading/writing a non healthy drive might ruin it further. ddrescue
is meant to do as less damage as possible, but there are no guarantees.
First, if the target partition is mounted, unmount it:
sudo umount /media/<username>/<partition_mount_point>
*<username> = your username; <partition_mount_point> = partition's mount point (you can check this by running lsblk
);
Remount the target partition as read-only:
sudo mkdir /media/<username>/ddrescue && sudo mount -o ro /dev/<sdXY> /media/<username>/ddrescue
*<username> = your username; <sdXY> = block device to which the partition is mapped (you can check this by running lsblk
);
Create a directory in which to copy the recovered file(s) (in this case it's a "recovered
" folder in your home
):
mkdir ~/recovered
Run ddrescue
:
ddrescue /media/<username>/ddrescue/<file_path> ~/recovered
*<username> = your username; <file_path> = file's path in the target partition;
And repeat this last step for each file you wish to recover.
Once done, unmount the target partition and remove the temporary folder:
sudo umount /media/<username>/ddrescue && sudo rmdir /media/<username>/ddrescue
*<username> = your username;
Related videos on Youtube
nux
The Quieter you are , the more you are able to hear . "Once you stop learning, you start dying". -Albert Einstein Started learning Python . I am from Lebanon .
Updated on September 18, 2022Comments
-
nux over 1 year
I have an I/O error every time I copy folders and files from a partition to a backup harddrive .
So how can I safely backup this data to my backup HDD?
-
Fabby about 9 yearsMaybe add
smartctl
to check if there are any errors? ;-) -
kos about 9 years@Fabby Yes, done :)
-
Fabby about 9 yearsAnd upvoted! ;-)