Last active
December 15, 2021 18:33
-
-
Save x1unix/1da427d2ced8ad39f5a1a1f183333436 to your computer and use it in GitHub Desktop.
Linux - disable NVIDIA GPU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
# nvidia-remove - Disables NVIDIA GPU | |
# | |
# See: http://us.download.nvidia.com/XFree86/Linux-x86_64/455.45.01/README/dynamicpowermanagement.html | |
# Root user ID | |
ROOT_UID=0 | |
# NVIDIA PCI Vendor ID | |
NV_PCI_VENDOR_ID='0x10de' | |
if [ "${UID:-$(id -u)}" -ne "$ROOT_UID" ]; then | |
sudo "$0" | |
exit $? | |
fi | |
devices="$(lspci -d "$NV_PCI_VENDOR_ID:" -D -mm)" | |
if [ -z "$devices" ]; then | |
echo "No NVIDIA devices found!" | |
exit 1 | |
fi | |
echo "$devices" | while IFS= read -r line; do | |
devid=$(echo "$line" | awk -F'"' '{gsub(/^[[:space:]]+|[[:space:]]+$/,"", $1); print $1}') | |
name=$(echo "$line" | awk -F'"' '{print $4, $6}') | |
device_path="/sys/bus/pci/devices/$devid/remove" | |
printf 'Removing "%s" ...' "$name" | |
echo 1 > "/sys/bus/pci/devices/$devid/remove" | |
printf '\rRemoving "%s" - ' "$name" | |
[ ! -d "$device_path" ] && echo "SUCCESS" || echo "FAILED" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment