Failure executing driver install .run file on Ubuntu 18.04


This is an FYI, in hope it helps someone. Also, maybe nVidia can fix this issue somehow?

I was trying to install on Ubuntu 18.04. The install kept failing, unable to unload nVidia kernel driver. I was logged into the box remotely. I had no cuda code running on the box. I stopped the display manager (sudo service gdm stop), but that didn’t help. I looked up which nvidia modules were loaded, and sure enough I found nvidia-modeset. I tried to remove it, using the following command and ran into an error:

$> modprobe -r nvidia-modeset
modprobe: FATAL: Module nvidia_modeset is in use.

After some web-searching, I found the following solution deep within debian - How to unload kernel module 'nvidia-drm'? - Unix & Linux Stack Exchange

$> systemctl stop nvidia-persistenced
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop ‘nvidia-persistenced.service’.
Authenticating as:

After this the above modprobe -r has worked and the installation run file got executed successfully.

I’m wondering, is it possible to provide some automation for these steps, or at least some hint of what needs to be done to unlock driver install, as part the .run job? I had honestly no clue that nvidia-persistenced service was running on my box, and I’m still not sure what it is.