21

Every time there's a kernel update, nvidia graphics drivers stops working because there's not a valid kernel module.

What is the ubuntu way to 'recompile' the nvidia module for the new kernel?

Shouldn't it be done automatically? I am suffering a bug?

Jorge Castro
  • 71,754

6 Answers6

6

If you have installed the NVIDIA driver as an ubuntu package, it should be updated automatically after each kernel upgrade.

You can install the packaged driver using the Additional Drivers tool in the dashboard, or installing the package nvidia-current.

If you have installed the nvidia driver directly from their website it is probably sensible to remove it before installing this package - I'm not certain how good it will be at detecting the conflict.

If you have installed the package from the ubuntu repositories, you can try reconfiguring it with dpkg-reconfigure but I suspect building the nvidia module is triggered by installing a new kernel, and I'm not sure how to trigger this otherwise. The traditional uninstall and re-install might well work (sudo apt-get remove nvidia-current; sudo apt-get install nvidia-current).

chronitis
  • 12,367
  • I installed the nvidia driver through an Ubuntu package. But updating the kernel didnt trigger the recompilation of my nvidia module. Thanks for your tips anyway. – fazineroso Aug 09 '12 at 12:04
6

For me dpkg-reconfigure rebuilds the Nvidia driver with the latest kernel. This then requires a reboot to take effect. My example below uses the older nvidia-304-updates.

sudo dpkg-reconfigure nvidia-304-updates

EDIT: I managed to automate this by writing a script zz-dkpg-reconfigure-nvidia that runs after kernel updates

#!/bin/bash
#
# Reconfigure nvidia driver

DRIVER=nvidia-304-updates

dpkg-reconfigure $DRIVER > /var/log/dpkg-reconfigure-nvidia.log 2>&1

exit 0

I installed the above script by running

sudo install zz-dkpg-reconfigure-nvidia /etc/kernel/postinst.d

Works on my Ubuntu 14.04 kernel 3.13.0-29 to 3.13.0-36 update.

6

When you have installed the NVIDIA binary driver, you probably haven't installed the dkms package. Dkms makes sure that every time you update kernel, modules which support it are recompiled:

sudo apt-get install dkms

You would probably need to re-install the NVIDIA binary drivers afterwards, and allow to use DKMS during the setup as it needs to be registered with it.

  • I am encountering the same issue and just realized I haven't installed dkms after reading this answer. – yaobin Sep 25 '18 at 20:11
  • I have dkms installed and yet I had to do sudo dpkg-reconfigure nvidia-kernel-dkms – rustyx Mar 01 '22 at 22:21
3

When installing new kernels using the "Ubuntu Mainline Kernel Installer" it doesn't automatically rebuild the kernel modules for the nvidia proprietary driver.

First ensure you have installed the dkms package for your nvidia driver. The package name will be nvidia-dkms-{DRIVER VERSION} (IE: for version 530 it would be nvidia-dkms-530).

After you've installed a new kernel from the mainline installer, run the following command to rebuild the nvidia kernel modules.

sudo dpkg-reconfigure nvidia-dkms-{DRIVER VERSION}

You should now be able to boot with the new kernel

John
  • 131
3

If you want to rebuild the kernel modules only, then you might just want to execute

sudo apt-get install --reinstall nvidia-current

if you have nvidia-current installed, or if you have nvidia-331 installed then this should do the work:

sudo apt-get install --reinstall nvidia-331

no need to add a repo or install new software :-)

Steel Brain
  • 215
  • 1
  • 10
1

Please note that neither installing a kernel upgrade nor drivers from officially unsupported repositories is recommended! Follow these instructions at your own risk and only if you know what you're doing!

If you installed an kernel that's ahead of current official Ubuntu repositories (e.g. kernel 3.4 or 3.5) you might not succeed with simply reinstalling nvidia drivers.

The only way I found so far to get nvidia-drivers to work again is by adding the following ppa to your repositories. In a terminal type:

sudo add-apt-repository ppa:xorg-edgers/ppa

After that, do a sudo apt-get update and sudo apt-get install nvidia-current.

That should do the trick. If not, run an additional sudo apt-get upgrade.

FuzzyQ
  • 2,328