Skip to content

Instantly share code, notes, and snippets.

@rolfen
Last active April 9, 2021 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolfen/3829e0bfd7287854d63105f2b0f1212a to your computer and use it in GitHub Desktop.
Save rolfen/3829e0bfd7287854d63105f2b0f1212a to your computer and use it in GitHub Desktop.
Resume a dd operation with a check

This little script resumes an interrupted dd copy at a given offset.

Before resuming, it rolls back (the amount of roll-back is OVERLAP_SIZE * CHUNK) then calculate the checksum of the overlap on both files to make sure that they are valid images of each other.

The checksums have to be checked manually by the operator (todo: automate).

IDEV=$1;
ODEV=$2;
POS=$3;
LOG="/home/rolf/dd.log";
OVERLAP_SIZE=200
OVERLAP_POS=`expr $POS - $OVERLAP_SIZE`
CHUNK=95200
if [ $# -lt 3 ]
then
echo "Usage: mydd INPUT_DEVICE OUTPUT_DEVICE START_POSITION"
echo "Example: mydd /dev/sdc /dev/sdb 840000"
echo "Note: Needs super user"
exit 0
fi
echo "Copy $IDEV -> $ODEV at $POS";
dd if=$IDEV count=$OVERLAP_SIZE bs=1MB skip=$OVERLAP_POS | md5sum;
dd if=$ODEV count=$OVERLAP_SIZE bs=1MB skip=$OVERLAP_POS | md5sum;
read -p "Please check matching checksums above then press Enter to continue";
echo "Starting at $POS" >> $LOG ;
dd if=$IDEV of=$ODEV count=$CHUNK bs=1MB skip=$POS seek=$POS conv=notrunc status=progress;
hdparm --idle-unload $IDEV;
echo "Please power cycle input device then launch this script again with adjusted parameters";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment