Check diskspace
This commit is contained in:
parent
2d4b6e8bd9
commit
ce16198374
1 changed files with 11 additions and 2 deletions
13
disk.sh
13
disk.sh
|
@ -10,10 +10,19 @@ DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
|
|||
DATA="$IMG/data${DISK_SIZE}.img"
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
|
||||
rm -f "${DATA}"
|
||||
echo "ERROR: Could not allocate file for virtual disk." && exit 82
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
[ ! -f "$DATA" ] && echo "ERROR: Data image does not exist ($DATA)" && exit 83
|
||||
|
|
Loading…
Reference in a new issue