30 lines
912 B
Bash
Executable File
30 lines
912 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
# Get HD filename
|
|
FILENAME=`vboxmanage showvminfo kaz-vm | grep SATA | grep UUID | cut -d':' -f2 | cut -d'(' -f1 | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//'`
|
|
|
|
# Split the dir and filename
|
|
DIR=`dirname "$FILENAME"`
|
|
FILE=`basename "$FILENAME"`
|
|
|
|
# Get HD UUID
|
|
UUID=`vboxmanage showvminfo kaz-vm | grep SATA | grep UUID | cut -d':' -f 3| cut -d')' -f1 | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//'`
|
|
|
|
# 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"
|