Fully Working Patch for Nvidia Driver 340.102 [Compiler/Installer File] and Linux Kernel 4.12

For those who would like to immediately begin using Nvidia Driver 340.102 with Linux Kernel 4.12, apply the fully working patch provided here:

  • Name of the patch file is: “nv_patch_340.102_linux_kernel_4.12”, see direct links or extract from attached “patch.zip” file below

  • The patch is a cleaned-up combination of 4 individual patches for Linux Kernels 4.9, 4.10, 4.11 & 4.12

  • I have thoroughly tested the patch and it works well without any issues

  • 100% FULL CREDIT and MANY THANKS for those original, individual patches go out to: Alberto Milone, Michael Marley, Robert Hooker & Piotr Oniszczuk

Instructions for Applying Patch [nv_patch_340.102_linux_kernel_4.12] to Nvidia Driver Compiler/Installer 340.102 used with Linux Kernel 4.12 in CLI/Terminal:

  1. Download the following NVIDIA Driver Compiler/Installer file from NVIDIA website for Linux: NVIDIA-Linux-x86_64-340.102.run
  2. Go into CLI/Terminal, and SU into root(#)
  3. Completely Exit Xorg Server: The command “systemctl isolate multi-user.target” usually followed by “CTL+ALT+[F1 to F6]” will do this
  4. In CLI, go into root then provide execution permissions: “chmod 755 NVIDIA-Linux-x86_64-340.102.run”
  5. Extract the Nvidia Driver Compiler/Installer Contents & Source Files: “./NVIDIA-Linux-x86_64-340.102.run --extract-only”
  6. Copy [cp] Patch File “nv_patch_340.102_linux_kernel_4.12” into “NVIDIA-Linux-x86_64-340.102” directory
  7. Go into [cd] “NVIDIA-Linux-x86_64-340.102” directory where patch file is now located
  8. Apply Patch in that directory: “patch -p0 < nv_patch_340.102_linux_kernel_4.12”
  9. Proceed with NVIDIA Driver Compilation & Installation by running “./nvidia-installer”. Important: Make sure the Nouveau Driver is disabled-blacklisted and modeset set to 0 in /etc/modprobe.d with “blacklist nouveau” & “options nouveau modeset=0”, and the Initial RAM Disk (initrd) is created prior to compiling, installing & rebooting. Enjoy!

Note 1: You may wish to test out the patch first by executing a Dry-Run with:
“patch --dry-run -p0 < nv_patch_340.102_linux_kernel_4.12”

Note 2: If you are getting a “gcc/cc-version-check failed” error, please run “./nvidia-installer --no-cc-version-check” after applying patch

Pastebin & Google links for patch “nv_patch_340.102_linux_kernel_4.12”:
https://pastebin.com/raw/jfmmp0FK & https://goo.gl/5BxdJD

patch.zip (2.5 KB)

Thanks, ejmarkow!

Works on my machine:

Distro: Slackware64 v14.2
Kernel: 4.12.3
WinMgr: compiz 0.8.8
CPU: AMD Phenom II X6.
Desktop: xfce4

Thanks again!

Thanks for the patch. As a result I now have 340-102 running on Linux-4.12.8.

I have two PCI cards on my PC, the 8600GT and a TBS DVB-S2 card. Now that X11 works fine on 4.12.8, the other card, the TBS one does not, because I can’t compile the driver for the TBS card on Linux-4.12.8.

So I have to go back to Linux-4.9.44 where I can compile the TBS card driver.

But I found no patch yet to make the NVIDIA driver load on Linux-4.9.44. Yes I tried a number of patches, but either the driver won’t install or it won’t run.

So may I ask if by chance you have a patch that would make NVIDIA-340-102 load on Linux-4.9.44.

Thanks.

JustinCrowe & RichardWZ09, you’re welcome!

RichardWZ09,

Attached is the patch for Nvidia 340.102 w/ Linux Kernel 4.9, in a zip file.

The patch file is called: nv_patch_340.102_linux_kernel_4.9

Apply it to the raw, extracted contents of NVIDIA-Linux-x86_64-340.102.run following the same directions. Make sure you use the correct patch name.

Please let me know if this works for you.

patch.zip (451 Bytes)

Hi ejmarkow. I installed the patch but the install failed. There is a problem with the number of arguments to NV_GET_USER_PAGES. I wish to attach the installer log but I can’t find how so I paste the last part of the log here.

In file included from /tmp/selfgz1139/NVIDIA-Linux-x86_64-340.102-custom/kern
el/os-mlock.c:15:0:
   /tmp/selfgz1139/NVIDIA-Linux-x86_64-340.102-custom/kernel/nv-linux.h:2092:28:
 note: expected 'int' but argument is of type 'struct page **'
            static inline long NV_GET_USER_PAGES(unsigned long start,
                               ^~~~~~~~~~~~~~~~~
   /tmp/selfgz1139/NVIDIA-Linux-x86_64-340.102-custom/kernel/os-mlock.c:48:11: error: too few arguments to function 'NV_GET_USER_PAGES'
        ret = NV_GET_USER_PAGES((unsigned long)address,
              ^~~~~~~~~~~~~~~~~
   In file included from /tmp/selfgz1139/NVIDIA-Linux-x86_64-340.102-custom/kernel/os-mlock.c:15:0:
   /tmp/selfgz1139/NVIDIA-Linux-x86_64-340.102-custom/kernel/nv-linux.h:2092:28: note: declared here
            static inline long NV_GET_USER_PAGES(unsigned long start,
                               ^~~~~~~~~~~~~~~~~
   /tmp/selfgz1139/NVIDIA-Linux-x86_64-340.102-custom/kernel/os-mlock.c:28:23: warning: unused variable 'force' [-Wunused-variable]
        NvBool write = 1, force = 0;
                          ^~~~~
   make[3]: *** [/ssd204/usr/src/linux-4.9.44/scripts/Makefile.build:294: /tmp/selfgz1139/NVIDIA-Linux-x86_64-340.102-custom/kernel/os-mlock.o] Error 1
   make[2]: *** [/ssd204/usr/src/linux-4.9.44/Makefile:1493: _module_/tmp/selfgz1139/NVIDIA-Linux-x86_64-340.102-custom/kernel] Error 2
   make[2]: Leaving directory '/usr/src/linux-4.9.44'
   make[1]: *** [Makefile:150: sub-make] Error 2
   make[1]: Leaving directory '/ssd204/usr/src/linux-4.9.44'
   NVIDIA: left KBUILD.
   nvidia.ko failed to build!
   make: *** [Makefile:185: nvidia.ko] Error 1
-> Error.
ERROR: Unable to build the NVIDIA kernel module.
ERROR: Installation has failed.  Please see the file '/var/log/nvidia-installer.

Hello RichardWZ09,

I found the issue, corrected it, and uploaded a new patch.zip file with nv_patch_340.102_linux_kernel_4.9 into my previous post (I removed the original one). Please download and apply it, I’m confident it will work with your Kernel 4.9 this time.

Don’t forget to apply it to a freshly extracted NVIDIA-Linux-x86_64-340.102.run file.

Please let me know how it works, thank you.

Regards,

Eugene

Hi ejmarkow,

Thanks so much. The patch works like a charm. The driver is up and running.

You will surely be laughing now since that is the the simplest patch there could be. I am surprised that it works this time around since I am sure I have already tried that patch (I edited the file manually though) and the driver didn’t load then.

You surely have a magic hand :-).

RichardWZ09,

Always happy to help out, I’m glad both Nvidia patches for Kernels 4.9 & 4.12 worked for you!

Cheers,

Eugene J. Markow

If you don’t want to do the complex task just do.

wget http://rpms.if-not-true-then-false.com/nvidia/NVIDIA-Linux-x86_64-340.102-kernel-4.12-patched.run
bash NVIDIA-Linux-x86_64-340.102-kernel-4.12-patched.run

Reference… https://www.if-not-true-then-false.com/2015/fedora-nvidia-guide

Sorry for the bump, but does anyone know if there is a patch for 4.13?

Thanks!

-Michael

Michael,

You can find it here: https://goo.gl/43MEqe

It was posted a while ago.

Eugene

Thanks! For some reason neither forum nor Google search brought that thread up.

-Michael

Hi Michael,

Just want to confirm if everything worked out for you with this patch and instructions. How did it go?

Eugene

Technically it’s not working, at least in what I was attempting to fix. Cinnamon keeps crashing on log in, and only runs in fallback mode. I am currently just running in Gnome 3 with some tweaks, which is taking a bit of getting used to, but is better than Cinnamon fallback mode. :)

F25 reaches EOL next week, so I will just need to bite the bullet and upgrade soon anyway, which I am dreading but am assuming will fix the issue. Thank you for your help.

-Michael