Ubuntu – nvidia modules are missing after each kernel upgrade in 18.04

18.04kernelnvidia

After each kernel upgrade, when I reboot I only get a blank screen

It looks like the proprietary nvidia kernel modules do not get auto recompiled

I have to boot into recovery mode and do

dpkg-reconfigure nvidia-dkms-415

and after that all good till the next upgrade.

I guess something get messed up in the system, originaly I tried to install the nvidia driver from nvidia, but ended up removing it and just used the ubuntu one.

Any tips how to sort out my system? i don't want to reinstall.

sudo dkms status:

Error! Could not locate dkms.conf file.  
File:  does not exist.

ls /var/lib/dkms

dkms_dbversion  nvidia

ls /var/lib/dkms/nvidia/

410.78  415.27  kernel-4.15.0-39-generic-x86_64  kernel-4.15.0-45-generic-x86_64

sudo ubuntu-drivers devices

== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==  
modalias : pci:v000010DEd00001B81sv00001028sd00003301bc03sc00i00  
vendor   : NVIDIA Corporation  
model    : GP104 [GeForce GTX 1070]  
driver   : nvidia-driver-390 - third-party free  
driver   : nvidia-driver-415 - third-party free recommended  
driver   : nvidia-driver-396 - third-party free  
driver   : nvidia-driver-410 - third-party free  
driver   : xserver-xorg-video-nouveau - distro free builtin

I am using this ppa:

deb-src http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu bionic main  

after

sudo apt purge 'nvidia.*'
sudo apt install nvidia-driver-415

output:   
...
Setting up nvidia-dkms-415 (415.27-0ubuntu0~gpu18.04.2) ...
update-initramfs: deferring update (trigger activated)
INFO:Enable nvidia
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
Loading new nvidia-415.27 DKMS files...
Building for 4.15.0-45-generic
Building for architecture x86_64
Building initial module for 4.15.0-45-generic
Secure Boot not enabled on this system.
Done.

nvidia:
Running module version sanity check.

Good news! Module version 415.27 for nvidia.ko
exactly matches what is already found in kernel 4.15.0-45-generic.
DKMS will not replace this module.
You may override by specifying --force.

nvidia-modeset.ko:
Running module version sanity check.

Good news! Module version 415.27 for nvidia-modeset.ko
exactly matches what is already found in kernel 4.15.0-45-generic.
DKMS will not replace this module.
You may override by specifying --force.

nvidia-drm.ko:
Running module version sanity check.

Good news! Module version 415.27 for nvidia-drm.ko
exactly matches what is already found in kernel 4.15.0-45-generic.
DKMS will not replace this module.
You may override by specifying --force.

nvidia-uvm.ko:
Running module version sanity check.

Good news! Module version  for nvidia-uvm.ko
exactly matches what is already found in kernel 4.15.0-45-generic.
DKMS will not replace this module.
You may override by specifying --force.

depmod...

DKMS: install completed.
Setting up nvidia-driver-415 (415.27-0ubuntu0~gpu18.04.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for initramfs-tools (0.130ubuntu3.6) ...
update-initramfs: Generating /boot/initrd.img-4.15.0-45-generic

Now:

dkms status

nvidia, 415.27, 4.15.0-45-generic, x86_64: installed

Best Answer

Your dkms is broken. I suggest to fix it this way:

sudo rm -r /var/lib/dkms/nvidia
sudo apt install --reinstall dkms
sudo apt purge 'nvidia.*'
sudo apt install nvidia-driver-415

That will cleanup the dkms directory, create dkms.conf and install the driver properly.