This commit is contained in:
Kroese 2023-04-27 20:59:01 +02:00 committed by GitHub
parent 81d45c7d4c
commit 2da7622c94

View file

@ -1,9 +1,9 @@
#!/usr/bin/env bash
set -eu
# Docker environment variabeles
# Docker environment variables
: ${BOOT:=''} # URL of the ISO file
: ${BOOT:=''} # URL of the ISO file
: ${DEBUG:='N'} # Enable debug mode
: ${ALLOCATE:='Y'} # Preallocate diskspace
: ${CPU_CORES:='1'} # Amount of CPU cores
@ -31,33 +31,35 @@ fi
# Configure shutdown
. /run/power.sh
KVM_ERR=""
KVM_OPTS=""
if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then
if grep -q -e vmx -e svm /proc/cpuinfo; then
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
if ! grep -q -e vmx -e svm /proc/cpuinfo; then
KVM_ERR="(cpuinfo $(grep -c -e vmx -e svm /proc/cpuinfo))"
fi
else
[ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)"
fi
if [ -z "${KVM_OPTS}" ]; then
echo "Error: KVM acceleration is disabled.."
if [ -n "${KVM_ERR}" ]; then
echo "ERROR: KVM acceleration not detected ${KVM_ERR}, please enable it."
[ "$DEBUG" != "Y" ] && exit 88
else
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
fi
DEF_OPTS="-nographic -nodefaults"
KVM_OPTS="-machine type=q35,usb=off${KVM_OPTS}"
DEF_OPTS="-nographic -nodefaults -display none"
RAM_OPTS=$(echo "-m ${RAM_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
CPU_OPTS="-smp ${CPU_CORES},sockets=1,cores=${CPU_CORES},threads=1"
CPU_OPTS="-smp ${CPU_CORES},sockets=1,dies=1,cores=${CPU_CORES},threads=1"
MAC_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
SERIAL_OPTS="-serial mon:stdio -device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3"
EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0 -object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng-pci,rng=rng0"
ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${KVM_OPTS} ${MON_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS}"
ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${MAC_OPTS} ${MON_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS}"
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
if [ "$DEBUG" = "Y" ]; then
echo -n "qemu-system-x86_64 "
echo "${ARGS}" && echo
fi
[ "$DEBUG" = "Y" ] && echo "qemu-system-x86_64 ${ARGS}" && echo
set -m
(