user2057368
user2057368

Reputation: 13

How can I use bash to keep my GPU turned off?

I'm currently getting familiar with bash scripting. One of my problems is trying to fix a hybrid video on laptop by switching off the powerful GPU every time Linux loads.

To do that, I currently edit rc.local by adding the following lines:

chown -R $USER:$USER /sys/kernel/debug
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

The problem is, every time the system comes out of sleep mode, the GPU turns back on again, eventually going hotter and hotter, as indicated by lm-sensors.

My question: What do I have to do to keep said GPU turned off constantly?

Upvotes: 1

Views: 515

Answers (2)

iabdalkader
iabdalkader

Reputation: 17312

I think it's a bug and it hasn't been fixed yet, so for now you could call your script on wakeup events by adding something like this to /etc/pm/sleep.d

#!/bin/sh
case "${1}" in
    resume|thaw)
        vga_off.sh
        ;;
esac

Note: Are you sure the GPU turns on again ? or does it consume more power as reported in this bug ? if that's the case the workaround is to turn it on and off again.

Upvotes: 1

Cory Klein
Cory Klein

Reputation: 55660

There are likely many solutions to this problem, but one that would work is to put those two lines into a script, and then add it to your crontab to run every 5 minutes. This would cause the computer to disable the GPU every five minutes, and if it is already disabled it doesn't cause any adverse effect (besides running a short script every 5 minutes, which isn't much).

crontab -e
# Add the following line:
*/5 * * * * /home/user2057368/scripts/GPUTurnOffScript.sh

GPUTurnOffScript.sh can be written as follows:

#!/bin/bash
chown -R $USER:$USER /sys/kernel/debug
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

Then you have to make sure it is executable by changing the permissions

sudo chmod u+x GPUTurnOffScript.sh

Upvotes: 0

Related Questions