Ubuntu – Restore specific kernel & modules (nvidia drivers)

backupbootgrub2kernelnvidia

Background: I've been running Ubuntu for years (started at 16.04, now at 20.04), and been constantly fighting with NVIDA drivers which I need as I use CUDA. As recently as yesterday, my NVIDIA 460 drivers were working fine, and an apt upgrade broke them again: Ubuntu 20.4 update broke my Nvidia 460 driver config


What I want to achieve:

  • Create a restore point of a kernel and its modules (eg nvidia drivers) I'm happy with
  • Whenever NVIDIA drivers break (or something else breaks badly), restore it

What I already have:

  • GRUB which seems to allow choosing specific kernels to boot from

(screenshots for illustration, not reflecting latest version)
enter image description here
enter image description here


Questions:

  • Restore point containing kernel+modules: is it possible to create (if so how), or am I simply misunderstanding how kernels & modules are managed on linux (ie a kernel wouldn't include the nvidia drivers) ?

  • Restoring from grub: It seems /etc/grub.d/40_custom is the file I want to modify as it's designed specifically for custom menu entries. Do you confirm this is the intended way of booting custom kernels or should I be looking at another file?

/etc/grub.d/40_custom:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

Best Answer