Check diskspace

This commit is contained in:
Kroese 2023-04-15 03:59:18 +02:00 committed by GitHub
parent bab6554cbd
commit 6970159c8c

View File

@ -14,10 +14,16 @@ DATA="$IMG/data$DISK_SIZE.img"
if [ ! -f "$DATA" ]; then if [ ! -f "$DATA" ]; then
# Check free diskspace
SPACE=$(df --output=avail -B 1 "$IMG" | tail -n 1)
if (( NEW_SIZE > SPACE )); then
echo "ERROR: Not enough free space to create virtual disk." && exit 87
fi
# Create an empty file # Create an empty file
if ! fallocate -l "${NEW_SIZE}" "${DATA}"; then if ! fallocate -l "${NEW_SIZE}" "${DATA}"; then
rm -f "${DATA}" rm -f "${DATA}"
echo "ERROR: Not enough free space to create virtual disk." && exit 88 echo "ERROR: Could not allocate file for virtual disk." && exit 88
fi fi
# Check if file exists # Check if file exists