Skip to content

Instantly share code, notes, and snippets.

@nilya
Created December 26, 2012 14:44
Show Gist options
  • Save nilya/4380689 to your computer and use it in GitHub Desktop.
Save nilya/4380689 to your computer and use it in GitHub Desktop.
"vgaswitch" script to turn on/off discrete videocard under Linux.
#!/bin/bash
# Place this file under /usr/local/bin/vgaswitch
# load module (without this module "vgaswitcheroo" isn't available on my system)
modprobe radeon
# switch
SWITCH=/sys/kernel/debug/vgaswitcheroo/switch
if [ $# -eq 1 ]; then
if [ "$1" == "low" ]; then
echo "Turning on low-power card."
echo DIGD > $SWITCH
elif [ "$1" == "high" ]; then
echo "Turning on high-power card."
echo DDIS > $SWITCH
elif [ "$1" == "on" ]; then
echo "Turning on unused card."
echo ON > $SWITCH
elif [ "$1" == "off" ]; then
echo "Turning off unused card."
echo OFF > $SWITCH
elif [ "$1" == "st" ]; then
cat $SWITCH
fi
else
echo "Commands: [low, high, on, off]"
echo
echo "Status:"
cat $SWITCH
fi
#!/bin/sh
### BEGIN INIT INFO
# Provides: vgaswitch
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Power on second videocard to fix errors on shutdown.
# Description: Place this file under /etc/init.d/vgaswitch and run "update-rc.d vgaswitch defaults".
### END INIT INFO
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
case "$1" in
start)
;;
stop)
/usr/local/bin/vgaswitch on
;;
esac
:
@nilya
Copy link
Author

nilya commented Mar 19, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment