Check which graphics card is being used
lspci | grep -E "VGA|3D"
To disable NOEVEAU, it needs to be blacklisted, update the configuration, and reboot the machine
sudo echo -e "blacklist nouveau\noptions nouveau modeset=0\nalias nouveau off" | sudo tee --append /etc/modprobe.d/blacklist-nouveau.conf
sudo update-initramfs -u
sudo reboot
After rebooting, check if the NOEVEAU driver is working
lsmod | grep -i nouveau
After disabling NOEVEAU, you can install the NVIDIA drivers Most likely, the drivers installed will not be the latest, but they will be stable
sudo apt-get install nvidia-driver nvidia-xconfig nvidia-prime
Check which bus the discrete graphics card is on, in order to record these values in the configuration (next step)
nvidia-xconfig --query-gpu-info | grep 'BusID'
Remember the BusID values, for example PCI:3:0:0
Xconfig is needed for the system to understand how to work with the graphics card; the following example makes the system work with the discrete graphics card.
- The configuration should be stored at the following path:
/etc/X11/xorg.conf
- Replace
PCI:x:x:x
with your own value taken from the previous step.
Section "ServerLayout"
Identifier "layout"
Screen 0 "nvidia"
Inactive "intel"
EndSection
Section "Device"
Identifier "nvidia"
Driver "nvidia"
BusID "PCI:x:x:x"
EndSection
Section "Screen"
Identifier "nvidia"
Device "nvidia"
Option "AllowEmptyInitialConfiguration"
EndSection
Section "Device"
Identifier "intel"
Driver "modesetting"
EndSection
Section "Screen"
Identifier "intel"
Device "intel"
EndSection
If you are not satisfied with this configuration, you can customize it following this instruction.
Alternatively, you can try generating the correct /etc/X11/xorg.conf
using the nvidia-xconfig
command.
nvidia-xconfig --enable-all-gpus
nvidia-xconfig --cool-bits=4
The script should fit your desktop environment. All scripts for desktop environments can be found here.
Check which DisplayManager you have
cat /etc/X11/default-display-manager
sudo nano /etc/lightdm/display_setup.sh
# Script:
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
sudo nano /usr/share/sddm/scripts/Xsetup
# Script:
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
sudo nano /usr/share/gdm/greeter/autostart/optimus.desktop
sudo nano /etc/xdg/autostart/optimus.desktop
# Script:
[Desktop Entry]
Type=Application
Name=Optimus
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"
NoDisplay=true
X-GNOME-Autostart-Phase=DisplayServer
After creating the scripts and configurations, reboot the system
sudo reboot -h now
If your system is using NVIDIA drivers, the output of the following command will be direct rendering: Yes
.
glxinfo | grep -i "direct rendering"
Now you can install CUDA
sudo apt-get install ocl-icd-libopencl1 nvidia-cuda-toolkit
If you have multiple operating systems on one machine, you need to update GRUB.
All values should be "1" (Example: PRIME Synchronization: 1
)
xrandr --verbose | grep PRIME
The GRUB configuration is located at: /etc/default/grub
You need to change the following field to the code below:
....
GRUB_CMDLINE_LINUX_DEFAULT="quiet nvidia-drm.modeset=1"
...
After saving, update GRUB
sudo update-grub
sudo reboot -h now
After rebooting, check if PRIME NVIDIA is being used
xrandr --verbose|grep PRIME
The output should be the following:
PRIME Synchronization: 1
PRIME Synchronization: 1
If you see a black screen after rebooting, you need to:
- Switch to a pseudo-graphical terminal (ALT+CTRL+F2 or ALT+CTRL+F3 and so on).
- Remove the previously created configurations; they were likely created incorrectly and are causing the display not to work.
sudo apt-get remove --purge nvidia*
sudo rm -rf /etc/X11/xorg.conf
# For LightDM
sudo rm -rf /etc/lightdm/lightdm.conf
# For SDDM
sudo rm -rf /usr/share/sddm/scripts/Xsetup
# For GDM
sudo rm -rf /usr/share/gdm/greeter/autostart/optimus.desktop
sudo rm -rf /etc/xdg/autostart/optimus.desktop
- Reboot the system
sudo reboot -h now
- Check if NOUVEAU is actually in use
lsmod | grep -i nouveau
- If it is in use, disable it by proceeding to step 2
sudo echo -e "blacklist nouveau\noptions nouveau modeset=0\nalias nouveau off" > /etc/modprobe.d/blacklist-nouveau.conf
sudo update-initramfs -u
- Reboot the system
sudo reboot -h now