Files
nvdriver/uninstall.sh

93 lines
3.7 KiB
Bash
Executable File

#!/bin/bash
# Undo ./install.sh: unload nvdriver, remove its modules and the host configuration it
# wrote (modprobe.d, modules-load.d, udev rule, /dev/nvidia* bind-mount service, CDI patch).
#
# Left in place: /lib/firmware/nvidia/<ver>/gsp_*.bin (install.sh only copies those when
# missing, so they may belong to a stock driver package) and volta-forever (it has its own
# uninstaller). Set REMOVE_FIRMWARE=1 to also remove the extracted packs under
# /lib/firmware/nvidia-rs. Set UNLOAD=0 to leave the running modules loaded until the next boot.
set -euo pipefail
UNLOAD=${UNLOAD:-1}
REMOVE_FIRMWARE=${REMOVE_FIRMWARE:-0}
have_systemd() { command -v systemctl >/dev/null 2>&1; }
if [ "$UNLOAD" = "1" ]; then
echo "== unload =="
if have_systemd; then
sudo systemctl stop nvidia-persistenced 2>/dev/null || true
sudo systemctl stop nvdriver-devnodes.service 2>/dev/null || true
fi
# bind mounts the service did not own (e.g. from install.sh's own --bind)
for f in /dev/nvidia[0-9]* /dev/nvidiactl /dev/nvidia-uvm /dev/nvidia-modeset; do
if mountpoint -q "$f" 2>/dev/null; then
sudo umount "$f" 2>/dev/null || true
fi
# Remove regular-file placeholders created by bind_dev_nodes.sh (including
# those already unmounted by nvdriver-devnodes.service); preserve real char
# devices, symlinks, and anything still mounted.
if ! mountpoint -q "$f" 2>/dev/null && [ -f "$f" ] && [ ! -c "$f" ] && [ ! -L "$f" ]; then
sudo rm -f -- "$f"
fi
done
for m in nvidia_rs_drm nvidia_rs_modeset nvidia_rs_peermem nvidia_rs_modeset_bridge nvidia_rs_uvm_bridge nvidia_rs; do
# A short-circuiting grep can give lsmod SIGPIPE under pipefail.
module_list=$(lsmod)
if grep -q "^$m " <<<"$module_list"; then
sudo rmmod "$m" 2>/dev/null || echo "WARN: $m is in use and stays loaded until the next boot (sudo fuser -v /dev/nvidia*)." >&2
fi
done
fi
echo "== remove modules =="
if command -v dkms >/dev/null 2>&1 && [ -n "$(dkms status -m nvdriver 2>/dev/null || true)" ]; then
echo "WARN: nvdriver is registered with DKMS; leaving its modules to DKMS." >&2
echo " Remove them with: sudo dkms remove nvdriver/<version> --all" >&2
else
for dir in /lib/modules/*/updates/nvdriver; do
[ -d "$dir" ] || continue
krel=${dir#/lib/modules/}
krel=${krel%%/*}
sudo rm -rf -- "$dir"
sudo depmod -a "$krel"
echo "removed $dir"
done
fi
echo "== remove host configuration =="
for f in \
/etc/modprobe.d/nvdriver.conf \
/etc/modules-load.d/nvdriver.conf \
/etc/udev/rules.d/70-nvdriver.rules \
/usr/local/sbin/nvdriver-bind-dev-nodes \
/usr/local/sbin/nvdriver-cdi-patch \
/etc/systemd/system/nvidia-cdi-refresh.service.d/10-nvdriver-dev-char.conf; do
if [ -e "$f" ]; then
sudo rm -f -- "$f"
echo "removed $f"
fi
done
sudo rmdir /etc/systemd/system/nvidia-cdi-refresh.service.d 2>/dev/null || true
if [ -e /etc/systemd/system/nvdriver-devnodes.service ]; then
if have_systemd; then
sudo systemctl disable nvdriver-devnodes.service 2>/dev/null || true
fi
sudo rm -f /etc/systemd/system/nvdriver-devnodes.service
echo "removed /etc/systemd/system/nvdriver-devnodes.service"
fi
if have_systemd; then
sudo systemctl daemon-reload 2>/dev/null || true
fi
if command -v udevadm >/dev/null 2>&1; then
sudo udevadm control --reload-rules 2>/dev/null || true
fi
if [ "$REMOVE_FIRMWARE" = "1" ] && [ -d /lib/firmware/nvidia-rs ]; then
sudo rm -rf /lib/firmware/nvidia-rs
echo "removed /lib/firmware/nvidia-rs"
fi
echo "nvdriver uninstalled. The stock nvidia blacklist is gone; reinstall or re-enable your stock driver"
echo "package if you want it back, and rebuild the initramfs if your distribution keeps modprobe.d there."