Bash scripts to automate installation of NVIDIA proprietary driver

I don’t have a Optimus enabled laptop so I cannot test whether the following will work.


From the documentation of NVIDIA_GLX-1.0, I found the following:

Chapter 33 says you can use NVIDIA GPU to render images and use your integrated GPU (let’s say Intel GPU) to display images.

Create a new file /etc/X11/xorg.conf.d/20-optimus.conf with the following

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

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "<BusID for NVIDIA device here>"
EndSection

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

Section "Device"
    Identifier "intel"
    Driver "modesetting"
EndSection

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

where the <BusID for NVIDIA device here> should be replaced by the correct bus ID of your NVIDIA card. For example, on my system I have the following

❯ lspci | grep -i vga   
01:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
02:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)

I’ve two NVIDIA cards so you see two entries here. But you should only see one NVIDIA card, and let’s say it’s bus id is 01:00.0, then you should put "PCI:1:0:0" (Don’t remove the double quotes) in the 20-optimus.conf file.

The next is to use xrandr to enable displays to your intel GPU. Let’s say you use gdm which is the default display manager if you’re not using lightdm or sddm. Then create/edit the file /etc/gdm/Init/Default with the contents

xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Then you can install the NVIDIA drivers.