Hybrid Intel/NVIDIA GPU. NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver

I’m trying to install nvidia drivers for my notebook Lenovo Legion7 on Ubuntu 18.04. My GPU is Hybrid Intel/ NVIDIA GeForce RTX3060 and the last driver is 470. So I tried different ways to install the driver via downloading the driver (.run) from official NVIDIA site, from Software&Update, installing from terminal. But when try:

nvidia-smi

Got the error:

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

I think that the problem is that I have Hybrid GPU on my laptop. I run:

sudo lspci -nnk | grep -iA3 vga

The result is:

00:02.0 VGA compatible controller [0300]: Intel Corporation Device [8086:9a60] (rev 01)
    Subsystem: Lenovo Device [17aa:3f80]
    Kernel modules: i915
00:04.0 Signal processing controller [1180]: Intel Corporation Device [8086:9a03] (rev 05)
--
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:2560] (rev a1)
    Subsystem: Lenovo Device [17aa:3f80]
    Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia
01:00.1 Audio device [0403]: NVIDIA Corporation Device [10de:228e] (rev a1)

Another thing when I reboot Ubuntu (18.04) it can not start. There appears the message:

/dev/nvme0n1p6: clean, 552599/6111232 files, 7119295/24414464 blocks

Then I pres Ctrl + Shift + F3:

sudo prime-select intel

After that the notebook starts. When it have been started I change the main gpu to nvidia:

sudo prime-select nvidia

The error is the same when trying nvidia-smi
Any suggestions?
P.S. Secure Boot is disabled and nomodeset parameter is not the problem too. When run:

sudo nano /etc/default/grub

It can be seen the row:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

In the failed state switch to a terminal

and then as root run nvidia-bug-report.sh and post the resulting file here.
Also show the output of:
grep -ri nvidia /etc/modprobe.d/

The output is:

/etc/modprobe.d/blacklist-framebuffer.conf:blacklist nvidiafb

And bug report
nvidia-bug-report.log.gz (102.3 KB)

I think your kernel version is too old for that new notebook. Not even the integrated GPU is supported. Get a kernel v5.10 or higher.
I’d install Ubuntu 20. And then a newer kernel. If Ubuntu 20 is not an option, still go for a newer kernel.
Make sure you have the kernel headers installed. Then better use this ppa:

Never use the .run file!
If you don’t want to install Ubuntu 20, then run the .run file with the --uninstall option.
Then sudo apt purge nvidia* libnvidia*.
The steps below are also for Ubuntu 20, if you choose to install it.
Install a newer kernel und headers.
Then add the ppa and run sudo apt install nvidia-driver-470.
Then sudo prime-select nvidia and reboot.
If it’s not working, create a new bug report.

I want to remain on Ubuntu 18.04. I’ve tried to install severall types of kernels 5.14.7, 5.14.8 and 5.10. When I try to install kernel 5.10 there is the following error:

Selecting previously unselected package linux-headers-5.10.0-051000.
(Reading database ... 171407 files and directories currently installed.)
Preparing to unpack linux-headers-5.10.0-051000_5.10.0-051000.202012132330_all.deb ...
Unpacking linux-headers-5.10.0-051000 (5.10.0-051000.202012132330) ...
Selecting previously unselected package linux-headers-5.10.0-051000-generic.
Preparing to unpack linux-headers-5.10.0-051000-generic_5.10.0-051000.202012132330_amd64.deb ...
Unpacking linux-headers-5.10.0-051000-generic (5.10.0-051000.202012132330) ...
Selecting previously unselected package linux-image-unsigned-5.10.0-051000-generic.
Preparing to unpack linux-image-unsigned-5.10.0-051000-generic_5.10.0-051000.202012132330_amd64.deb ...
Unpacking linux-image-unsigned-5.10.0-051000-generic (5.10.0-051000.202012132330) ...
Selecting previously unselected package linux-modules-5.10.0-051000-generic.
Preparing to unpack linux-modules-5.10.0-051000-generic_5.10.0-051000.202012132330_amd64.deb ...
Unpacking linux-modules-5.10.0-051000-generic (5.10.0-051000.202012132330) ...
Setting up linux-headers-5.10.0-051000 (5.10.0-051000.202012132330) ...
Setting up linux-headers-5.10.0-051000-generic (5.10.0-051000.202012132330) ...
/etc/kernel/header_postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.10.0-051000-generic

Kernel preparation unnecessary for this kernel.  Skipping...
applying patch disable_fstack-clash-protection_fcf-protection.patch...patching file Kbuild
Hunk #1 succeeded at 82 (offset 11 lines).


Building module:
cleaning build area...
unset ARCH; [ ! -h /usr/bin/cc ] && export CC=/usr/bin/gcc; env NV_VERBOSE=1 'make' -j16 NV_EXCLUDE_BUILD_MODULES='' KERNEL_UNAME=5.10.0-051000-generic IGNORE_XEN_PRESENCE=1 IGNORE_CC_MISMATCH=1 SYSSRC=/lib/modules/5.10.0-051000-generic/build LD=/usr/bin/ld.bfd modules......
Signing module:
 - /var/lib/dkms/nvidia-srv/470.57.02/5.10.0-051000-generic/x86_64/module/nvidia-modeset.ko
 - /var/lib/dkms/nvidia-srv/470.57.02/5.10.0-051000-generic/x86_64/module/nvidia.ko
 - /var/lib/dkms/nvidia-srv/470.57.02/5.10.0-051000-generic/x86_64/module/nvidia-peermem.ko
 - /var/lib/dkms/nvidia-srv/470.57.02/5.10.0-051000-generic/x86_64/module/nvidia-uvm.ko
 - /var/lib/dkms/nvidia-srv/470.57.02/5.10.0-051000-generic/x86_64/module/nvidia-drm.ko
Secure Boot not enabled on this system.
cleaning build area...

DKMS: build completed.

nvidia.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.10.0-051000-generic/updates/dkms/

nvidia-modeset.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.10.0-051000-generic/updates/dkms/

nvidia-drm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.10.0-051000-generic/updates/dkms/

nvidia-uvm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.10.0-051000-generic/updates/dkms/

nvidia-peermem.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.10.0-051000-generic/updates/dkms/

depmod...

DKMS: install completed.
   ...done.
Setting up linux-modules-5.10.0-051000-generic (5.10.0-051000.202012132330) ...
Setting up linux-image-unsigned-5.10.0-051000-generic (5.10.0-051000.202012132330) ...
I: /vmlinuz.old is now a symlink to boot/vmlinuz-5.4.0-86-generic
I: /initrd.img.old is now a symlink to boot/initrd.img-5.4.0-86-generic
I: /vmlinuz is now a symlink to boot/vmlinuz-5.10.0-051000-generic
I: /initrd.img is now a symlink to boot/initrd.img-5.10.0-051000-generic
Processing triggers for linux-image-unsigned-5.10.0-051000-generic (5.10.0-051000.202012132330) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.10.0-051000-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.10.0-051000-generic
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8125b-2.fw for module r8169
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.10.0-051000-generic
Found initrd image: /boot/initrd.img-5.10.0-051000-generic
Found linux image: /boot/vmlinuz-5.4.0-86-generic
Found initrd image: /boot/initrd.img-5.4.0-86-generic
Found linux image: /boot/vmlinuz-5.4.0-84-generic
Found initrd image: /boot/initrd.img-5.4.0-84-generic
Found Windows Boot Manager on /dev/nvme0n1p2@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for EFI firmware configuration
done

When try to install the 5.14.7 or 5.14.8 there is the next error:

ERROR (dkms apport): kernel package linux-headers-5.14.7-051407-generic is not supported

So the kernels 5.14.7 or 5.14.8 are not supported. Is there some way to install 5.10 or I should switch to Ubuntu 20.04?

I don’t see an error with the 5.10 kernel installation. All looks good from what I can tell.

When reboot there is the error.

Thats first errors of the BIOS (check for an update).
Then your firmware files are too old. You could get the iwlwifi files from the url provided.
Still newer OS would help.

Re-reading your initial post… did you uninstall the files of the .run file installer using the --uninstall parameter?
If not do so, and then re-install the nvidia driver from ppa.

Also this firmware seems too old.

I’ve purged the old drivers

apt purge nvidia* libnvidia*.

Upgraded ubuntu to 20.04. The firmware now is

linux-firmware-xilinx-vcu/focal-updates,focal-updates 2020.2-0ubuntu1~20.04.1 all
linux-firmware/focal-updates,focal-updates,now 1.187.17 all [installed,automatic]

Bios version is H1CN33WW release date 07/18/2021.
Then stalled the drivers

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt install nvidia-driver-470

And the error is the same

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

Bug report is attached. nvidia-bug-report.log.gz (107.5 KB)

There is no sign of the driver installation and/or it trying to load.
Do you have the kernel-headers package installed?
What’s the output of: dkms status?

nvidia, 470.74: added

It should say “installed”.

So do you have the kernel-headers for your kernel installed?

I checked and when installed nvidia drivers I had some broken dependencies and ran:

apt --fix-broken install

and headears were deleted.
I’ve tried:

sudo apt install linux-headers-$(uname -r)

(I have kernel version 5.14.8-051408-generic) got:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package linux-headers-5.14.8-051408-generic is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'linux-headers-5.14.8-051408-generic' has no installation candidate

Well you need the kernel headers in order to build the nvidia kernel modules.
Solve that and then run:
sudo dkms autoinstall -m nvidia -v 470.74 -k $(uname -r)

I installed Ubuntu from USB (last time I upgraded it from Ubuntu 18.04) and now have the kernel version. 5.11.0-36-generic. Added the repository and and installed driver:

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt install nvidia-driver-470

nvidia is installed:

nvidia, 470.74, 5.11.0-36-generic, x86_64: installed

Reboot and Ubuntu failed to start, I ran the script and bug report is in the attachment.nvidia-bug-report.log.gz (315.1 KB)

So to enter at the start I press Ctrl+Alt+F3 and selected intel

sudo prime-select intel

After that reboot. Tried nvidia-smi and got the same error that NVIDIA-SMI has failed ...
I’ve changed the prime-select to nvidia:
sudo prime-select nvidia
and reboot. And it works!
Thank’s a lot for your patience. Finally it’s done!