Skip to content

Instantly share code, notes, and snippets.

@countingpine
Created January 28, 2018 23:15
Show Gist options
  • Select an option

  • Save countingpine/9cac455546b60940fd76bd3c3df4f870 to your computer and use it in GitHub Desktop.

Select an option

Save countingpine/9cac455546b60940fd76bd3c3df4f870 to your computer and use it in GitHub Desktop.
#!/bin/bash
# sha256sum each (megabyte-sized) block of /dev/sda, prepend the block number
# intent is to compare two drivesum lists and then dd out the changed blocks and send them to the other drive
device=/dev/sda
bs=1048576
size=$(blockdev --getsize64 $device)
sumsfile=/tmp/sums_$(date +%s).txt
blocks=$(( ($size+$bs-1)/$bs ))
#test: blocks=10
for ((i = 0; i < $blocks; i++)); do
dd if=/$device bs=$bs skip=$i count=1 status=none | sha256sum
done | awk '{print n+0, $1; n++}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment