Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oprizal/998635a2ff5cbecb0519455c12b2994f to your computer and use it in GitHub Desktop.
Save oprizal/998635a2ff5cbecb0519455c12b2994f to your computer and use it in GitHub Desktop.
Install Nvidia legacy driver 340xx on Debian 11 Bullseye

How to Install Nvidia Legacy 340xx Driver on Debian 11 Bullseye

DE/WM: Xfce4 & i3

First of all, always update the system first.

$ sudo apt update && sudo apt upgrade

Then adding Debian SID repository since there are no available Nvidia 340xx legacy driver available on Debian 11---or at least it's not available if we read the Debian documentation here: Debian Nvidia Documentation.

There we can see that on Bullseye and Bookworm the only available are version 390xx and 460xx for Bullseye then 390xx and 470xx for Bookworm.

But bare in mind, it's not stable. But on my system with GeForce 310M it's working fine.

WARNING: It's important to run sudo apt update above BEFORE adding Debian SID repositories. You don't want to mix your current installed system Bullseye version with SID version. All we need only access to Nvidia legacy 340xx driver that's not available on Bullseye repositories.

Create a *.list file on /etc/apt/sources.list.d/. Then edit it and add Debian SID repositories address.

$ sudo touch /etc/apt/sources.list.d/sid-repositories.list
$ sudo nano /etc/apt/sources.list.d/sid-repositories.list

Below are Debian SID repositories address.

# Insert this line to /etc/apt/sources.list.d/sid-repositories.list
# we created above.
# Debian Sid.
deb http://deb.debian.org/debian/ sid main contrib non-free

After that install the Nvidia proprietary driver and let it finished.

$ sudo apt update && sudo apt install nvidia-legacy-340xx-driver firmware-misc-nonfree

You'll get a message prompt mentioning about conflict with nouveau driver, but this is ok. Read carefully. This message prompt only remainder to reboot your system after installation has finished.

After installation finished, then reboot your system.

$ systemctl reboot

When you successfully reboot and login to the system, you should remove the file---we created above---which have Debian SID address to prevent mixing the system version.

There should be no more update with Nvidia 340xx driver since it's no more development to this driver version---as long as I remember. That's why it must be safe to not using Debian SID repositories address again in the future.

$ sudo rm /etc/apt/sources.list.d/sid-repositories.list

Check if your driver successfully installed.

$ lsmod | grep -i nvidia

You should get drm mentioning nvidia.

Once more, it doesn't work with wayland.

@maiconjs
Copy link

Before deleting the "sid-repositories.list" file, it is useful to install nvidia-smi:

sudo apt install nvidia-legacy-340xx-smi

Once installed, using nvidia-smi will display details of GPU operation

@abzrg
Copy link

abzrg commented Nov 29, 2023

thanks man!

I confirm (in my case) this worked on bookworm as well.

@vansnyder
Copy link

I followed the instructions but "apt install nvidia-legacy-340xx-driver" replied "Unable to locate package nvidia-legacy-340xx-driver". It also complained that "firmware-misc-nonfree is not available". I didn't include the comments in the sid-repositories.list file. Are they necessary?

@fr33m0nk
Copy link

I followed the instructions but "apt install nvidia-legacy-340xx-driver" replied "Unable to locate package nvidia-legacy-340xx-driver". It also complained that "firmware-misc-nonfree is not available". I didn't include the comments in the sid-repositories.list file. Are they necessary?

The comments aren't necessary.
You may have missed executing sudo apt-get update after adding the sid repositories.

@NikolayKuraga
Copy link

Боже правый!
Worked for Devuan 5 (daedalus), runit, Linux 6.1.0-17-amd64:

  1. Commented sources in /etc/apt/sources.list, then added there this line:
    deb http://deb.devuan.org/merged ceres main contrib non-free non-free-firmware
  2. sudo apt update && sudo apt install nvidia-legacy-340xx-driver firmware-misc-nonfree
  3. Uncommented sources in /etc/apt/sources.list, removed added previously line
  4. sudo reboot

Thank you very much!

@Anakiev2
Copy link

Anakiev2 commented Apr 16, 2024

This method will mix your stable packages with packages from unstable.
Try this method instead it won't mix your packages. It's for Debian 12 but will probably work on Debian 11 too:
https://gist.github.com/Anakiev2/b828ed2972c04359d52a44e9e5cf2c63

@NikolayKuraga
Copy link

@Anakiev2, are there any options to build i386 version of the driver along with amd64 on amd64-host? Only working way I found is to compile the same packages (nvidia-legacy-340xx-driver, nvidia-settings-legacy-340xx) in virtual machine with the same OS but i386, place them in the local "/nvidia"-repo with amd64 packages and provide --multiversion flag to dpkg-scanpackages command. After that installing package nvidia-legacy-340xx-driver installs packages of both amd64 and i386 architectures and everything works like a charm.

However, in case of debuild-ing on amd64 OS with argument --host-arch i386 (there's no misspelling, the flag must be --host-arch, not --target-arch) building stops on this stage:

# ...some nice output upper.
Now at patch arm-outer-sync.patch
cd kernel-source-tree && /usr/bin/make -j2 NV_VERBOSE=1 KERNEL_UNAME=6.1.0-22-amd64
make[4]: Entering directory '/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree'
NVIDIA: calling KBUILD...
/usr/bin/make NV_MODULE_SUFFIX= KBUILD_OUTPUT=/lib/modules/6.1.0-22-amd64/build KERNEL_SOURCES=/lib/modules/6.1.0-22-amd64/source KERNEL_OUTPUT=/lib/modules/6.1.0-22-amd64/build KBUILD_VERBOSE=1 -C /lib/modules/6.1.0-22-amd64/source M=/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree ARCH=x86_64 modules
make[5]: Entering directory '/usr/src/linux-headers-6.1.0-22-common'
/usr/bin/make -C /usr/src/linux-headers-6.1.0-22-amd64 -f /usr/src/linux-headers-6.1.0-22-common/Makefile modules
make[6]: Entering directory '/usr/src/linux-headers-6.1.0-22-amd64'
/usr/bin/make -f /usr/src/linux-headers-6.1.0-22-common/scripts/Makefile.build obj=/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree need-builtin=1 need-modorder=1
make[7]: *** No rule to make target '/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree/nv-kernel-amd64.o_binary', needed by '/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree/nv-kernel.o'.  Stop.
make[7]: *** Waiting for unfinished jobs....
CONFTEST=/bin/sh /home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree/conftest.sh "i686-linux-gnu-gcc-12" "i686-linux-gnu-gcc-12" x86_64 /lib/modules/6.1.0-22-amd64/source /lib/modules/6.1.0-22-amd64/build
  printf '%s
'   nv-kernel.o nv.o nv-acpi.o nv-chrdev.o nv-cray.o nv-dma.o nv-drm.o nv-gvi.o nv-i2c.o nv-mempool.o nv-mmap.o nv-p2p.o nv-pat.o nv-procfs.o nv-usermap.o nv-vm.o nv-vtophys.o os-interface.o os-mlock.o os-pci.o os-registry.o os-smp.o os-usermap.o nv_uvm_interface.o nv-frontend.o | awk '!x[$0]++ { print("/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree/"$0) }' > /home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree/nvidia.mod
CONFTEST_CFLAGS=
KBUILD_CFLAGS=-Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu11 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mno-80387 -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mfunction-return=thunk-extern -fno-jump-tables -mharden-sls=all -fno-delete-null-pointer-checks -O2 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-main -ftrivial-auto-var-init=zero -pg -mrecord-mcount  -Wvla -Wno-pointer-sign -Wno-maybe-uninitialized -Wno-array-bounds -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -g
LINUXINCLUDE=-I/usr/src/linux-headers-6.1.0-22-common/arch/x86/include -I./arch/x86/include/generated -I/usr/src/linux-headers-6.1.0-22-common/include -I./include -I/usr/src/linux-headers-6.1.0-22-common/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/usr/src/linux-headers-6.1.0-22-common/include/uapi -I./include/generated/uapi -include /usr/src/linux-headers-6.1.0-22-common/include/linux/compiler-version.h -include /usr/src/linux-headers-6.1.0-22-common/include/linux/kconfig.h
LDFLAGS=-Wl,-z,relro
ARCH=x86_64
make[6]: *** [/usr/src/linux-headers-6.1.0-22-common/Makefile:2035: /home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree] Error 2
make[6]: Leaving directory '/usr/src/linux-headers-6.1.0-22-amd64'
make[5]: *** [Makefile:250: __sub-make] Error 2
make[5]: Leaving directory '/usr/src/linux-headers-6.1.0-22-common'
make[4]: *** [Makefile:217: nvidia.ko] Error 2
make[4]: Leaving directory '/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108/kernel-source-tree'
make[3]: *** [debian/rules:261: override_dh_auto_test] Error 2
make[3]: Leaving directory '/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108'
make[2]: *** [debian/rules:173: build] Error 2
make[2]: Leaving directory '/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108'
make[1]: *** [debian/rules:173: install] Error 2
make[1]: Leaving directory '/home/nikolay/Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108'
make: *** [debian/rules:173: binary] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
debuild: fatal error at line 1182:
dpkg-buildpackage -us -uc -ui --host-arch i386 -b failed

@Anakiev2
Copy link

Anakiev2 commented Aug 4, 2024

@NikolayKuraga I haven't used 32bit Linux but the process should be quite similar. The source code for i386 exists in debian.org you should be able to find information online how to compile it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment