nvidia-340 driver on Ubuntu 20.04
Solution 1
You'll need to install the 5.4 kernel, and uninstall 5.11.
-
sudo apt purge nvidia*
-
sudo apt install --install-recommends linux-generic
-
Now reboot, and select kernel 5.4 at grub menu.
-
sudo apt remove --purge linux-generic-hwe-20.04 linux-hwe-* linux-modules-5.11* linux-modules-extra-5.11*
-
If everything worked so far, run
sudo ubuntu-drivers autoinstall
to install Nvidia driver.
Solution 2
Sticking with 5.4
kernel will not be an option forever. I had the same issue with a early 2009 iMac
, where the last proprietary nvidia driver available for my C79 [GeForce 9400]
card is also nvidia-340
.
As said by others, this driver is not supported by kernels > 5.4.
It means the day you will go for a newer kernel (you will have to, soon or later), you will have 2 choices :
- try
nouveau
driver (I had lots of freeze issues on my iMac, but it could work for you, our cards are different) - keep the
nvidia-340
proprietary driver with the more recent kernel
For (2), there is a solution.
Basically, boot on your new kernel (like 5.11
, with for instance nouveau
driver), and do what is explained in the link above, something like :
sudo add-apt-repository ppa:kelebek333/nvidia-legacy
sudo apt-get update
sudo apt install nvidia-340
# Warning: below line for kernels >= 5.11
sudo apt install xorg-modulepath-fix
I did upgrade from 20.04
(kernel 5.4
, already with kelebek333
's nvidia-340
version) to 21.10
(kernel 5.13
) on the old iMac (I had no issue during the upgrade itself). The upgrade process did remove kelebeck333
repo), and enabled the nouveau
driver.
After booting the new system, I did apply (again) the commands above, and my nvidia
configuration is now :
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.10
Release: 21.10
Codename: impish
$ uname -r
5.13.0-28-generic
$ dpkg -l | grep nvidia
ii nvidia-340 340.108-4lmtrimpish3 amd64 NVIDIA binary driver - version 340.108
ii nvidia-opencl-icd-340 340.108-4lmtrimpish3 amd64 NVIDIA OpenCL ICD
ii nvidia-settings 470.57.01-0ubuntu3 amd64 Tool for configuring the NVIDIA graphics driver
ii screen-resolution-extra 0.18.1 all Extension for the nvidia-settings control panel
$ inxi -Gx
Graphics: Device-1: NVIDIA C79 [GeForce 9400] vendor: Apple iMac 9 1 driver: nvidia v: 340.108 bus-ID: 03:00.0
Device-2: Apple Built-in iSight type: USB driver: uvcvideo bus-ID: 1-4:2
Display: server: X.org 1.20.13 driver: loaded: nvidia tty: 186x32
velenos14
Updated on September 18, 2022Comments
-
velenos14 over 1 year
I have a dual-boot machine with Windows8 and Ubuntu 20.04.3 LTS.
It worked fine up until I pressed Yes (install) to some automatic updates from Ubuntu via the GUI pop-up window. These updates failed at around 70%. The problem is with nVidia drivers.
My motherboard is GT216 (GeForce GT 220). Running
ubuntu-drivers devices
I get:driver: nvidia-340 - distro non-free recommended
driver: xserver-xorg-video-nouveau -distro free builtin.
After I shut down the computer after that failed update, at restart I got a login-infinite loop at the login screen (entered password, no login into Gnome Desktop, asked for password again, entered it again, no login into Gnome Desktop, repeat). I researched online and I found out that the nvidia-340 drivers are not compatible with my current kernel version.
Using
tty
terminals I worked through this tutorial https://www.if-not-true-then-false.com/2020/inttf-nvidia-patcher/ and then I installed nvidia-340 by running the executable I got via the tutorial. I followed the steps from here: https://www.if-not-true-then-false.com/2021/debian-ubuntu-linux-mint-nvidia-guide/#before-installation. I can now login into Gnome.Problem:
All my graphics programs are destroyed. In the past when my machine was functioning properly, I had installed Qt5 and linked against a framework I use for work. Now that framework doesn't function anymore, I cannot compile programs against the visualization drivers anymore.
I tried to reinstall the visualization drivers again, as I did 3-4 months ago on the same machine (when I successfully set up that framework I use for work): but I fail at the very first step:
sudo apt install qt5-default
Removing nvidia-340 (340.108-0ubuntu5.20.04.2)... /var/lib/dpkg/info/nvidia-340.postrm: 59: /usr/sbin/update-initramfs: not found
dpkg: error processing package nvidia-340 (--remove):
installed nvidia-340 package post-removal script subprocess returned error exit status 127
dpkg: too many errors, stopping
Errors were encountered while processing:
nvidia-340
Processing was halted because there were too many errorrs.
E: Sub-process /usr/bin/dpkg reurned an error code (1).
Attemtps I did:
-
I have tried to do what it's written in here Ubuntu 18.10 problem with Nvidia 340 drivers
-
I have tried to run
sudo apt-get install nvidia-current
: E : Package 'nvidia-current' has no installation candidate -
I have tried to switch to Nouveau from the Applications -> Software & Updates -> Additional Drivers, but it doesn't work. When I click to switch to that,
Error while applying changes: pk-client-error-quark: Error while installing package: installed nvidia-340 package post-removal script subprocess returned error exit status 127 (313)
-
I have tried to run
nvidia-settings
-> this pops up a new window with various information, which I can provide if needed. -
I have tried to run
sudo apt-ache policy nvidia-340
-> this returns nvidia -340 : Installed : 340-108-0ubuntu5.20.04.2 candidate : 340-108-0ubuntu5.20.04.2 ... etc -
I have tried to run
which nvidia-smi
-> this returns nothing
6') I have tried to run
nvidia-smi
-> returns 'nvidia-smi' command nout found, can be installed with: and here appears a list of nvidia drivers it recommends installing via sudo apt install nvidia-XYZ or sudo apt install nvidia-utils-XYZ.-
I have tried to run
sudo ubuntu-drivers autoinstall
-> this returns the same thing as before: The following packages will be removed: nvidia-340 Removing nvidia-340 ... dpkg: error processing package nvidia-340 (--remove): installed nvidia-340 package post-removal script subprocess returned error exit status 127 dpkg: too many errors, stopping Errors were encountered while processing: nvidia-340 ... -
I have tried to run
sudo apt-get install nvidia-340
-> this returns that nvidida-340 is already the newest version (340.108-0ubuntu5.20.04.2) 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 1 not fully installed or removed. Need to get 52,0 MB of archives. After this operation, 0B of additional disk space will be used. Do you want to continue ? Yes Y Get: 1 ... Fetched 52,0 MB in 2 s Processing triggers for libc-bin (2.31-0ubuntu9.2) ... and here I don't get any more returned statements and I just get a new line on the terminal to enter a new command as in $ > ... (so process exits alright and I can just continue doing stuff).
When writing (to configure my framework again)
sudo apt install qt5-default
I again get the same errors as above (in the Problem section)Do you know what is happening or what shall I do? I really want to be able to compile applications again and run them on my machine.
I can provide any necessary info which might be useful to solve my problem.
Thank you in advance!
Edit (new info):
My current kernel version which appears as output when running
uname -r
is:5.11.0-36-generic
-
-
velenos14 over 2 yearsthank you! just to check before I write these commands, from the link wiki.ubuntu.com/Kernel/…, I read that one step is as following: "And then install appropriate NNN version of the drivers:
sudo apt install --install-recommends linux-modules-nvidia-NNN-generic
" . Do I need to do this aftersudo apt install --install-recommends linux-generic
and before rebooting? -
velenos14 over 2 yearsdoes Ubuntu install automatically all the necessary nVidia drivers when I log-in onto the kernel 5.4? Or do I need to manually install them after booting onto this kernel 5.4? so I am asking whether do I need to perform additional steps after booting onto kernel 5.4 in order to have correctly installed nVidia drivers
-
mikewhatever over 2 yearsYou'll need to install it. The
ubuntu-drivers autoinstall
should work for kernel 5.4. ...and yes, you need to install the 5.4 kernel first. Whether you reboot or not is less important, but if kernel 5.11 is still present, the Nvidia module will also build for it, and will fail. -
velenos14 over 2 yearssorry, but
sudo apt install --install-recommends
fails! It reads: Fetched 75,5 MB in 4s ... Removing nvidia-340 (340.108-0ubuntu5.20.04.2) ... /var/lib/dpkg/info/nvidia-340.postrm: 59: /usr/sbin/update-initramfs: not found dpkg: error processing package nvidia-340 (--remove): installed nvidia-340 package post-removal script subprocess returned error exit status 127 dpkg: too many errors, stopping. Errors were encountered while processing: nvidia-340. E: Sub-process /usr/bin/dpkg returned an error code (1). Just to make sure: Do I need to run that command in my actual ubuntu terminal? -
mikewhatever over 2 yearsYou can run it remotely too, but do remove any broken packages first. It looks like that Nvidia driver you've tried is still there.
-
velenos14 over 2 yearswhat do you mean to run it remotely? what do you mean to remove any broken packages first? do I need to purge any file having in its name something related to nvidia-310? I re-ask: do I need to run the commands you wrote in your answer in my ubuntu terminal (in the Gnome desktop environment) having kernel 5.11? I am sorry, but I am just trying to follow what you said as I don't have enough expertise to build upon your instructions... thanks
-
mikewhatever over 2 yearsBy remotely, I mean ssh. If that is irrelevant, run it "in my actual ubuntu terminal". Yes, do purge all Nvidia files. I'll number the steps in the answer above, so that the order is cristal clear.
-
mikewhatever over 2 yearsAlright, I've added step 0, according to your suggestion. Try and see if it works. For whatever reason, I have no access to chat, so can't join you there. Sorry about that.
-
velenos14 over 2 yearsnope, doesn't work. same error with
dpkg: too many errors, stopping. Errors were encountered while processing: nvidia-340. Processing was halted because there were too many errors. E: Sub-process /usr/bin/dpkg returned an error code (1)
. Maybe because I installed nvidia-340 as from the tutorial in if-not-true-then-false.com/2020/inttf-nvidia-patcher ? -
xofer over 2 yearsThis solved my problem, but I also had to remove kernel version
5.8*
, i.e. repeat step 3, replacing5.11*
with5.8*
. -
velenos14 over 2 yearshow did you manage to
purge nvidia*
? didn't you get an error? I get an error at the very step of this answer ... -
mikewhatever over 2 years@velenos14 Generally, it is not a good idea to run untrusted scripts form untrusted website. Looks like it installed a patched Nvidia driver and a patched 5.11 kernel. Perhaps it is time to reinstall.
-
velenos14 over 2 years@mikewhatever, I see, it was the only option which worked and helped me go past my initial problem askubuntu.com/questions/1364816/… with the infinite login loop which then transformed into me only being able to use a tty terminal. So I understand that my aim is now to remove what this patch installed? thanks
-
Rafael Bluhm about 2 yearsThis is the only of a ton of solutions that works, also try the more votated, Ty
-
Cerin about 2 yearsThanks. Worked pretty well. However, I had to manually purge all other kernel packages besides the one for 5.4. Otherwise, by default it still tried to load a non-5.4 kernel, which then blocks login since the video driver crashes, having been compiled only for 5.4.