Skip to content

Commit

Permalink
scripts: Add Windows disk clone script
Browse files Browse the repository at this point in the history
  • Loading branch information
Tu Dinh committed Jan 10, 2025
1 parent 096ae4a commit 60bb1dc
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions scripts/guests/windows/clone-compact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -eu

src=$1
dst=$2

if [ "$(blockdev --getsz $src)" != "$(blockdev --getsz $dst)" ]
then
echo "Disks are not the same size!"
exit 1
fi

if (sfdisk -d $dst > /dev/null)
then
echo "Destination contains partition table! Stopping"
exit 1
fi

echo "Cloning partition table"
sfdisk -d $src | sfdisk $dst

echo "Cloning non-data partitions"
for srcpart in $(sfdisk -d $src |
grep start= |
grep -v type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 |
cut -d ':' -f 1)
do
dstpart=${srcpart/"$src"/"$dst"}
echo "Cloning $srcpart to $dstpart"
pv $srcpart > $dstpart
done

echo "Cloning data partitions"
for srcpart in $(sfdisk -d $src |
grep type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 |
cut -d ':' -f 1)
do
dstpart=${srcpart/"$src"/"$dst"}
echo "Cloning $srcpart to $dstpart"
ntfsclone -O $dstpart $srcpart
done

0 comments on commit 60bb1dc

Please sign in to comment.