From bb3982edfdb5f8889ea558c3731a284081970b97 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Thu, 24 Nov 2016 15:37:39 +0100 Subject: [PATCH] if shrinking from device, copy only the relevant part --- pishrink.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pishrink.sh b/pishrink.sh index 73b9b6e..45d4d76 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -38,7 +38,13 @@ fi #Copy to new file if requested if [ -n "$2" ]; then echo "Copying $1 to $2..." - cp --reflink=auto --sparse=always "$1" "$2" + if [[ -f $img ]]; then + cp --reflink=auto --sparse=always "$1" "$2" + else + imgsize=`parted -m $img unit B print | tail -1 | cut -d ':' -f 3 | tr -d 'B\n'` + imgsize=`expr $imgsize + 1` + dd if="$1" of="$2" conv=sparse count=$imgsize iflag=count_bytes bs=1M + fi if (( $? != 0 )); then echo "ERROR: Could not copy file..." exit -5