KVM detection

This commit is contained in:
Kroese 2023-04-27 11:40:44 +02:00 committed by GitHub
parent 7574a83325
commit 91b808db26

View File

@ -43,32 +43,31 @@ fi
# Configure shutdown # Configure shutdown
. /run/power.sh . /run/power.sh
KVM_OPTS="" KVM_ERR=""
if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then
if grep -q -e vmx -e svm /proc/cpuinfo; then if ! grep -q -e vmx -e svm /proc/cpuinfo; then
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
else
KVM_ERR="(cpuinfo $(grep -c -e vmx -e svm /proc/cpuinfo))" KVM_ERR="(cpuinfo $(grep -c -e vmx -e svm /proc/cpuinfo))"
fi fi
else else
[ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)" [ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)"
fi fi
if [ -z "${KVM_OPTS}" ]; then if [ -z "${KVM_ERR}" ]; then
echo "Error: KVM acceleration not detected ${KVM_ERR}, please enable it." echo "Error: KVM acceleration not detected ${KVM_ERR}, please enable it."
[ "$DEBUG" != "Y" ] && exit 88 [ "$DEBUG" != "Y" ] && exit 88
fi fi
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
DEF_OPTS="-nographic -nodefaults -boot strict=on -display none" DEF_OPTS="-nographic -nodefaults -boot strict=on -display none"
RAM_OPTS=$(echo "-m ${RAM_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') 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,dies=1,cores=${CPU_CORES},threads=1" CPU_OPTS="-smp ${CPU_CORES},sockets=1,dies=1,cores=${CPU_CORES},threads=1"
KVM_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}" MAC_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4" EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
EXTRA_OPTS="$EXTRA_OPTS -object rng-random,id=objrng0,filename=/dev/urandom" EXTRA_OPTS="$EXTRA_OPTS -object rng-random,id=objrng0,filename=/dev/urandom"
EXTRA_OPTS="$EXTRA_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c" EXTRA_OPTS="$EXTRA_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
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 ' ') ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
if [ "$DEBUG" = "Y" ]; then if [ "$DEBUG" = "Y" ]; then