Intle i7 and RTX 3060 Notebook with ubuntu 22.04 external screen dont work

I am using Lenovo Legion 5 with Intel i7 and RTX 3060 Notebook with dual boot windows 11 and Ubuntu 22.04 with kernal 6.5.0-14-generic

>> sudo lshw -C display
[sudo] password for ahmedelfateh: 
  *-display                 
       description: VGA compatible controller
       product: GA106M [GeForce RTX 3060 Mobile / Max-Q]
       vendor: NVIDIA Corporation
       physical id: 0
       bus info: pci@0000:01:00.0
       logical name: /dev/fb0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress vga_controller bus_master cap_list rom fb
       configuration: depth=32 driver=nvidia latency=0 mode=1920x1080 visual=truecolor xres=1920 yres=1080
       resources: iomemory:600-5ff iomemory:600-5ff irq:186 memory:60000000-60ffffff memory:6000000000-600fffffff memory:6010000000-6011ffffff ioport:5000(size=128) memory:61000000-6107ffff
  *-display
       description: VGA compatible controller
       product: Alder Lake-P Integrated Graphics Controller
       vendor: Intel Corporation
       physical id: 2
       bus info: pci@0000:00:02.0
       logical name: /dev/fb0
       version: 0c
       width: 64 bits
       clock: 33MHz
       capabilities: pciexpress msi pm vga_controller bus_master cap_list rom fb
       configuration: depth=32 driver=i915 latency=0 resolution=1920,1080
       resources: iomemory:620-61f iomemory:400-3ff irq:184 memory:6203000000-6203ffffff memory:4000000000-400fffffff ioport:6000(size=64) memory:c0000-dffff memory:4010000000-4016ffffff memory:4020000000-40ffffffff

>> lspci -k | grep -EA3 'VGA|3D|Display'
00:02.0 VGA compatible controller: Intel Corporation Alder Lake-P Integrated Graphics Controller (rev 0c)
	Subsystem: Lenovo Device 3831
	Kernel driver in use: i915
	Kernel modules: i915
--
01:00.0 VGA compatible controller: NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile / Max-Q] (rev a1)
	Subsystem: Lenovo GA106M [GeForce RTX 3060 Mobile / Max-Q]
	Kernel driver in use: nvidia
	Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidi

I used this doc to install the driver https://ubuntu.com/server/docs/nvidia-drivers-installation
and tried to run nvidia-smi was not working then tried to run sudo nvidia-bug-report.sh to get the report but something strange happened the external screen worked and the laptop screen went black and wen I tried to restart the laptop the screens went like before external black and the laptop is working and I can see in the setting view the Graphics: Mesa Intel® Graphics (ADL GT2) with X11.

>> nvidia-smi
Sun Jan 14 16:39:14 2024       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.146.02             Driver Version: 535.146.02   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| 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 RTX 3060 ...    Off | 00000000:01:00.0 Off |                  N/A |
| N/A   31C    P8               9W /  80W |      0MiB /  6144MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|  No running processes found                                                           |
+---------------------------------------------------------------------------------------+

here is the result of the command, and it will be great if you can help.

So something new happened, it is not a fix or anything but may give a clue about what is happening.

I decided to install Ubuntu again be it fix the problem, so I made the flash disk first boot and did not but it the boot for the Lenovo tried to access and failed so it went for the second option which the install Ubuntu. so it wrote the pass and the two screens were working and the Nvidia X server is showing both screen’s data.

I think it will be useful to know that I set Wayland to true in the /etc/gdm3/custom.conf
but even though it is still X11 in the setting view, when I tried to set it to false the external screen went black again.

So if this can help to lead to why this is happening it will be great.

to make this thread more like a docs, for anyone who has the same case.
the problem: I had Ubuntu 22.04 installed on this machine for 6 months or so, two days ago I shut it down for the weekend and then tried to open the laptop the external screen was blacked out and did not show on the monitors tab in the settings.
what I tried in steps:
1- install Ubuntu 22.04 on Legion 5 Intel i7 and RTX 3060 Notebook BIOS GKCN60WW and Kernal 6.5.0-14-generic with the Secure Boot=false from the BIOS.
2- after I tried to install the Nvidia driver from the GUI it was v535 the install from the GUI went ok, but the setting view did not affect and nvidia-smi did not return any data, so I restarted the laptop. and after nothing changed.
3- I tried a lot of things as I wrote in the two comments in this thread and the very weird thing is the inconsistency of the results so I tried a command and restarted when the laptop was up everything is working as expected and the two screens are working and the setting view showing that it has the correct Nvidia card driver, so I restart for another update or so and when the laptop is up everything returned to the first state.
4- there are no clear steps for this problem to be fixed because not all people on the internet have the same machine and install the same distro or even have the same process and Nvidia version, so some say the problem is with the kernel and some say with the BIOS and some with the driver itself. I don’t know what is the problem but I managed to find some Lenove docs for installing Ubuntu 18.04 on two different machines
a- https://download.lenovo.com/pccbbs/mobiles_pdf/thinkpad_p43s_p53s_ubuntu_installation_whitepaper_v1.0.pdf
b- https://download.lenovo.com/pccbbs/mobiles_pdf/tp_p1_gen2_ubuntu_18.04_lts_installation_v1.0.pdf
c- and this thread on Lenovo support forms English Community-Lenovo Community
5- I tried the steps they used and managed to make everything work continuously the two screens and nvidia-smi command are working and the Nvidia X server is detecting the two screens and the setting view is showing the correct driver name NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile / Max-Q].

🟢The Solution:
➡️ Display=Discrete Graphics
1- Boot into BIOS, tab over to the “Config” menu option, and select the “Display” option
2- The Graphics Device will likely be set to Hybrid Graphics. To run exclusively Nvidia
graphics set the “Graphics Device” to “Discrete Graphics”.

🔴 The Problem:
this fix is disabling the intel integrated Graphics, and this is affecting -as I think because I am still trying- the battery life and some video and audio rendering and even the ML Enginers may need it for their work.
For me, I am usually plugged in and don’t do this advanced rendering and don’t work with ML.
But for sure this is not a good solution because everything is meant to work correctly. After all, my case is not everyone’s case.

So I still try to find some solution with a different tradeoff but disabling one of my two graphic cards. hope this helped some one and hope if any one finds a better solution add it to this thread.

This is a some machine specific bug with Linux kernels >6.3, there’s a thread from another user with the same issue.

[    4.556322] NVRM: GPU 0000:01:00.0: RmInitAdapter failed! (0x24:0x72:1436)

https://forums.developer.nvidia.com/t/no-hdmi-in-nvidia-on-demand-mode-since-kernel-6-4-x/278051?u=generix

so from your answer

it is something related to Lenovo and Ubuntu teams, yes?

Now a third ubuntu user with a Dell notebook showed up. So I guess you should also report it to Ubuntu kernel team.