Nvidia dkms not support kernel when mannuly compile 5.15.65-rt49 / 5.10.140-rt73 kernel

A new rt kernel, such as 5.10.140-rt73, tried to be compiled from source code. At the compile stage, I meet a compile error, while nvidia-dkms can be installed on current os (kernel 5.15.0-48-generic).

The compilation error says:

Building module:
cleaning build area…(bad exit status: 2)
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.140-rt73 IGNORE_XEN_PRESENCE=1 IGNORE_CC_MISMATCH=1 SYSSRC=/lib/modules/5.10.140-rt73/build LD=/usr/bin/ld.bfd modules…(bad exit status: 2)
ERROR (dkms apport): kernel package linux-headers-5.10.140-rt73 is not supported
Error! Bad return status for module build on kernel: 5.10.140-rt73 (x86_64)
Consult /var/lib/dkms/nvidia/510.85.02/build/make.log for more information.

And file /var/lib/dkms/nvidia/510.85.02/build/make.log reads:

Makefile:18: /Kbuild: No such file or directory
make[3]: *** No rule to make target ‘/Kbuild’. Stop.

Some my computer/os information:
Linux ascend-GE76-Raider-11UH 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal

Installed: 510.85.02-0ubuntu0.20.04.1
Candidate: 510.85.02-0ubuntu0.20.04.1
Version table:
*** 510.85.02-0ubuntu0.20.04.1 500
500 Index of /ubuntu/ focal-updates/restricted amd64 Packages
500 Index of /ubuntu/ focal-security/restricted amd64 Packages
100 /var/lib/dpkg/status
Installed: (none)
Candidate: 515.76-0ubuntu0.20.04.1
Version table:
515.76-0ubuntu0.20.04.1 500
500 Index of /ubuntu/ focal-proposed/restricted amd64 Packages
515.65.01-0ubuntu0.20.04.1 500
500 Index of /ubuntu/ focal-updates/restricted amd64 Packages
500 Index of /ubuntu/ focal-security/restricted amd64 Packages
100 /var/lib/dpkg/status


/lib/modules/5.10.140-rt73/build needs to be a symbolic link to the kernel build directory. Since it can’t find Kbuild, this seems to point somewhere else.

Yes, I found the /lib/modules/5.10.140-rt73/build points to my kernel build directory where the command make module_install runs. The nividia driver sources are located at /var/lib/dkms/nvidia/510.85.02 I found the var $(src) in makefile of nvidia/510.85.02 is empty at runtime, so that cannot find nvidia’s Kbuild files, which also located at /var/lib/dkms/nvidia/510.85.02. Since this reason, I copy the nvidia driver sources to arch/x86/boot/ in my kernel build directory, and finally can compile. But it warns that nvidia driver not supports PREEMPT_RT kernel. I set IGNORE_PREEMPT_RT_PRESENCE=1 to avoid this error. After all these steps, the nvidia driver as well as the new kernel is compiled. But it is stuck at black screen when I restart the computer. The screen freezes in Loading initial ramdisk. Which step did I goes to wrong ?