Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Linux NVidia Optimus with external monitor - enable/disable scripts tested on Ubuntu. Source article: http://www.unixreich.com/blog/2013/linux-nvidia-optimus-on-thinkpad-w520w530-with-external-monitor-finally-solved
set /augeas/load/PHP/incl[last()] /etc/bumblebee/bumblebee.conf
set /augeas/load/Xorg/incl[last()] /etc/bumblebee/xorg.conf.nvidia
load
set /files/etc/bumblebee/bumblebee.conf/bumblebeed/KeepUnusedXServer false
set /files/etc/bumblebee/bumblebee.conf/driver-nvidia/PMMethod auto
set /files/etc/bumblebee/bumblebee.conf/driver-nouveau/PMMethod auto
set /files/etc/bumblebee/xorg.conf.nvidia/ServerLayout/Option[last() + 1] "AutoAddDevices"
set /files/etc/bumblebee/xorg.conf.nvidia/ServerLayout/Option[last()]/value "false"
set /files/etc/bumblebee/xorg.conf.nvidia/ServerLayout/Option[last() + 1] "AutoAddGPU"
set /files/etc/bumblebee/xorg.conf.nvidia/ServerLayout/Option[last()]/value "false"
set /files/etc/bumblebee/xorg.conf.nvidia/Device/Option[last() + 1] "UseEDID"
set /files/etc/bumblebee/xorg.conf.nvidia/Device/Option[last()]/value "false"
set /files/etc/bumblebee/xorg.conf.nvidia/Device/Option[last() + 1] "UseDisplayDevice"
set /files/etc/bumblebee/xorg.conf.nvidia/Device/Option[last()]/value "none"
save
set /augeas/load/PHP/incl[last()] /etc/bumblebee/bumblebee.conf
set /augeas/load/Xorg/incl[last()] /etc/bumblebee/xorg.conf.nvidia
load
set /files/etc/bumblebee/bumblebee.conf/bumblebeed/KeepUnusedXServer true
set /files/etc/bumblebee/bumblebee.conf/driver-nvidia/PMMethod none
set /files/etc/bumblebee/bumblebee.conf/driver-nouveau/PMMethod none
rm /files/etc/bumblebee/xorg.conf.nvidia/ServerLayout/Option[. = "AutoAddDevices"]
rm /files/etc/bumblebee/xorg.conf.nvidia/ServerLayout/Option[. = "AutoAddGPU"]
rm /files/etc/bumblebee/xorg.conf.nvidia/Device/Option[. = "UseDisplayDevice"]
rm /files/etc/bumblebee/xorg.conf.nvidia/Device/Option[. = "UseEDID"]
save
# You will need latest NVIDIA drivers installed. At the time of writing, version is 331.20.
# On ubuntu 13.10, it looks like this:
sudo add-apt-repository ppa:xorg-edgers/ppa
sudo apt-get update
sudo apt-get install nvidia-331
# Now we need to install bumblebee:
sudo add-apt-repository ppa:bumblebee/stable
sudo apt-get install bumblebee bumblebee-nvidia bbswitch-dkms
# Reboot
# Intel-virtual-output tool
# First, you will need latest xf86-video-intel driver installed (2.99). Ubuntu 13.10 comes with it,
# so you don’t need to update driver in that case. However, what made all of this possible is the
# latest release of intel-virtual-output tool, which comes bundled with xf86-video-intel driver
# source. But, ubuntu’s package does not bundle it, and we need to compile it from source. One
# MAJOR thing to note here is: DO NOT compile it from ubuntu’s deb-src package. That package is old,
# and current release has some major fixes for the tool that we will actually need in order to have
# everything working properly. So lets do it:
sudo apt-get install xorg-dev git autoconf automake libtool
cd /usr/src
git clone git://anongit.freedesktop.org/xorg/driver/xf86-video-intel
cd xf86-video-intel
./autogen.sh
cd tools
make
sudo cp intel-virtual-output /usr/bin/
sudo chmod +x /usr/bin/intel-virtual-output
# Install scripts listed in this Gist and augtool:
sudo vim /usr/local/bin/nvidia-enable
sudo chmod +x /usr/local/bin/nvidia-enable
sudo vim /usr/local/bin/nvidia-disable
sudo chmod +x /usr/local/bin/nvidia-disable
sudo mkdir -p /etc/bumblebee/dual-monitor
sudo vim /etc/bumblebee/dual-monitor/enable.aug
sudo vim /etc/bumblebee/dual-monitor/disable.aug
sudo apt-get install augeas-tools
# Done, now enable external monitors with: `nvidia-enable` and disable with `nvidia-enable` command
#!/bin/bash
PID=$(ps ax | grep Xorg | grep :8 | grep -v grep | awk '{print $1}')
# Kill the second X server.
if [ ! -z $PID ]; then
sudo kill -15 $PID
fi
# Now you need to turn off nvidia card completely.
if lsmod | grep -q nvidia; then
sudo rmmod nvidia
fi
sudo tee /proc/acpi/bbswitch <<<OFF
sudo augtool --noload --file /etc/bumblebee/dual-monitor/disable.aug
sudo service bumblebeed restart
#!/bin/bash
sudo augtool --noload --file /etc/bumblebee/dual-monitor/enable.aug
sudo modprobe bbswitch
optirun true
intel-virtual-output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment