feat: GPU passthrough

* feat: GPU passthrough
This commit is contained in:
Kroese 2023-12-16 08:17:53 +01:00 committed by GitHub
parent c2edb081bb
commit 8ffc3bf842
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 2 deletions

View file

@ -3,15 +3,47 @@ set -Eeuo pipefail
# Docker environment variables # Docker environment variables
: ${GPU:='N'} # GPU passthrough
: ${DISPLAY:='none'} # Display type : ${DISPLAY:='none'} # Display type
case "${DISPLAY,,}" in case "${DISPLAY,,}" in
vnc) vnc)
if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
DISPLAY_OPTS="-nographic -vga std -vnc :0" DISPLAY_OPTS="-nographic -vga std -vnc :0"
else
DISPLAY_OPTS="-vga std -vnc :0"
fi
;; ;;
*) *)
if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
DISPLAY_OPTS="-nographic -display none" DISPLAY_OPTS="-nographic -display none"
else
DISPLAY_OPTS=""
fi
;; ;;
esac esac
if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
return 0
fi
DISPLAY_OPTS="$DISPLAY_OPTS -display egl-headless,rendernode=/dev/dri/renderD128"
DISPLAY_OPTS="$DISPLAY_OPTS -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1"
[ ! -d /dev/dri ] && mkdir -m 755 /dev/dri
if [ ! -c /dev/dri/card0 ]; then
mknod /dev/dri/card0 c 226 0
fi
if [ ! -c /dev/dri/renderD128 ]; then
mknod /dev/dri/renderD128 c 226 128
fi
chmod 666 /dev/dri/card0
chmod 666 /dev/dri/renderD128
addPackage "xserver-xorg-video-intel" "Intel GPU drivers"
addPackage "qemu-system-modules-opengl" "OpenGL module"
return 0 return 0

View file

@ -32,4 +32,26 @@ VERS=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1)
STORAGE="/storage" STORAGE="/storage"
[ ! -d "$STORAGE" ] && error "Storage folder ($STORAGE) not found!" && exit 13 [ ! -d "$STORAGE" ] && error "Storage folder ($STORAGE) not found!" && exit 13
# Helper functions
addPackage () {
local pkg=$1
local desc=$2
if apt-mark showinstall | grep -qx "$pkg"; then
return 0
fi
info "Installing $desc..."
export DEBCONF_NOWARNINGS="yes"
export DEBIAN_FRONTEND="noninteractive"
apt-get -qq update
apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null
return 0
}
return 0 return 0