There is a similar question and I have been following this answer here on askubuntu: https://askubuntu.com/a/1158183/254943. This solution worked exactly as I want. Sadly after the most recent update, the solution stopped working and Xorg is now using nvidia again.
- | NVIDIA-SMI 450.66 Driver Version: 450.66 CUDA Version: 11.0 |
- Linux XXX 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
- plasmashell 5.18.5 | Qt: 5.12.8 | KDE Frameworks: 5.68.0 | kf5-config: 1.0
$ cat /usr/share/X11/xorg.conf.d/11-nvidia-prime.conf
# DO NOT EDIT. AUTOMATICALLY GENERATED BY gpu-manager
Section "OutputClass"
Identifier "Nvidia Prime"
MatchDriver "nvidia-drm"
Driver "nvidia"
Option "AllowEmptyInitialConfiguration"
Option "IgnoreDisplayDevices" "CRT"
# Option "PrimaryGPU" "Yes" <<< commented out
ModulePath "/x86_64-linux-gnu/nvidia/xorg"
EndSection
# added
Section "OutputClass"
Identifier "intel"
MatchDriver "i915"
Driver "modesetting"
Option "PrimaryGPU" "yes"
EndSection
I have tried to debug It by myself but I can't get it fixed.
$ nvidia-smi # shows running process /usr/lib/xorg/Xorg
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.66 Driver Version: 450.66 CUDA Version: 11.0 |
|-------------------------------+----------------------+----------------------+
| 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 GeForce GTX 105... Off | 00000000:01:00.0 Off | N/A |
| N/A 50C P8 N/A / N/A | 6MiB / 4040MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1257 G /usr/lib/xorg/Xorg 4MiB |
+-----------------------------------------------------------------------------+
Best Answer
I think have figured it out. First I have re-moved the 10-nvidia.conf file. Instead I have added a 10-intel.conf. Then I have commented out every line the 11-nvidia-prime.conf, it is basically an empty file. Since this file gets created/overwritten at every start/stop of xserver one needs to protect it with
chattr +i