From 63cac9a75e80a80ad56e1d373202948e65b56c99 Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 29 Dec 2023 16:56:49 +0100 Subject: [PATCH] fix: Display config (#519) * fix: Display config --- src/config.sh | 17 +++++------------ src/cpu.sh | 1 + src/{gpu.sh => display.sh} | 17 +++++++++++++++++ src/entry.sh | 2 +- src/power.sh | 14 ++++++++++---- src/reset.sh | 2 -- 6 files changed, 34 insertions(+), 19 deletions(-) rename src/{gpu.sh => display.sh} (55%) diff --git a/src/config.sh b/src/config.sh index 3d4fc3c..98ade00 100644 --- a/src/config.sh +++ b/src/config.sh @@ -1,22 +1,15 @@ #!/usr/bin/env bash set -Eeuo pipefail -DEF_OPTS="-nographic -nodefaults -boot strict=on -display none" +DEF_OPTS="-nodefaults -boot strict=on" RAM_OPTS=$(echo "-m $RAM_SIZE" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') CPU_OPTS="-cpu $CPU_MODEL -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}" -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 -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c" +DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4" +DEV_OPTS="$DEV_OPTS -object rng-random,id=objrng0,filename=/dev/urandom" +DEV_OPTS="$DEV_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c" -if [[ "$GPU" == [Yy1]* ]] && [[ "$ARCH" == "amd64" ]]; then - DEF_OPTS="-nodefaults -boot strict=on -display egl-headless,rendernode=/dev/dri/renderD128" - DEF_OPTS="$DEF_OPTS -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1" -fi - -[[ "$CONSOLE" != [Yy]* ]] && DEF_OPTS="$DEF_OPTS -daemonize -D $QEMU_LOG" - -ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $EXTRA_OPTS $ARGUMENTS" +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 ' ') return 0 diff --git a/src/cpu.sh b/src/cpu.sh index bc8137e..51b4792 100644 --- a/src/cpu.sh +++ b/src/cpu.sh @@ -3,6 +3,7 @@ set -Eeuo pipefail # Docker environment variables +: ${KVM:='Y'} : ${HOST_CPU:=''} : ${CPU_MODEL:='host'} : ${CPU_FEATURES:='+ssse3,+sse4.1,+sse4.2'} diff --git a/src/gpu.sh b/src/display.sh similarity index 55% rename from src/gpu.sh rename to src/display.sh index 289c423..0fc2b2c 100644 --- a/src/gpu.sh +++ b/src/display.sh @@ -1,10 +1,27 @@ #!/usr/bin/env bash set -Eeuo pipefail +# Docker environment variables + +: ${GPU:='N'} # GPU passthrough +: ${DISPLAY:='none'} # Display type + +case "${DISPLAY,,}" in + vnc) + DISPLAY_OPTS="-display vnc=:0 -vga virtio" + ;; + *) + DISPLAY_OPTS="-display $DISPLAY -vga none" + ;; +esac + if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then return 0 fi +DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128 -vga virtio" +[[ "${DISPLAY,,}" == "vnc" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0" + [ ! -d /dev/dri ] && mkdir -m 755 /dev/dri if [ ! -c /dev/dri/card0 ]; then diff --git a/src/entry.sh b/src/entry.sh index 8526e01..258e6df 100755 --- a/src/entry.sh +++ b/src/entry.sh @@ -9,8 +9,8 @@ cd /run . reset.sh # Initialize system . install.sh # Run installation . disk.sh # Initialize disks +. display.sh # Initialize graphics . network.sh # Initialize network -. gpu.sh # Initialize graphics . cpu.sh # Initialize processor . serial.sh # Initialize serialport . power.sh # Configure shutdown diff --git a/src/power.sh b/src/power.sh index 259901b..3759472 100644 --- a/src/power.sh +++ b/src/power.sh @@ -157,10 +157,16 @@ _graceful_shutdown() { finish "$code" && return "$code" } -if [[ "$CONSOLE" != [Yy]* ]]; then - _trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT -fi - MON_OPTS="\ -pidfile $QEMU_PID \ -monitor telnet:localhost:$QEMU_PORT,server,nowait,nodelay" + +if [[ "$CONSOLE" != [Yy]* ]]; then + + MON_OPTS="$MON_OPTS -daemonize -D $QEMU_LOG" + + _trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT + +fi + +return 0 diff --git a/src/reset.sh b/src/reset.sh index 53666ba..48a79fd 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -12,8 +12,6 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR # Docker environment variables : ${TZ:=''} # System local timezone -: ${GPU:='N'} # Disable GPU passthrough -: ${KVM:='Y'} # Enable KVM acceleration : ${DEBUG:='N'} # Disable debugging mode : ${COUNTRY:=''} # Country code for mirror : ${CONSOLE:='N'} # Disable console mode