Skip to content

Instantly share code, notes, and snippets.

@sergey-cheperis
Last active May 16, 2023 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergey-cheperis/6eb57493293f0e9f19f86e6031727528 to your computer and use it in GitHub Desktop.
Save sergey-cheperis/6eb57493293f0e9f19f86e6031727528 to your computer and use it in GitHub Desktop.
Prevent NVIDIA driver from auto-updating and breaking vast.ai
#!/bin/bash
# This script "pins" currently installed nvidia driver to prevent it from auto-updating and breaking running vast.ai services.
# It creates the file /etc/apt/preferences.d/nvidia-manual-pin.
#
# From time to time, you'll still need to update the driver manually. Only do this while no vast.ai jobs are running
# (except your default jobs). Follow these steps:
#
# 1. Stop vast.ai and related things: `systemctl stop vastai docker cron`
# 2. Remove the pin: `rm -f /etc/apt/preferences.d/nvidia-manual-pin`
# 3. Do the update: `apt dist-upgrade`
# 4. Reboot.
# 5. After rebooting, run this script again to pin the new version of the driver.
cat /proc/driver/nvidia/version
FULL_VERSION=`cat /proc/driver/nvidia/version | grep NVRM | egrep -o "[0-9]{3}\.[0-9]{2,3}\.[0-9]{2,3}"`
if [ x$FULL_VERSION == x ]
then
MINOR_VERSION=`cat /proc/driver/nvidia/version | grep NVRM | egrep -o "[0-9]{3}\.[0-9]{2,3}"`
if [ x$MINOR_VERSION == x ]
then
echo ERROR: could not determine version
exit 1
fi
else
MINOR_VERSION=${FULL_VERSION%.*}
fi
MAJOR_VERSION=${MINOR_VERSION%.*}
echo Major: $MAJOR_VERSION, minor: $MINOR_VERSION
FILE=/etc/apt/preferences.d/nvidia-manual-pin
echo "Package: nvidia-*-$MAJOR_VERSION libnvidia-*-$MAJOR_VERSION" > $FILE
echo "Pin: version $MINOR_VERSION*" >> $FILE
echo "Pin-Priority: 1001" >> $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment