-
-
Save parkerlreed/ec3156dbc22952a5618f to your computer and use it in GitHub Desktop.
Switch NVIDIA/nouveau modules
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/sh | |
unbind_vtconsoles() | |
{ | |
for ((i = 0; i < 16; i++)) | |
do | |
if [ -d "/sys/class/vtconsole/vtcon$i" ]; then | |
if [ `cat /sys/class/vtconsole/vtcon$i/name | grep -c "frame buffer"` -eq 1 ]; then | |
while [ `cat /sys/class/vtconsole/vtcon$i/bind` -ne 0 ]; do | |
echo Unbinding vtcon$i | |
echo 0 > /sys/class/vtconsole/vtcon$i/bind | |
sleep 1 | |
done | |
fi | |
fi | |
done | |
} | |
bind_vtconsoles() | |
{ | |
for ((i = 0; i < 16; i++)) | |
do | |
if [ -d "/sys/class/vtconsole/vtcon$i" ]; then | |
if [ `cat /sys/class/vtconsole/vtcon$i/name | grep -c "frame buffer"` -eq 1 ]; then | |
echo 0 > /sys/class/vtconsole/vtcon$i/bind | |
while [ `cat /sys/class/vtconsole/vtcon$i/bind` -ne 1 ]; do | |
echo Binding vtcon$i | |
if [ ! -e "/dev/dri" ]; then | |
vbetool vbestate restore < /usr/local/etc/vbestate | |
fi | |
echo 1 > /sys/class/vtconsole/vtcon$i/bind | |
sleep 1 | |
done | |
fi | |
fi | |
done | |
} | |
wait_plymouth_quit() | |
{ | |
while [ `ps ax | grep -c plymouth` -gt 1 ]; do | |
sleep 1 | |
done | |
} | |
_rmmod() | |
{ | |
output=`rmmod $1 2>&1` | |
status="$?" | |
if [ `echo $output | grep -c "not currently loaded"` -eq 1 ]; then | |
true | |
else | |
[[ -n $output ]] && >&2 echo $output | |
`exit $status` | |
fi | |
} | |
load_nouveau() | |
{ | |
modprobe nouveau | |
} | |
unload_nouveau() | |
{ | |
_rmmod nouveau | |
_rmmod ttm | |
_rmmod drm_kms_helper | |
} | |
load_nvidia() | |
{ | |
modprobe nvidia | |
} | |
unload_nvidia() | |
{ | |
_rmmod nvidia | |
} | |
load_fb() | |
{ | |
modprobe efifb | |
} | |
unload_fb() | |
{ | |
_rmmod efifb | |
} | |
switch_nvidia() | |
{ | |
echo "blacklist nvidia" > /usr/lib/modprobe.d/nvidia.conf | |
echo "blacklist nvidia_uvm" >> /usr/lib/modprobe.d/nvidia.conf | |
wait_plymouth_quit | |
unbind_vtconsoles | |
unload_nouveau | |
if [ "$?" -ne 0 ]; then | |
load_nouveau | |
bind_vtconsoles | |
exit 1 | |
fi | |
echo "blacklist nouveau" > /usr/lib/modprobe.d/nvidia.conf | |
load_fb | |
bind_vtconsoles | |
} | |
switch_nouveau() | |
{ | |
echo "blacklist nvidia" > /usr/lib/modprobe.d/nvidia.conf | |
echo "blacklist nvidia_uvm" >> /usr/lib/modprobe.d/nvidia.conf | |
unload_nvidia | |
} | |
if [ "$1" == "nvidia" ]; then | |
switch_nvidia | |
elif [ "$1" == "nouveau" ]; then | |
switch_nouveau | |
else | |
echo "Module not specified!" | |
echo "You need to specify either nvidia or nouveau" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment