diff --git a/src/config.sh b/src/config.sh index d16f2d7..387b93a 100644 --- a/src/config.sh +++ b/src/config.sh @@ -12,4 +12,18 @@ DEV_OPTS="$DEV_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0 ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $DEV_OPTS $ARGUMENTS" ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ') +# Check available memory as the very last step + +RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}') +AVAIL_GB=$(( (RAM_AVAIL + 1073741823)/1073741824 )) + +if (( (RAM_WANTED + 500000000) > RAM_AVAIL )); then + error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available, please set a lower value." + exit 17 +fi + +if (( (RAM_WANTED + 1450000000) > RAM_AVAIL )); then + warn "your configured RAM_SIZE of $WANTED_GB GB is much too close to the $AVAIL_GB GB of memory available, please set a lower value." +fi + return 0 diff --git a/src/reset.sh b/src/reset.sh index faa7a9d..ba44786 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -86,13 +86,9 @@ echo # Check memory -if (( RAM_WANTED > RAM_AVAIL )); then - error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available." - exit 15 -fi - -if (( (RAM_WANTED + 1950000000) > RAM_AVAIL )); then - warn "your configured RAM_SIZE of $WANTED_GB GB is much too close to the $AVAIL_GB GB of memory available." +if (( (RAM_WANTED + 500000000) > RAM_AVAIL )); then + error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available, please set a lower value." + exit 17 fi # Cleanup files