Skip to content

Instantly share code, notes, and snippets.

@rokups
Created November 5, 2018 08:14
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 rokups/8f04e8a3389d1b0f6433fc79e72a4896 to your computer and use it in GitHub Desktop.
Save rokups/8f04e8a3389d1b0f6433fc79e72a4896 to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
if [ "$EUID" != "0" ];
then
echo "Please run as root."
exit
fi
driver="$1"
shift
while [[ $# > 0 ]];
do
dev="0000:$1"
shift
if [ -z $driver ] | [ -z $dev ];
then
exit 1
fi
vendor=$(cat /sys/bus/pci/devices/${dev}/vendor)
device=$(cat /sys/bus/pci/devices/${dev}/device)
echo -n Unbinding $vendor:$device ...
if [ -e /sys/bus/pci/devices/${dev}/driver ]; then
echo ${dev} > /sys/bus/pci/devices/${dev}/driver/unbind
while [ -e /sys/bus/pci/devices/${dev}/driver ]; do
sleep 0.5
echo -n .
done
fi
echo " OK!"
echo -n Binding \'$driver\' to $vendor:$device ...
echo ${vendor} ${device} > /sys/bus/pci/drivers/${driver}/new_id
echo " OK!"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment