Install nvidia-340 driver on Ubuntu 20.04.3 LTS

在一台旧PC上安装了Ubuntu 20.04.3 LTS, 显卡是”微星N240GT-MD 暴雪512/D5″, 芯片是 Nvidia Geforce GT240, 需要安装显卡驱动

》 先是从nvidia官方网站根据显卡型号下载了NVIDIA-Linux-x86_64-340.108.run 安装过程中提示: asm/kmap_types.h: No such file or directory 没有找到有效解决办法

》 google一番后尝试直接安装nvidia-340驱动

sudo apt install nvidia-340

也是安装失败, 主要的错误是: dpkg: error: version ‘-‘ has bad syntax: revision number is empty

Setting up lib32gcc-s1 (10.3.0-1ubuntu1~20.04) ...
Setting up vdpau-driver-all:amd64 (1.3-1ubuntu2) ...
Setting up nvidia-340 (340.108-0ubuntu5.20.04.2) ...
dpkg: error: version '-' has bad syntax: revision number is empty
dpkg: error: version '-' has bad syntax: revision number is empty
update-initramfs: deferring update (trigger activated)
INFO:Enable nvidia-340
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
Adding system user `nvidia-persistenced' (UID 127) ...
Adding new group`nvidia-persistenced' (GID 134) ...
Adding new user `nvidia-persistenced' (UID 127) with group`nvidia-persistenced' ...
Not creating home directory `/'.
Loading new nvidia-340-340.108 DKMS files...
Building for 5.11.0-40-generic Building for architecture x86_64 Building initial module for 5.11.0-40-generic
Error! Bad return status for module build on kernel: 5.11.0-40-generic (x86_64)
Consult /var/lib/dkms/nvidia-340/340.108/build/make.log for more information.
dpkg: error processing package nvidia-340 (--configure):
  installed nvidia-340 package post-installation script subprocess returned error exit status 10
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: Generating /boot/initrd.img-5.11.0-40-generic
I: The initramfs will attempt to resume from /dev/sda2
I: (UUID=de437dbe-e6b9-4aad-a865-3b9c62bcb807)
I: Set the RESUME variable to override this. 
Errors were encountered while processing:
  nvidia-340
E: Sub-process /usr/bin/dpkg returned an error code (1)

》 继续查找资料
* 有说是postinstall scripts中的一个bug: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1853977 第#3个回复
* 有说是nvidia-340不支持Ubuntu 20.04.3 LTS 最新的内核 5.11.0-40-generic, 后来按照 (https://askubuntu.com/questions/1284266/the-installation-of-the-nvidia-display-driver-340-fails-in-kubuntu-20-10)的说法

卸载5.11.0-40-generic, 安装5.4.0-90-generic内核后解决:

sudo apt install linux-generic
sudo apt-get remove --purge linux-*-5.11.*

重启后重新安装nvidia-340:

sudo apt install -y nvidia-340

成功!!

$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0 ==
modalias : pci:v000010DEd00000CA3sv00001462sd00002072bc03sc00i00
vendor   : NVIDIA Corporation
model    : GT215 [GeForce GT 240]
driver   : nvidia-340 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

Leave a Comment