Skip to content

Instantly share code, notes, and snippets.

@Nislaco
Last active July 29, 2024 16:55
Show Gist options
  • Save Nislaco/fdd58c2436ad5a90ec9e22b5014301c5 to your computer and use it in GitHub Desktop.
Save Nislaco/fdd58c2436ad5a90ec9e22b5014301c5 to your computer and use it in GitHub Desktop.
Build script for dxgkrnl kernel module from WSL linux-msft-wsl-5.15.y for Debian 12 Bookworm guest on Hyper-V for GPU-PV
#!/bin/bash -e
BRANCH=linux-msft-wsl-5.15.y
if [ "$EUID" -ne 0 ]; then
echo "Swithing to root..."
exec sudo $0 "$@"
fi
apt-get install -y git dkms
git clone -b $BRANCH --no-checkout --depth=1 https://github.com/microsoft/WSL2-Linux-Kernel.git
cd WSL2-Linux-Kernel
git sparse-checkout set --no-cone /drivers/hv/dxgkrnl /include/uapi/misc/d3dkmthk.h /include/linux/hyperv.h /include/linux/eventfd.h
git checkout
BATCH='test'
RUN=$(git rev-parse --short HEAD)
VERSION="${RUN}${BATCH}"
curl -fsSL https://content.staralt.dev/dxgkrnl-dkms/main/0001-Add-a-gpu-pv-support.patch | git apply -v
echo
curl -fsSL https://content.staralt.dev/dxgkrnl-dkms/main/0002-Add-a-multiple-kernel-version-support.patch | git apply -v
echo
curl -fsSL https://content.staralt.dev/dxgkrnl-dkms/main/0003-Fix-gpadl-has-incomplete-type-error.patch | git apply -v
echo
cp -r drivers/hv/dxgkrnl /usr/src/dxgkrnl-$VERSION
mkdir -p /usr/src/dxgkrnl-$VERSION/include/{uapi/misc,linux}
cp include/uapi/misc/d3dkmthk.h /usr/src/dxgkrnl-$VERSION/include/uapi/misc/d3dkmthk.h
cp include/linux/hyperv.h /usr/src/dxgkrnl-$VERSION/include/linux/hyperv.h
cp include/linux/eventfd.h /usr/src/dxgkrnl-$VERSION/include/linux/eventfd.h
sed -i 's/\$(CONFIG_DXGKRNL)/m/' /usr/src/dxgkrnl-$VERSION/Makefile
sed -i 's#<uapi/linux/eventfd.h>#<linux/eventfd.h>#g' /usr/src/dxgkrnl-$VERSION/include/linux/eventfd.h
echo "EXTRA_CFLAGS=-I\$(PWD)/include -D_MAIN_KERNEL_" >> /usr/src/dxgkrnl-$VERSION/Makefile
cat > /usr/src/dxgkrnl-$VERSION/dkms.conf <<EOF
PACKAGE_NAME="dxgkrnl"
PACKAGE_VERSION="$VERSION"
BUILT_MODULE_NAME="dxgkrnl"
DEST_MODULE_LOCATION="/kernel/drivers/hv/dxgkrnl/"
AUTOINSTALL="yes"
EOF
dkms add dxgkrnl/$VERSION
dkms build dxgkrnl/$VERSION
dkms install dxgkrnl/$VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment