Make preallocation configurable

Make preallocation configurable
This commit is contained in:
Kroese 2023-04-18 18:31:35 +02:00 committed by GitHub
commit ec10de346f
6 changed files with 55 additions and 30 deletions

View File

@ -48,6 +48,7 @@ EXPOSE 5000
EXPOSE 5001
ENV URL ""
ENV ALLOCATE Y
ENV CPU_CORES 1
ENV DISK_SIZE 16G
ENV RAM_SIZE 512M

View File

@ -29,20 +29,27 @@ if [ -f "${DATA}" ]; then
echo "INFO: Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.."
if [ "$ALLOCATE" != "Y" ]; then
truncate -s "${DATA_SIZE}" "${DATA}";
else
REQ=$((DATA_SIZE-OLD_SIZE))
# Check free diskspace
SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1)
if (( REQ > SPACE )); then
echo "ERROR: Not enough free space to resize virtual disk." && exit 84
echo "ERROR: Not enough free space to resize virtual disk to ${DISK_SIZE}." && exit 84
fi
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
echo "ERROR: Could not allocate file for virtual disk." && exit 85
echo "ERROR: Could not allocate a file for the virtual disk." && exit 85
fi
fi
fi
if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then
@ -52,22 +59,31 @@ if [ -f "${DATA}" ]; then
mv -f "${DATA}" "${DATA}.bak"
fi
fi
if [ ! -f "${DATA}" ]; then
# Create an empty file
if [ "$ALLOCATE" != "Y" ]; then
truncate -s "${DATA_SIZE}" "${DATA}"
else
# Check free diskspace
SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1)
if (( DATA_SIZE > SPACE )); then
echo "ERROR: Not enough free space to create virtual disk." && exit 86
echo "ERROR: Not enough free space to create a virtual disk of ${DISK_SIZE}."
echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 86
fi
# Create an empty file
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
rm -f "${DATA}"
echo "ERROR: Could not allocate file for virtual disk." && exit 87
echo "ERROR: Could not allocate a file for the virtual disk." && exit 87
fi
fi
# Check if file exists
@ -80,12 +96,11 @@ if [ ! -f "${DATA}" ]; then
fi
AGENT_VERSION=1
AGENT="${STORAGE}/${BASE}.agent"
[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}")
[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1
if ((AGENT_VERSION < 5)); then
echo "INFO: The installed VirtualDSM Agent is an outdated version, please upgrade it."
echo "INFO: The installed VirtualDSM Agent v${AGENT_VERSION} is an outdated version, please upgrade it."
fi
KVM_DISK_OPTS="\

View File

@ -112,12 +112,12 @@ SYSTEM_SIZE="4954537983"
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
if (( SYSTEM_SIZE > SPACE )); then
echo "ERROR: Not enough free space to create virtual system disk." && exit 87
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 file for virtual system disk." && exit 88
echo "ERROR: Could not allocate a file for the system disk." && exit 88
fi
PART="$TMP/partition.fdisk"

View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -eu
# Docker environment variabeles
: ${VM_NET_TAP:=''}
: ${VM_NET_IP:='20.20.20.21'}
: ${VM_NET_HOST:='VirtualDSM'}

View File

@ -42,9 +42,8 @@ _graceful_shutdown(){
# If we cannot shutdown the usual way, fallback to the NMI method
AGENT_VERSION=1
AGENT="${STORAGE}/${BASE}.agent"
[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}")
[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1
if ((AGENT_VERSION < 2)); then

View File

@ -1,6 +1,14 @@
#!/usr/bin/env bash
set -eu
# Docker environment variabeles
: ${URL:=''}. # URL of PAT file
: ${ALLOCATE:='Y'} # Preallocate diskspace
: ${CPU_CORES:='1'} # vCPU count
: ${DISK_SIZE:='16G'} # Initial disk size
: ${RAM_SIZE:='512M'} # Amount of RAM
echo "Starting Virtual DSM for Docker v${VERSION}..."
STORAGE="/storage"