Skip to content

Instantly share code, notes, and snippets.

@bindi
Last active August 27, 2021 05:25
Show Gist options
  • Save bindi/9c55b59f3b5cb3b5a7afb1c3dd218a99 to your computer and use it in GitHub Desktop.
Save bindi/9c55b59f3b5cb3b5a7afb1c3dd218a99 to your computer and use it in GitHub Desktop.
#!/bin/bash
# helps with (re)installing https://github.com/DualCoder/vgpu_unlock
# after you have installed nvidia drivers (./NVIDIA-Linux-*-vgpu-kvm.run --dkms)
#
# this script assumes you have vgpu_unlock in /root
# it also assumes you only have one nvidia-<version> in /usr/src/
# (beware that NVIDIA doesn't clean up files in that directory, even if you run the uninstaller, do it yourself if required)
#
# hope it isn't too hacky. works for me :)!
dir=$(find /usr/src/ -maxdepth 1 -name 'nvidia-*' -type d)
amount=$(echo "$dir" | wc -l)
if [ "$amount" -ne "1" ]
then
echo "fix your stuff, you have multiple versions in /usr/src/nvidia-*/"
echo "make sure you only have the version you are currently trying to fiddle with"
else
ver=$(basename "$dir" | sed 's/^nvidia-//')
files=(/usr/lib/systemd/system/nvidia-vgpud.service /usr/lib/nvidia/systemd/nvidia-vgpud.service /usr/lib/systemd/system/nvidia-vgpu-mgr.service /usr/lib/nvidia/systemd/nvidia-vgpu-mgr.service)
for file in "${files[@]}"; do grep -q "vgpu_unlock" $file && echo "not touching $file, already has vgpu_unlock" || sed -i 's/ExecStart=/ExecStart=\/root\/vgpu_unlock\/vgpu_unlock / w /dev/stdout' $file; done
systemctl daemon-reload
osif=$(find /usr/src/nvidia-$ver/nvidia/os-interface.c)
kbui=$(find /usr/src/nvidia-$ver/nvidia/nvidia.Kbuild)
grep -q vgpu_unlock "$osif" && echo "not touching $osif, already has vgpu_unlock" || sed -i '/^#include "nv-time.h"/a #include "/root/vgpu_unlock/vgpu_unlock_hooks.c"' "$osif"
grep -q vgpu_unlock "$kbui" && echo "not touching $kbui, already has vgpu_unlock" || echo "ldflags-y += -T /root/vgpu_unlock/kern.ld" >> "$kbui"
dkms remove -m nvidia -v $ver --all
dkms install -m nvidia -v $ver
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment