How to use ddrescue to clone disk drive (better than ghost for failing drives)
See also
DataRecoveryCleanupFiles
1. Identify disks
Run this to identify the disks connected to your linux PC
lsblk | grep ^sd; echo; lsblk|grep ^sd |sed -e 's/ .*$//'| xargs -i hdparm -I /dev/{} | grep -v '^ *$' | grep 'number\|device size\|/dev' -i | grep -v '1024[*]1024'
2. Clone
If you know that about 100GB are used in a 400GB disk set USED_SIZE to 125GB (real use +25% overhead). If not sure set a random number, it doesn't hurt.
#-------SET THESE FIRST----------
SRC=/dev/sdX
DST=/dev/sdY #<--- you can also write the disk to a file e.g. /mnt/temp/disk.raw
USED_SIZE=125GiB
A_NAME=RN01234
# ^--It's best to use the RN number but you can type anything you like
# If you have to rescue more than one disks from the same RN add -1,2,...
#------------------------------------
QUICK="-f -n -u -r1"
THOROUGH="-f -d -r3"
PARANOID="-f -d -r-1"
# How hard to try
#------------------------------------
# -d direct access to disk (slower)
# -u only scan forwards (faster)
# -n skips scraping phase (faster)
# -r how many times to retry (-1 for ever)
# -f force writting to disk/partition(instead of file)
# which part of disk to work on
#------------------------------------
FIRST_MB="-i0 -s1MiB"
FIRST_FIFTY_MB="-i1MiB -s50MiB"
USED_PART="-i50MiB -s$USED_SIZE"
REST_OF_DISK="-i$USED_SIZE"
EVERYTHING=""
# standard options
#------------------------------------
STD_OPTS="$SRC $DST $A_NAME.ddrescue"
# Main part
#------------------------------------
ddrescue $QUICK $FIRST_MB $STD_OPTS
ddrescue $QUICK $FIRST_FIFTY_MB $STD_OPTS
ddrescue $QUICK $USED_PART $STD_OPTS
ddrescue $THOROUGH $FIRST_MB $STD_OPTS
ddrescue $THOROUGH $FIRST_FIFTY_MB $STD_OPTS
ddrescue $QUICK $REST_OF_DISK $STD_OPTS
ddrescue $THOROUGH $USED_PART $STD_OPTS
ddrescue $THOROUGH $REST_OF_DISK $STD_OPTS
ddrescue $PARANOID $EVERYTHING $STD_OPTS
echo ; echo "ALL DONE"
echo
echo
Consider monitoring for disk errors while cloning
You can monitor for disk errors from another terminal like this:
tail -f /var/log/syslog | grep --line-buffered -w 'sd[a-z]'
If while copying from /dev/sda to /dev/sdb, /dev/sda freezes up at position 12345678.
Reboot computer and restart copy at freeze_postition + *10000*
ddrescue -f -i 12355678 $SRC $DST mapfile
Start copying backwards down to the troubled sector
ddrescue -f -R $SRC $DST mapfile
If disk begins returning read errors from position 12345678 onwards
stop ddrescue and reboot computer
ddrescue -f -n -A -O -i 12345678 $SRC $DST mapfile
If disk fails again, reboot computer and then repeat the above command as many times as needed until it succeeds.
ddrescue -d -r3 $SRC $DST mapfile
If while copying from sda, it disappears from /dev.
Reboot computer and then repeat the same command as many times as needed until it succeeds
Finaly
You can consider adjusting the timeout to read a sector (change sdX to the disk id). You may wish to make it small in order for a quick first clone with many errors and then make it large (e.g. 2sec) to try hard to copy the few failing sectors:
echo 1 > /sys/block/sdX/device/timeout