kaz-vagrant/sparsify.sh

30 lines
912 B
Bash
Raw Normal View History

2022-11-30 19:43:06 +01:00
#!/usr/bin/env bash
set -e
# Get HD filename
2023-02-08 12:26:39 +01:00
FILENAME=`vboxmanage showvminfo kaz-vm | grep SATA | grep UUID | cut -d':' -f2 | cut -d'(' -f1 | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//'`
2022-11-30 19:43:06 +01:00
# Split the dir and filename
DIR=`dirname "$FILENAME"`
FILE=`basename "$FILENAME"`
# Get HD UUID
2023-02-08 12:26:39 +01:00
UUID=`vboxmanage showvminfo kaz-vm | grep SATA | grep UUID | cut -d':' -f 3| cut -d')' -f1 | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//'`
2022-11-30 19:43:06 +01:00
# echo -e $DIR
# echo -e $FILE
# echo -e $UUID
echo "Old disk is at $DIR/$FILE, moving it away to $DIR/old.vmdk..."
mv -v "$DIR/$FILE" "$DIR/old.vmdk"
echo
echo "Creating a new sparsed disk at $DIR/$FILE from $DIR/old.vmdk..."
virt-sparsify "$DIR/old.vmdk" "$DIR/$FILE"
echo
echo "Setting UUID to $UUID..."
vboxmanage internalcommands sethduuid "$DIR/$FILE" $UUID
echo
echo "Old virtual disk has been moved to $DIR/old.vmdk, you can now confirm its deletion"
rm -iv "$DIR/old.vmdk"