From e29a0f13832b2dfb2f780593a6d4a63e71453a1f Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:13:05 +0200 Subject: [PATCH] Make preallocation configurable --- run/install.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/run/install.sh b/run/install.sh index 1356b3d..8d7eb5d 100644 --- a/run/install.sh +++ b/run/install.sh @@ -108,16 +108,24 @@ echo "Install: Creating partition table..." SYSTEM="$TMP/sys.img" SYSTEM_SIZE="4954537983" -# Check free diskspace -SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) +if [ "$ALLOCATE" != "Y" ]; then -if (( SYSTEM_SIZE > SPACE )); then - echo "ERROR: Not enough free space to create virtual system disk." && exit 87 -fi + truncate -s "${SYSTEM_SIZE}" "${SYSTEM}"; + +else + + # Check free diskspace + SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) + + if (( SYSTEM_SIZE > SPACE )); then + echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87 + fi + + if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then + rm -f "${SYSTEM}" + echo "ERROR: Could not allocate a file for the system disk." && exit 88 + fi -if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then - rm -f "${SYSTEM}" - echo "ERROR: Could not allocate file for virtual system disk." && exit 88 fi PART="$TMP/partition.fdisk"