Switching between Intel and NVIDIA graphics processors on a laptop with NVIDIA Optimus hardware running Gentoo Linux
July 1, 2015 14 Comments
I have a Clevo W230SS laptop with an Intel HD 4600 IGP and an NVIDIA GeForce GTX 860M GPU, running KDE in Gentoo Linux. I could have installed Bumblebee in order to use the NVIDIA GPU with selected applications, but I decided instead to switch manually between the graphics processors. To achieve this I created two Desktop Configuration Files with nice icons on my Desktop, to launch two simple Bash scripts which configure my installation for the desired graphics processor, which will then be used when I next login to KDE. All the necessary files are listed below for Gentoo Linux. You would need to modify them if you are using a different distribution.
The Bash script ~/intel.sh
contains the following:
#!/bin/bash echo echo "Your installation is currently configured to use the following graphics processor:" echo GPU=`eselect opengl list | grep \* | awk '{ print $2 }'` if [ "$GPU" = "xorg-x11" ]; then echo "Intel HD 4600 Integrated Graphics Processor" echo echo "You do not need to do anything. Please close this window." elif [ "$GPU" = "nvidia" ]; then echo "NVIDIA GeForce GTX 860M" echo echo "This script will configure your installation to use the" echo "Intel HD 4600 Integrated Graphics Controller all the time." echo echo "Enter your own password." echo sudo eselect opengl set xorg-x11 sudo cp /home/fitzcarraldo/Xsetup.intel /usr/share/config/kdm/Xsetup sudo cp /home/fitzcarraldo/xorg.conf.intel /etc/X11/xorg.conf echo echo "Now you should logout to restart X Windows." fi
The Bash script ~/nvidia.sh
contains the following:
#!/bin/bash echo echo "Your installation is currently configured to use the following graphics processor:" echo GPU=`eselect opengl list | grep \* | awk '{ print $2 }'` if [ "$GPU" = "nvidia" ]; then echo "NVIDIA GeForce GTX 860M" echo echo "You do not need to do anything. Please close this window." elif [ "$GPU" = "xorg-x11" ]; then echo "Intel HD 4600 Integrated Graphics Processor" echo echo "This script will configure your installation to use the NVIDIA GeForce GTX 860M GPU all the time." echo echo "Enter your own password." echo sudo eselect opengl set nvidia sudo cp /home/fitzcarraldo/Xsetup.nvidia /usr/share/config/kdm/Xsetup sudo cp /home/fitzcarraldo/xorg.conf.nvidia /etc/X11/xorg.conf echo echo "Now you should logout to restart X Windows." fi
I created two files, xorg.conf.intel
and xorg.conf.nvidia
, in my home directory. The corresponding Bash script copies the applicable file to the directory /etc/X11/
to create an xorg.conf
file with the correct contents for the graphics processor.
The file ~/xorg.conf.intel
contains the following:
Section "Device" Identifier "Intel Graphics" Driver "intel" Option "AccelMethod" "sna" Option "TearFree" "true" EndSection
The file ~/xorg.conf.nvidia
contains the following:
Section "ServerLayout" Identifier "Layout0" Screen 0 "nvidia" 0 0 Inactive "intel" EndSection Section "Monitor" Identifier "Monitor0" Option "DPMS" EndSection Section "Device" Identifier "nvidia" Driver "nvidia" BusID "PCI:1:0:0" EndSection Section "Device" Identifier "intel" Driver "modesetting" BusID "PCI:0:2:0" EndSection Section "Screen" Identifier "nvidia" Device "nvidia" Monitor "Monitor0" DefaultDepth 24 Option "UseDisplayDevice" "none" SubSection "Display" Depth 24 # Modes "nvidia-auto-select" Virtual 1920 1080 EndSubSection EndSection Section "Screen" Identifier "intel" Device "intel" Monitor "Monitor0" EndSection
I created two files, Xsetup.intel
and Xsetup.nvidia
, in my home directory. The corresponding Bash script copies the applicable file to the directory /usr/share/config/kdm/
to create an Xsetup
file with the correct contents for the graphics processor.
The file ~/Xsetup.intel
is listed below. As you can see, everything is commented out in the file.
#! /bin/sh # Xsetup - run as root before the login dialog appears #xconsole -geometry 480x130-0-0 -notify -verbose -fn fixed -exitOnFail -file /dev/xconsole &
The file Xsetup.nvidia
is listed below. As you can see, it contains two xrandr
commands.
#! /bin/sh # Xsetup - run as root before the login dialog appears #xconsole -geometry 480x130-0-0 -notify -verbose -fn fixed -exitOnFail -file /dev/xconsole & xrandr --setprovideroutputsource modesetting NVIDIA-0 xrandr --auto
I downloaded nice icons from the Web for the Desktop Configuration Files and put them in the directory ~/Pictures/Icons/
.
The file ~/Desktop/Select\ Intel\ HD\ Graphics.desktop
is listed below.
[Desktop Entry] Comment[en_GB]=Run a script to configure your installation to use Intel Integrated Graphics when you restart X Windows Comment=Run a script to configure your installation to use Intel Integrated Graphics when you restart X Windows Exec=/home/fitzcarraldo/intel.sh GenericName[en_GB]=Configure your installation to use Intel HD Graphics GenericName=Configure your installation to use Intel HD Graphics Icon=/home/fitzcarraldo/Pictures/Icons/intel_hd_graphics_icon.png MimeType= Name[en_GB]=Intel HD Graphics Name=Intel HD Graphics Path= StartupNotify=true Terminal=true TerminalOptions=\s--noclose Type=Application X-DBUS-ServiceName= X-DBUS-StartupType=none X-KDE-SubstituteUID=false X-KDE-Username=fitzcarraldo
The file ~/Desktop/Select\ NVIDIA\ GPU.desktop
is listed below.
[Desktop Entry] Comment[en_GB]=Run a script to configure your installation to use the NVIDIA GeForce GTX 860M GPU when you restart X Windows Comment=Run a script to configure your installation to use the NVIDIA GeForce GTX 860M GPU when you restart X Windows Exec=/home/fitzcarraldo/nvidia.sh GenericName[en_GB]=Configure your installation to use the NVIDIA GeForce GTX 860M GPU GenericName=Configure your installation to use the NVIDIA GeForce GTX 860M GPU Icon=/home/fitzcarraldo/Pictures/Icons/nvidia_icon.png MimeType= Name[en_GB]=NVIDIA GPU Name=NVIDIA GPU Path= StartupNotify=true Terminal=true TerminalOptions=\s--noclose Type=Application X-DBUS-ServiceName= X-DBUS-StartupType=none X-KDE-SubstituteUID=false X-KDE-Username=fitzcarraldo
Don’t forget to make all the Bash script files and .desktop
files executable. All I have to do is double-click on either icon on the Desktop and a Konsole window pops up and tells me what to do. Next time I log in, the graphics processor I selected will be active.
My thanks go to Gentoo Linux user arthanis for showing me the way in the Gentoo Forums thread [SOLVED] Optimus and Nvidia.
Update (September 24, 2016): I upgraded xorg-server from 1.17.4 to 1.18.4 today and had to change the following line in /etc/X11/xorg.conf:
Screen 0 "nvidia" 0 0
to:
Screen 1 "nvidia" 0 0
See the Gentoo Forums post What’s up with xorg-server 1.18 and Optimus? for further details
Update (September 6, 2017): KDM is not used for KDE Plasma 5, so the line in the Bash scripts ~/intel.sh
and ~/nvidia.sh
to copy a file to /usr/share/config/kdm/Xsetup
can be deleted. However, the replacement Display Manager needs to be configured to cater for the NVIDIA GPU and Intel HD Graphics. I use LightDM on my Clevo W230SS laptop that has Optimus hardware, and the method of configuring LightDM to cater for the two different graphics processors is given in my blog post Getting KDE Plasma 5 to work with the NVIDIA closed-source driver in Gentoo Linux.
Hallo Fitz.
Really sorry to bother you. I have found your description to switch from Intel to NVidia (Optimus) with scripts via Google search. I’m using Sabayon 15.08 with KDE 4.14.10.
I have a core i7-4510 with build in HD4400 and a second NVidia Geforce 840M.
I copied your files onto the appropriate locations on my notebook and changed my username in the batches only. I could start nvidia.sh, and received the massage to log out. I logged out then and expected the Login screen (again). Instead a new login window the screen went black and blank with a blinking cursor up left in first line.
As root I have checked, xorg.conf.nvidia was copied to /etc/X11/xorg.conf and and also /usr/share/config/kdm/Xsetup (including xrandr commands).
My Optimus works fine with bumblebee (optirun, primusrun). Here I can switch and run (e.g.) Unigine Heaven much faster than with Intel.
So, what can I do else to run pure nvidia?
Thank you for your any support, really.
-Linuxfluesterer (I’m member of Sabayon forum)
Check your Bus IDs, as they may be different to mine. Use the
lspci
command as root user to see what your Bus IDs are for the NVIDIA GPU and Intel IGP.Thanks for your reply, Fitz. I have checked: This is (I assume) same as you have:
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
and
01:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 840M] (rev ff)
As of now, I have no second monitor connected on HDMI, which I finally want to run with the NVidia graphics.
-Linuxfluesterer
You need to have your kernel configured appropriately, and also the correct parameters specified in the kernel boot line in the file
grub.cfg
. See under X Windows and NVIDIA Optimus in my earlier post A new laptop.Below is an excerpt from the kernel configuration in my Gentoo installation, although I have no idea if all of them are relevant here or if the list is exhaustive.
I don’t know what Sabayon Linux has, but in my Gentoo Linux installation I have the following in the file
/etc/default/grub
(the file/etc/default/sabayon-grub
in your case) which I used to generate the filegrub.cfg
:I created the EDID firmware file by following the instructions from the Gentoo Wiki article (see my above-mentioned post for the link).
Hallo Fitz.
After I was busy in last days, I have tried to understand the way to create my own EDID binary fimware file today. I’m honest: That’s too complicated, I don’t get it (for my Sabayon). So, I’ll stop here. Maybe in future there will be a simpler way in Linux Kernel or a tool similar to nvidiasetup to activate and adopt the necessary steps. I mean, if bumblee switching already works, then it should be possible at all in general. Or am I wrong?
At any rate, thank you for your support.
-Linuxfluester
Why do you think it is difficult to create the EDID firmware file? According to the Gentoo Wiki article I mentioned earlier, it should be straightforward if the driver can actually read an EDID from the monitor:
# emerge --ask x11-misc/read-edid
# get-edid > /lib/firmware/edid/1920x1080_Clevo_W230SS.bin
As I have a Clevo W230SS laptop, I named the firmware file
1920x1080_Clevo_W230SS.bin
but it could have any name.The package
x11-misc/read-edid
exists in Sabayon Linux, so you should be able to generate the firmware file:# equo install read-edid
# mkdir /lib64/firmware/edid
# get-edid > /lib/firmware/edid/any_name_you_want.bin
Thank you again, Fitz.
Exactly, the edid is not the real problem. It is to compile the Kernel with my Sabayon. I have tried some month before, but there were only errors, I even could not execute “make menuconfig” so that I could change the .config parameters. And yes, I have downloaded “sys-kernel/sabayon-sources” before.Many years ago (maybe 10?) I have compiled some own kernels with SuSE distros. That worked. But with Sabayon I haven’t had that luck.
This is the complicated part I really can not solve, and it will have to be repeated then for every patch or mainline of a new kernel.
In my Sabayon, /usr/src/linux-sabayon-4.1.0/.config the differences to your settings for grub-changes are:
CONFIG_DRM=m
CONFIG_DRM_KMS_HELPER=m
# CONFIG_DRM_LOAD_EDID_FIRMWARE is not set
CONFIG_DRM_I915=m
CONFIG_SND_HDA=m
CONFIG_AGP=m
CONFIG_AGP_INTEL=m
# CONFIG_RCU_FANOUT_NO_HZ is not set
CONFIG_RCU_CPU_STALL_TIMEOUT=60
…the other lines are identical to yours…
-Linuxfluesterer
Pingback: Getting KDE Plasma 5 to work with the NVIDIA closed-source driver in Gentoo Linux | Fitzcarraldo's Blog
Pingback: Text too small in X Windows when using nvidia-drivers | Fitzcarraldo's Blog
My slightly-updated files since my 2015 blog post, now that I am using KDE Plasma 5 rather than KDE 4:
intel.sh
nvidia.sh
Xsetup.intel
Xsetup.nvidia
xorg.conf.intel
xorg.conf.nvidia
Select Intel HD Graphics.desktop
Select NVIDIA GPU.desktop
You also need to configure the Desktop Manager to work with Optimus hardware. If you use KDE Plasma 5, I could not get SDDM to work with the Optimus hardware despite following the Gentoo Wiki to the letter, so I switched to LightDM which works fine both with the NVIDIA GPU and the Intel HD Graphics processor providing it is configured as explained in my blog post: Getting KDE Plasma 5 to work with the NVIDIA closed-source driver in Gentoo Linux (see the Comments section of that post for my latest steps).
Pingback: Gentoo Linux: A work-around to be able to Resume from Suspend to RAM when using the NVIDIA closed-source driver | Fitzcarraldo's Blog
I came across this post looking for a solution for an issue I have on a windows laptop that is the same as yours. I don’t suppose you run this laptop on windows by any chance because I cannot get the 860m to work on either 8.1 or windows 10.
I am unable to help you, as I have never had Windows installed on this laptop.
Pingback: Migrating to libglvnd in Gentoo Linux on a laptop with NVIDIA Optimus | Fitzcarraldo's Blog