Check diskspace

This commit is contained in:
Kroese 2023-04-15 04:05:12 +02:00 committed by GitHub
parent 2d4b6e8bd9
commit ce16198374

13
disk.sh
View file

@ -10,10 +10,19 @@ DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
DATA="$IMG/data${DISK_SIZE}.img" DATA="$IMG/data${DISK_SIZE}.img"
if [ ! -f "$DATA" ]; then if [ ! -f "$DATA" ]; then
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
rm -f "${DATA}" # Check free diskspace
SPACE=$(df --output=avail -B 1 "$IMG" | tail -n 1)
if (( DATA_SIZE > SPACE )); then
echo "ERROR: Not enough free space to create virtual disk." && exit 82 echo "ERROR: Not enough free space to create virtual disk." && exit 82
fi fi
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
rm -f "${DATA}"
echo "ERROR: Could not allocate file for virtual disk." && exit 82
fi
fi fi
[ ! -f "$DATA" ] && echo "ERROR: Data image does not exist ($DATA)" && exit 83 [ ! -f "$DATA" ] && echo "ERROR: Data image does not exist ($DATA)" && exit 83