Skip to content

Instantly share code, notes, and snippets.

@ronnymajani
Last active June 1, 2019 02:46
Show Gist options
  • Save ronnymajani/69d67c5e10544e37eac1634765a1d358 to your computer and use it in GitHub Desktop.
Save ronnymajani/69d67c5e10544e37eac1634765a1d358 to your computer and use it in GitHub Desktop.
[Bash Script Enable/Disable Nvidia GPU on XPS15 9570 running Manjaro] Bash script to enable/disable the NVIDIA GPU using ACPI commands in Manjaro Linux because bbswitch can switch it off but fails to switch it back on. I suggest to put these scripts in /usr/local/bin/ and put disable-nvidia.conf and disable-ipmi.conf and blacklist.conf in /etc/m…
Section "ServerFlags"
Option "AutoAddGPU" "off"
EndSection

I had trouble using bbswitch on my XP15 9570 running Manjaro Linux 18.04. After some digging I found the following method in the forums to manually enable/disable the Nvidia GPU

Requirements

  • Install video-linux using mhwd sudo mhwd -i pci video-linux
  • Then install the nvidia driver (not using Manjaro's mhwd tool, just do it using pacman) sudo pacman -S nvidia
  • Then install bumblebee (this give you optirun) sudo pacman -S bumblebee

Setup

Modify the following lines in /etc/bumblebee/bumblebee.conf:

  • Driver=nvidia
  • KernelDriver=nvidia
  • PMMethod=none

Make sure that /etc/modprobe.d/mhwd-gpu.conf is empty, if it's not, delete the entries related to nvidia. (assuming you just started manjaro and are now installing the nvidia drivers, then there shouldn't be any other non-gpu related entries)

Put the file 01-noautogpu.conf in /etc/X11/xorg.conf.d/

Then we need to add the following modprobe configuration files to /etc/modprobe.d/:

  • blacklist.conf
  • disable-ipmi.conf
  • disable-nvidia.conf

Then install a systemctl service to automatically disable the Nvidia GPU on shutdown, by first putting the file disable-nvidia-on-shutdown.service in /etc/systemd/system/ and then registering the service by running sudo systemctl daemon-reload then sudo systemctl enable disable-nvidia-on-shutdown.service in your terminal

Then add the file nvidia_pm.conf to /etc/tmpfiles.d/

Then for convenience sake add the following 2 scripts to /usr/local/bin so you can easily access them without typing the full script path:

  • enablegpu.sh
  • disablegpu.sh

Also don't forget to chmod a+rx those 2 scripts

  • sudo chmod a+rx /usr/local/bin/disablegpu.sh
  • sudo chmod a+rx /usr/local/bin/enablegpu.sh

Restart your machine.

Usage

Now whenever you need the Nvidia GPU, simply open your terminal and run enablegpu.sh to switch it on

Similarly if you want to switch it off run disablegpu.sh

To actually utilize the GPU to handle the graphics of a specific application, use optirun optirun my_cool_graphics_app

Tips

Also if you end up having screen resolution problems just remove /etc/X11/xorg.conf or rename it if you want to keep a backup

You can use autorandr to make youre laptop remember the screen resolutions settings you prefer and automatically apply them when appropriate

You can use nvidia-smi to check if your Nvidia card is responding/working.

You can use glxgears to test your graphics performance

  • run glxgears to test your integrated intel graphics
  • run optirun glxgears to test your discrete nvidia graphics (alternatively use the -v flag for a verbose output)
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv
blacklist nv
blacklist nvidia
blacklist nvidia-drm
blacklist nvidia-modeset
blacklist nvidia-uvm
blacklist ipmi_msghandler
blacklist ipmi_devintf
install ipmi_msghandler /usr/bin/false
install ipmi_devintf /usr/bin/false
[Unit]
Description=Disables Nvidia GPU on OS shutdown
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/bin/bash -c "mv /etc/modprobe.d/disable-nvidia.conf.disable /etc/modprobe.d/disable-nvidia.conf || true"
[Install]
WantedBy=multi-user.target
install nvidia /bin/false
#!/bin/sh
modprobe -r nvidia_drm
modprobe -r nvidia_uvm
modprobe -r nvidia_modeset
modprobe -r nvidia
echo -n auto > /sys/bus/pci/devices/0000\:01\:00.0/power/control
sleep 1
echo -n auto > /sys/bus/pci/devices/0000\:00\:01.0/power/control
sleep 1
mv /etc/modprobe.d/disable-nvidia.conf.disable /etc/modprobe.d/disable-nvidia.conf
#!/bin/sh
mv /etc/modprobe.d/disable-nvidia.conf /etc/modprobe.d/disable-nvidia.conf.disable
echo -n 1 > /sys/bus/pci/devices/0000\:01\:00.0/remove
sleep 1
echo -n on > /sys/bus/pci/devices/0000\:00\:01.0/power/control
sleep 1
echo -n 1 > /sys/bus/pci/rescan
modprobe nvidia
w /sys/bus/pci/devices/0000:01:00.0/power/control - - - - auto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment