Skip to content

Instantly share code, notes, and snippets.

@Nislaco
Last active January 29, 2025 22:45
Show Gist options
  • Save Nislaco/ce7ec314bdf0cf519ff0fb2fffc55107 to your computer and use it in GitHub Desktop.
Save Nislaco/ce7ec314bdf0cf519ff0fb2fffc55107 to your computer and use it in GitHub Desktop.
Ubuntu LTS dxgkrnl 6.6.y script
#!/bin/bash -e
BRANCH=linux-msft-wsl-6.6.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
git checkout
BATCH='test'
RUN=$(git rev-parse --short HEAD)
VERSION="${RUN}${BATCH}"
cp -r drivers/hv/dxgkrnl /usr/src/dxgkrnl-$VERSION
mkdir -p /usr/src/dxgkrnl-$VERSION/include/uapi/misc
mkdir -p /usr/src/dxgkrnl-$VERSION/include/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_dxgkrnl.h
sed -i 's/\$(CONFIG_DXGKRNL)/m/' /usr/src/dxgkrnl-$VERSION/Makefile
sed -i 's#linux/hyperv.h#linux/hyperv_dxgkrnl.h#' /usr/src/dxgkrnl-$VERSION/dxgmodule.c
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
wget https://raw.githubusercontent.com/thexperiments/dxgkrnl-dkms-git/main/dxgkrnl.h.patch
patch -u /usr/src/dxgkrnl-$VERSION/dxgkrnl.h ./dxgkrnl.h.patch
sed -i 's/l(event->cpu_event, 1)/l(event->cpu_event)/g' /usr/src/dxgkrnl-$VERSION/dxgmodule.c
dkms add dxgkrnl/$VERSION
dkms build dxgkrnl/$VERSION
dkms install dxgkrnl/$VERSION
@Nislaco
Copy link
Author

Nislaco commented Jul 27, 2024

This compiles off git for WSL kernel mod directly for ubuntu 24.04 using LTS kernel. IE 6.8.0-39-generic

Other repos used for patches:
https://github.com/thexperiments/dxgkrnl-dkms-git?tab=readme-ov-file
https://github.com/staralt/dxgkrnl-dkms

In my testing Linux GPU_PV only seems to work if all GPU's (if multiple/multi vendor) are passed through. Manually selecting one specific GPU fails when trying to initialize the card in my attempts.

Please see this GitHub for info as well as previously listed ones for info in setting up driver's files between Host and Guest as well as partitioning GPU for passthrough .
https://github.com/brokeDude2901/dxgkrnl_ubuntu?tab=readme-ov-file

Tested on a system with 3 Gpus from 2 vendors all 3 devices show as Microsoft dxg devices.

#This example works for passing through multiple gpus into ubuntu..
$gpu_list = Get-VMHostPartitionableGpu
foreach ($k in $gpu_list){
$instance_path = $k.Name
$instance_path
Add-VMGpuPartitionAdapter -VMName $vm -InstancePath $instance_path
}

@mateuszdrab
Copy link

mateuszdrab commented Jan 28, 2025

Moved to seflerZ/oneclick-gpu-pv#8 for clarity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment