Fix #21 configurable RAM and #22 configurable cores

This commit is contained in:
Marcus Grenängen 2020-04-05 18:49:25 +02:00
parent 485aaed7c7
commit 9c139c2d5a

View File

@ -279,23 +279,31 @@ function vm_boot() {
fi
local CORES_VM="1"
local CORES_HOST=$(nproc --all)
if [ ${CORES_HOST} -ge 8 ]; then
CORES_VM="4"
elif [ ${CORES_HOST} -ge 4 ]; then
CORES_VM="2"
if [ -z "$cpu_cores" ]; then
local CORES_HOST=$(nproc --all)
if [ ${CORES_HOST} -ge 8 ]; then
CORES_VM="4"
elif [ ${CORES_HOST} -ge 4 ]; then
CORES_VM="2"
fi
else
CORES_VM="$cpu_cores"
fi
local SMP="-smp ${CORES_VM},sockets=1,cores=${CORES_VM},threads=1"
echo " - CPU: ${CORES_VM} Core(s)"
local RAM_VM="2G"
local RAM_HOST=$(free --mega -h | grep Mem | cut -d':' -f2 | cut -d'G' -f1 | sed 's/ //g')
#Round up - https://github.com/wimpysworld/quickemu/issues/11
RAM_HOST=$(printf '%.*f\n' 0 ${RAM_HOST})
if [ ${RAM_HOST} -ge 64 ]; then
RAM_VM="4G"
elif [ ${RAM_HOST} -ge 16 ]; then
RAM_VM="3G"
if [ -z "$ram" ]; then
local RAM_HOST=$(free --mega -h | grep Mem | cut -d':' -f2 | cut -d'G' -f1 | sed 's/ //g')
#Round up - https://github.com/wimpysworld/quickemu/issues/11
RAM_HOST=$(printf '%.*f\n' 0 ${RAM_HOST})
if [ ${RAM_HOST} -ge 64 ]; then
RAM_VM="4G"
elif [ ${RAM_HOST} -ge 16 ]; then
RAM_VM="3G"
fi
else
RAM_VM="$ram"
fi
echo " - RAM: ${RAM_VM}"