Skip to content

Instantly share code, notes, and snippets.

@alexlee-gk
Last active March 19, 2024 17:47
Show Gist options
  • Save alexlee-gk/76a409f62a53883971a18a11af93241b to your computer and use it in GitHub Desktop.
Save alexlee-gk/76a409f62a53883971a18a11af93241b to your computer and use it in GitHub Desktop.
Use integrated graphics for display and NVIDIA GPU for CUDA on Ubuntu 14.04

This was tested on a ThinkPad P70 laptop with an Intel integrated graphics and an NVIDIA GPU:

lspci | egrep 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation Device 191b (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM204GLM [Quadro M3000M] (rev a1)

A reason to use the integrated graphics for display is if installing the NVIDIA drivers causes the display to stop working properly. In my case, Ubuntu would get stuck in a login loop after installing the NVIDIA drivers. This happened regardless if I installed the drivers from the "Additional Drivers" tab in "System Settings" or the ppa:graphics-drivers/ppa in the command-line.

The solution is described in the answer from this post.

Install the NVIDIA drivers

Download the driver installation runfile from their website (e.g. the 375.26 driver runfile). Run the script with the option --no-opengl-files:

sudo ./NVIDIA-Linux-x86_64-375.26.run --no-opengl-files

Reboot.

Install CUDA

Download the CUDA installation runfile from their website. It's important to download the "runfile (local)" file so that we can explicitly prevent from overwriting the driver that was just installed. Run the script:

sudo ./cuda_8.0.44_linux.run 

Respond "no" when asked "Install NVIDIA accelerated Graphics Driver for Linux-x86_65 375.26?".

Configure xorg.conf

Modify or create the file /etx/X11/xorg.conf to specify that the NVIDIA GPU should be used for a secondary screen so that it has entries in nvidia-settings. Mine looks like this:

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "intel"
    Screen 1 "nvidia"
EndSection

Section "Device"
    Identifier "intel"
    Driver "intel"
    BusID "PCI:0@0:2:0"
    Option "AccelMethod" "SNA"
EndSection

Section "Screen"
    Identifier "intel"
    Device "intel"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1@0:0:0"
    Option "ConstrainCursor" "off"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    Option "AllowEmptyInitialConfiguration" "on"
    Option "IgnoreDisplayDevices" "CRT"
EndSection

The BusID should match what the lspci command above returned.

Reboot.

Miscellaneous tips

If installing the NVIDIA drivers messes up the OS (e.g. it gets stuck in a login loop or it shows a black screen before the login step), you can uninstall the drivers by openning a console with Ctrl-Alt-F1 and running:

sudo apt-get remove --purge nvidia-*
sudo apt-get autoremove
echo "nouveau" | sudo tee -a /etc/modules

Reboot.

@cjmcclellan
Copy link

This was a really good solution. However there are a few mistakes I had to fix before it worked for me. My system, Intel i5-4690K, Nvidia RTX 2080 Ti, Nvidia-410 driver installed from the Graphics PPA, CUDA 10 installed using the local deb file (off Nvidia website), and Ubuntu 18.04

I followed the instructions but was having the same issue as @jclevesque (but creating xorg.conf in etc/X11/). The issue was that the BusID was wrong in the above example as @falaktheoptimist pointed out. Once I changed the BusID to "PCI:1@1:0:0" everything worked. :)

@agisubagio
Copy link

agisubagio commented Jan 3, 2019

I have an old mainboard with ATI ES1000 onboard. I add 4 GTX 1060 3GB to that mainboard as a CUDA compute, but still want to see my ubuntu desktop from onboard VGA. Do you have any recommedation for xorg.conf and nvidia-settings?

@pulver22
Copy link

pulver22 commented Jan 16, 2019

I modify the xorg.conf but after rebooting the laptop it turns back to its default config. It may be overwritten by the nvidia-setting. How can I avoid that? Did it happen to someone else?

Edit: I must say that I installed the nvidia driver from the "additional drivers" applet and not the .run downloaded from the web.

@pgbarletta
Copy link

Thanks for this. Worked like a charm.

@sausthapit
Copy link

Wow, thanks for posting this. For me the /etc/X11/xorg.conf (Ubuntu 18.04) wasn't there so created a new one and it worked.

@hdsingh
Copy link

hdsingh commented Apr 10, 2019

This did not worked for me on Ubuntu 18.04. Got stuck in infinite login loop. And even unable to open terminal (tried almost all combinations including Ctrl-Alt-F1. Then deleted xorg.conf through dual booted windows and logged in.

@LanternD
Copy link

A small tip: before you work on the nvidia driver, you can install and enable the openssh server, such that you can edit everything on another computer via SSH in the same LAN.

@lexxwork
Copy link

lexxwork commented May 24, 2019

thank you so much bro!
one more tips:
if you have a black screen or any issue with loading gui you can run a console terminal with ctrl+alt+F2 for example and login.
as aditor would advice a 'micro' (apt install micro)
to see if something changed you should run
sudo service lightdm restart to load gui session
if all is fine you should atumaticaly switch to gui session

@0x6d3f9c
Copy link

0x6d3f9c commented Aug 25, 2019

I use ArchLinux and I updated Nvidia to version 430.40 and Xorg-server to version 1.20.5, this configuration didn't work as before. Just saw black screen with cursor after Lightdm login.

Just removing all configuration about Nvidia in xorg.conf, then it worked again. It doesn't bother MATLAB to find the Nvidia driver to do
GPU computing jobs.

/etc/X11/xorg.conf

Section "ServerLayout"
Identifier "layout"
Screen 0 "intel"
EndSection

Section "Device"
Identifier "intel"
Driver "intel"
BusID "PCI:0@0:2:0"
EndSection

Section "Screen"
Identifier "intel"
Device "intel"
EndSection

PS: I first suspected the black screen should be blame to /usr/share/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf , because the configuration is setting PrimaryGPU as nvidia. I changed "yes" to "no" or setting PrimaryGPU as intel, but both had no effect.

@ulisesbussi
Copy link

I use ArchLinux and I updated Nvidia to version 430.40 and Xorg-server to version 1.20.5, this configuration didn't work as before. Just saw black screen with cursor after Lightdm login.

Just removing all configuration about Nvidia in xorg.conf, then it worked again. It doesn't bother MATLAB to find the Nvidia driver to do
GPU computing jobs.

/etc/X11/xorg.conf

Section "ServerLayout"
Identifier "layout"
Screen 0 "intel"
EndSection

Section "Device"
Identifier "intel"
Driver "intel"
BusID "PCI:0@0:2:0"
EndSection

Section "Screen"
Identifier "intel"
Device "intel"
EndSection

PS: I first suspected the black screen should be blame to /usr/share/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf , because the configuration is setting PrimaryGPU as nvidia. I changed "yes" to "no" or setting PrimaryGPU as intel, but both had no effect.

Man you saved me a lot of time! thanks for this! you're awesome

@slxu
Copy link

slxu commented Dec 5, 2019

For me, Ubuntu 16.04 did not work but Ubuntu 18.04 worked incredibly well. And my major reason of configuring to letting Intel do the display while Nvida only do the GPGPU computation is that Nvidia display eats battery so quickly. Not sure if I'm the only person suffering this issue. The fan just cannot stop spinning once Nvidia GPU is on (and really noisy by the way).

Thank you so much man! Really appreciate it.

@AlexanderStohr
Copy link

/etx/X11/xorg.conf => /etc/X11/xorg.conf

@jbozas
Copy link

jbozas commented May 6, 2020

@alexlee-gk I fkng love you bro!

After 3 days of workarounds, this worked for me. I created the xorg.conf and remove the nvidia drivers as you said. Instead of "lspci" command I used "lshw -class display".

Have a nice year!

@pigidser
Copy link

pigidser commented May 13, 2020

This worked for me. Thanks for the idea!
(my setup: Intel 630 integrated + 4 GTX1060 + 1 GTX1070 Ti)

@corndog2000
Copy link

Amazing, thank you!

@Racansky
Copy link

Hi,
I'm trying to install drivers and CUDA for Ubuntu 20.04 LTS according to your instructions, but it doesn't want to run your command
sudo *.run - reports "command not found"
according to the nVidia installation instructions for CUDA, I added the SH command, so it starts correctly, for example:
sudo sh ./NVIDIA-Linux-x86_64-450.57.run --no-opengl-files

@fxfactorial
Copy link

xorg stuff is not needed if running under ubuntu 20 with wayland

@joaomamede
Copy link

In my RHEL8 I allow gdm to select wayland even with nvidia drivers installed.
Then if I want passthrough I select xorg.
If I want nvidia only for computing I just start my session in wayland.

@dedetuga
Copy link

dedetuga commented Oct 6, 2020

Confirmed on Ubuntu 18.04LTS !!!!!

I Almost want to kiss you!!!!

...Almost...

🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇 🥇

@scaomath
Copy link

Thanks for the post. I was able to get the iGPU in 10th gen Intel running using the xorg.conf given, as well as CUDA running VSCode. However, I got all pixelated and weird color strips across the screen. So I did some Google-fu and found that in order that X works on Intel UHD 630 (8th-10th gen desktop CPU). The iGPU part needs to be changed to:

Section "Device"
    Identifier  "Intel Graphics"
    Driver      "modesetting"
    BusID       "PCI:0:2:0"
EndSection

The driver has to be modesetting which is in xserver-xorg-core. Just to be safe, it is recommended to uninstall xserver-xorg-video-intel as well.

@K4R7IK
Copy link

K4R7IK commented Aug 3, 2021

What are changes to be made to make it work on AMD (Integrated) as I have Amd/Nvidia combo with AMD as iGPU and Nvidia as dGPU

@svh-pad
Copy link

svh-pad commented Dec 14, 2021

I am using an AMD integrated GPU (on 5800H) and NVIDIA 3070 in a laptop. These instructions worked for me with the following xorg.conf:

Section "ServerLayout"
	Identifier     "layout"
	Screen      0  "amdgpu"
	Screen      1  "nvidia"
EndSection

Section "Device"
	Identifier  "amdgpu"
	Driver      "amdgpu"
	BusID       "PCI:6:0:0"
EndSection

Section "Screen"
	Identifier "amdgpu"
	Device     "amdgpu"
EndSection

Section "Device"
	Identifier  "nvidia"
	Driver      "nvidia"
	BusID       "PCI:1:0:0"
EndSection

Section "Screen"
	Identifier "nvidia"
	Device     "nvidia"
	Option     "AllowEmptyInitialConfiguration" "true"
EndSection

and with NVIDIA-Linux-x86_64-470.94.run, cuda_11.5.1_495.29.05_linux.run and the mainline 5.12 kernel on Ubuntu 20.04.

@Aviksaikat
Copy link

Aviksaikat commented Jan 4, 2022

Hi i’m using hp pavilion 15-ec2xxx

AMD Ryzen 5600H with radeon graphics + nvidia gtx 1650

I’m using parrot-lts with kde

i’m having problem while using external monitor i switched to nvidia & the external display works fine but my laptop display is blank. How to fix this? is there any way to use a hybrid system like radeon for laptop and nvidia to external monitor simultaneously like we do in windows ? or can we run both the displays on nvidia ?

~ xrandr --listproviders 
Providers: number : 2
Provider 0: id: 0x1b8 cap: 0x1, Source Output crtcs: 4 outputs: 1 associated providers: 0 name:NVIDIA-0
Provider 1: id: 0x1f7 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 1 associated providers: 0 name:Unknown AMD Radeon GPU @ pci:0000:05:00.0

nvidia-smi

Tue Jan  4 11:23:57 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.57.02    Driver Version: 470.57.02    CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0  On |                  N/A |
| N/A   45C    P8     6W /  N/A |    505MiB /  3911MiB |      9%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1238      G   /usr/lib/xorg/Xorg                224MiB |
|    0   N/A  N/A      2317      G   /usr/bin/kwin_x11                  77MiB |
|    0   N/A  N/A      2401      G   /usr/bin/plasmashell               40MiB |
|    0   N/A  N/A      2442      G   /usr/bin/latte-dock                41MiB |
|    0   N/A  N/A      2731      G   ...akonadi_archivemail_agent        1MiB |
|    0   N/A  N/A      2739      G   .../akonadi_mailfilter_agent        1MiB |
|    0   N/A  N/A      2743      G   ...n/akonadi_sendlater_agent        1MiB |
|    0   N/A  N/A      2744      G   ...nadi_unifiedmailbox_agent        1MiB |
|    0   N/A  N/A      5142      G   ...AAAAAAAAA= --shared-files       63MiB |
|    0   N/A  N/A      8915      G   /usr/bin/kitty                      2MiB |
|    0   N/A  N/A     59428      G   ...AAAAAAAAA= --shared-files       38MiB |
+-----------------------------------------------------------------------------+
~ lspci -k | grep -A 2 -E "(VGA|3D)"                                                 
01:00.0 VGA compatible controller: NVIDIA Corporation TU117M (rev a1)
	DeviceName: NVIDIA Graphics Device
	Subsystem: Hewlett-Packard Company TU117M
--
05:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne (rev c6)
	DeviceName:  Onboard IGD
	Subsystem: Hewlett-Packard Company Device 88dd

I removed the xorg.conf file but still no output on laptop display

Device info

CPU: AMD Ryzen 5 5600H with Radeon Graphics (12) @ 3.3GHz
PRETTY_NAME="Parrot OS 5.0 (LTS)"
NAME="Parrot OS"
VERSION_ID="5.0"
VERSION="5.0 (LTS)"
VERSION_CODENAME=bullseye
ID=debian

@SwaySZ
Copy link

SwaySZ commented Jan 5, 2022

FOR DESKTOP ONLY: A very straightforward way is to set the BIOS to use your onboard device (i.e., Intel graphics) if possible. Your Nvidia card will be powered but 100% idle. Tested on Intel UHD graphics 630 on Ubuntu 20.04.3, and the Nvidia driver is the latest 495.46.
See details here

@Aviksaikat
Copy link

I don't have a VGA port. I don't know what's happening with the technology . Stupid design

@imakin
Copy link

imakin commented Mar 11, 2022

thanks for sharing, it's working fine in my desktop. also if you have more gpus you could add more screen (one screen per GPU)

so this is my /etc/X11/xorg.conf

Section "ServerLayout"
        Identifier     "layout"
        Screen      0  "amdgpu"
        Screen      1  "nvidia"
EndSection

Section "Device"
        Identifier  "amdgpu"
        Driver      "amdgpu"
        BusID       "PCI:7:0:0"
EndSection

Section "Screen"
        Identifier "amdgpu"
        Device     "amdgpu"
EndSection

Section "Device"
        Identifier  "nvidia"
        Driver      "nvidia"
        BusID       "PCI:1:0:0"
EndSection

Section "Screen"
        Identifier "nvidia"
        Device     "nvidia"
        Option     "AllowEmptyInitialConfiguration" "true"
EndSection

and optionally this is my /usr/share/X11/xorg.conf.d/10-nvidia.conf with coolbits to enable clock adjustment, you can also define screen here especially if all multiple gpus are nvidia

Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "Coolbits" "12"
    ModulePath "/usr/lib/x86_64-linux-gnu/nvidia/xorg"
EndSection

@unaisp
Copy link

unaisp commented Apr 5, 2022

It worked for me in Ubuntu 20.04 with nvidia-driver-510.

PCI details:

lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller (rev 06)
05:00.0 VGA compatible controller: NVIDIA Corporation Device 2489 (rev a1)

Updated xorg.conf as follows.

$ cat /etc/X11/xorg.conf
Section "ServerLayout"
    Identifier  "layout"
    Screen 0 	"intel"
    Screen 1 	"nvidia"
EndSection

Section "Device"
    Identifier  "intel"
    Driver 	"intel"
    BusID       "PCI:0:2:0"
    Option 	"AccelMethod" "SNA"
EndSection

Section "Screen"
    Identifier  "intel"
    Device 	"intel"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver 	"nvidia"
    BusID       "PCI:5:0:0"
    Option 	"ConstrainCursor" "off"
EndSection

Section "Screen"
    Identifier  "nvidia"
    Device 	"nvidia"
    Option 	"AllowEmptyInitialConfiguration" "true"
EndSection

Updated the following file with coolbits to enable the cpu/memory/fan overclocking with nvidia-settings

$ cat /usr/share/X11/xorg.conf.d/10-nvidia.conf 
Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "Coolbits" "12"
    ModulePath "/usr/lib/x86_64-linux-gnu/nvidia/xorg"
EndSection

Currently, nvidia-smi looks as follows. All other processes including chrome, firefox, TeamViewer, and ms-teams are using integrated GPU and one of my target applications is using the dedicated Nvidia gpu.

$ nvidia-smi
Tue Apr  5 10:40:07 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.54       Driver Version: 510.54       CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:05:00.0 Off |                  N/A |
| 95%   63C    P2   159W / 160W |   5110MiB /  8192MiB |    100%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1228      G   /usr/lib/xorg/Xorg                  5MiB |
|    0   N/A  N/A      1795      G   /usr/lib/xorg/Xorg                  6MiB |
|    0   N/A  N/A      3304      C   .../t-rex-0.25.8-linux/t-rex     5093MiB |
+-----------------------------------------------------------------------------+


@haipnh
Copy link

haipnh commented Jun 28, 2022

Hi,

Here is my system. But the PCI ID of the GTX 1080 Ti randomly changes between 01:00.0 and 03:00.0 after reboot. How can I make it static?

$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Device 9bc5 (rev 05)
01:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
06:00.0 VGA compatible controller: NVIDIA Corporation Device 1f82 (rev a1)

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