Nvidia-driver-470 failing on Ubuntu 20.04.2 with 5.13.8-051308-generic kernel. What to do?

My Asus laptop (ROG Strix G17 2021), which I’m trying to install the driver on, is equipped with an RTX 3070 and Ryzen 5900HX. Below is the relevant part of the installation

update-initramfs: deferring update (trigger activated)
INFO:Enable nvidia
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
Loading new nvidia-470.57.02 DKMS files...
Building for 5.13.8-051308-generic
Building for architecture x86_64
Building initial module for 5.13.8-051308-generic
ERROR (dkms apport): kernel package linux-headers-5.13.8-051308-generic is not supported
Error! Bad return status for module build on kernel: 5.13.8-051308-generic (x86_64)
Consult /var/lib/dkms/nvidia/470.57.02/build/make.log for more information.
dpkg: error processing package nvidia-dkms-470 (--configure):
 installed nvidia-dkms-470 package post-installation script subprocess returned error exit status 10
Setting up libxcb-sync1:i386 (1.14-2) ...
dpkg: dependency problems prevent configuration of nvidia-driver-470:
 nvidia-driver-470 depends on nvidia-dkms-470 (<= 470.57.02-1); however:
  Package nvidia-dkms-470 is not configured yet.
 nvidia-driver-470 depends on nvidia-dkms-470 (>= 470.57.02); however:
  Package nvidia-dkms-470 is not configured yet.

dpkg: error processing package nvidia-driver-470 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Setting up libllvm12:i386 (1:12.0.0-3ubuntu1~20.04.3) ...
Setting up libnvidia-encode-470:amd64 (470.57.02-0ubuntu0.20.04.1) ...
Setting up libxcb-dri2-0:i386 (1.14-2) ...
Setting up vdpau-driver-all:amd64 (1.3-1ubuntu2) ...
Setting up libxcb-randr0:i386 (1.14-2) ...
Setting up libx11-6:i386 (2:1.6.9-2ubuntu1.2) ...
Setting up libxcb-dri3-0:i386 (1.14-2) ...
Setting up mesa-vulkan-drivers:i386 (21.0.3-0ubuntu0.2~20.04.1) ...
Setting up libgl1-mesa-dri:i386 (21.0.3-0ubuntu0.2~20.04.1) ...
Setting up libxext6:i386 (2:1.3.4-0ubuntu1) ...
Setting up libxxf86vm1:i386 (1:1.1.4-1build1) ...
Setting up libxfixes3:i386 (1:5.0.3-2) ...
Setting up libnvidia-gl-470:i386 (470.57.02-0ubuntu0.20.04.1) ...
Setting up libnvidia-decode-470:i386 (470.57.02-0ubuntu0.20.04.1) ...
Setting up libglx-mesa0:i386 (21.0.3-0ubuntu0.2~20.04.1) ...
Setting up libglx0:i386 (1.3.2-1~ubuntu0.20.04.1) ...
Setting up libgl1:i386 (1.3.2-1~ubuntu0.20.04.1) ...
Setting up libnvidia-encode-470:i386 (470.57.02-0ubuntu0.20.04.1) ...
Setting up libnvidia-ifr1-470:i386 (470.57.02-0ubuntu0.20.04.1) ...
Setting up libnvidia-fbc1-470:i386 (470.57.02-0ubuntu0.20.04.1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: Generating /boot/initrd.img-5.13.8-051308-generic
Errors were encountered while processing:
 nvidia-dkms-470
 nvidia-driver-470
E: Sub-process /usr/bin/dpkg returned an error code (1)

I believe I’m using a kernel release too recent. I decided to choose the latest release due to the incompatibility issues my laptop had with the default kernel.

So… yeah. What should I do? What is the most recent kernel with which nvidia-driver-470 is compatible?

Try this, I just found; [SOLVED] nvidia errors during driver update - Linux Mint Forums

I’m getting a similar error. Attempting to do what they say in their first reply after posting. I see the date of your question, so, if you fixed it please let us know.

Also, sometimes downgrading the kernel helps for compatibility. New is not always the best.

I tried a lot of tricks. I believe I had a look at that post earlier when I had that problem. Thing is, looks like my laptop isn’t great with Linux, so I switched over to fedora. Everything workes fine, except I can’t install CUDA using DNF because it conflicts with the NVIDIA driver :(

Removed the whole installation out of frustration. Gotta give it a try again though.

You should always choose to install Linux kernel versions with long-term support (see https://www.kernel.org/ ). I am currently on Linux Kernel 5.10.* (LTS) , and the latest Nvidia driver is working fine.

xuancong@wxc-dell:~$ nvidia-smi
Sat Sep  4 16:19:40 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.63.01    Driver Version: 470.63.01    CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| 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 ...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   38C    P8    N/A /  N/A |      4MiB /  4042MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A     21812      G   /usr/lib/xorg/Xorg                  4MiB |
+-----------------------------------------------------------------------------+
xuancong@wxc-dell:~$ uname -a
Linux wxc-dell 5.10.57 #2 SMP Sat Aug 14 22:46:07 +08 2021 x86_64 GNU/Linux

installing the lts kernel is a really bad suggestion. for one it means dropping back down to 5.10.* as you said where his onboard amdgpu barely even will work. secondly the lts kernel is in my opinion completly useless for desktops, it recieves more backports/updates then normal mainline which means even more reboots and you are constantly running out of date drivers. nor will it solve the issue he is having. currently the nvidia driver is capable of running even on 5.14 which i am using.