From 6970159c8c995908be1255a7cd7bc1a56b6a533c Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 15 Apr 2023 03:59:18 +0200 Subject: [PATCH] Check diskspace --- disk.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/disk.sh b/disk.sh index cb6071f..d029b13 100644 --- a/disk.sh +++ b/disk.sh @@ -14,10 +14,16 @@ DATA="$IMG/data$DISK_SIZE.img" 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 if ! fallocate -l "${NEW_SIZE}" "${DATA}"; then 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 # Check if file exists