Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Anakiev2/b828ed2972c04359d52a44e9e5cf2c63 to your computer and use it in GitHub Desktop.
Save Anakiev2/b828ed2972c04359d52a44e9e5cf2c63 to your computer and use it in GitHub Desktop.
How to install nvidia-legacy-340xx-driver on Debian 12 Bookworm

How to install nvidia-legacy-340xx-driver on Debian 12 Bookworm

This guide will show you how to download, compile and install the nvidia-legacy-340xx-driver on Debian 12. Some people install the driver directly from sid but this will mix packages from both stable and unstable which may create issues. It's recommended to update and upgrade your system before you start.

It was reported to work with nvidia-legacy-390xx-driver just replace the appropriate package names.

Step 1. Download the source code.

Install these packages.

sudo apt install build-essential fakeroot devscripts

You can manually download the source code from debian.org and go to Step 2 or continue with Step 1. Don't worry you won't be able to install packages from sid.
Add 'deb-src http://httpredir.debian.org/debian unstable main non-free contrib' to '/etc/apt/sources.list'.
Update your system.

sudo apt update

Create these folders.

mkdir -p Build/nvidia340 Build/nvidia-settings

Download the driver in 'Build/nvidia340'.

apt source nvidia-legacy-340xx-driver

Download the nvidia-settings in 'Build/nvidia-settings'.

apt source nvidia-settings-legacy-340xx

Delete 'deb-src http://httpredir.debian.org/debian unstable main non-free contrib' from '/etc/apt/sources.list'.
Update your system.

sudo apt update

Step 2. Compile the driver.

Run

debuild -b -uc -us

in both folders 'Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108' and 'Build/nvidia-settings/nvidia-settings-legacy-340xx-340.108'.
It will complain about missing build dependencies. Install them.

# Example
# sudo apt install debhelper-compat m4 libgl-dev libgtk2.0-dev libjansson-dev libvdpau-dev libxext-dev libxv-dev libxxf86vm-dev pkg-config xserver-xorg-dev debhelper dh-dkms patchelf po-debconf quilt linux-headers-amd64

Run again

debuild -b -uc -us

in both folders 'Build/nvidia340/nvidia-graphics-drivers-legacy-340xx-340.108' and 'Build/nvidia-settings/nvidia-settings-legacy-340xx-340.108' to compile the driver.

Step 3. Make a local repository.

Make a new folder '/nvidia'.

sudo mkdir /nvidia

Copy all *.deb files from 'Build/nvidia340' and 'Build/nvidia-settings' inside '/nvidia'.

sudo cp *.deb /nvidia

Create 'Packages'.

cd /nvidia
sudo sh -c 'dpkg-scanpackages . > Packages'

Add 'deb [trusted=yes] file:/nvidia ./' to '/etc/apt/sources.list'.
Enable 'contrib' in your '/etc/apt/sources.list'.

# Example
# deb http://deb.debian.org/debian bookworm main non-free-firmware contrib

Step 4. Install the driver.

For each additional kernel you have to manually install the respective linux-headers.
Update your system and install the driver.

sudo apt update
sudo apt install nvidia-legacy-340xx-driver nvidia-settings-legacy-340xx
# If the above line doesn't work try with
# sudo apt install --no-install-recommends --no-install-suggests nvidia-legacy-340xx-driver nvidia-settings-legacy-340xx libgles1-nvidia-legacy-340xx libgles2-nvidia-legacy-340xx

It's recommended to uninstall all other video drivers or at least nouveau.

sudo apt autoremove xserver-xorg-video-nouveau

Step 5. Configure Xorg.

Create a file /etc/X11/xorg.conf (to configure NVIDIA Optimus - read the comments).

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection

Section "ServerFlags"
    Option         "IgnoreABI" "1"
EndSection

Step 6. Clean up. OPTIONAL.

I would definitely keep the source code because I might have to rebuild the driver in the future otherwise you can run.

rm -r Build/nvidia340 Build/nvidia-settings
rmdir Build

You can remove 'deb [trusted=yes] file:/nvidia ./' from '/etc/apt/sources.list' and update your system.
You can also delete '/nvidia' and all *.deb files.

sudo rm -r /nvidia

Sources:

https://wiki.debian.org/SourcesList
https://wiki.debian.org/BuildingTutorial
https://wiki.debian.org/DebianRepository/Setup

@pcmaker401
Copy link

pcmaker401 commented Sep 30, 2024

Thank you for this write up! I have tried so many attempts to get nvidia-smi verify the driver is working and this is the closest I've gotten. I do have a question: I have a Nvidia Optimus laptop (Geforce 310M and Intel Integrated Graphics), however I'm getting an error displayed on the screen "Something went wrong". I'm guessing that has to do with the Intel driver now. Any ideas?

@Anakiev2
Copy link
Author

Anakiev2 commented Oct 4, 2024

For NVIDIA Optimus use this configuration file. Modify BusID with your Nvidia GPU ID.

Section "Module"
  Load "modesetting"
EndSection

Section "Device"
  Identifier "Nvidia Card"
  Driver "nvidia"
  VendorName "NVIDIA Corporation"
  BusID "MODIFY_HERE"
  Option "AllowEmptyInitialConfiguration"
EndSection

Section "ServerFlags"
  Option "IgnoreABI" "1"
EndSection

https://wiki.archlinux.org/title/Lenovo_ThinkPad_P52

You have two GPUs with different BusID and your laptop defaults to the Intel one. This is why the Nvidia driver can't find the Nvidia GPU and reports (EE) No devices detected and (EE) no screens found(EE).

More useful links:
https://bbs.archlinux.org/viewtopic.php?id=223581
https://wiki.archlinux.org/title/NVIDIA_Optimus

To find your BusID you can run grep -r PCI /etc/optimus-manager/xorg/:
Askannz/optimus-manager#471 (comment)
https://unix.stackexchange.com/a/633709
https://unix.stackexchange.com/questions/585910/setting-busid-in-xorg-conf

@marques576
Copy link

Thanks, this also works with nvidia-settings-legacy-390xx

@it0it0
Copy link

it0it0 commented Nov 5, 2024

This all worked for me, except steam won't run as it expects the LibGL1 32 bit files. How to build or install these?

@Anakiev2
Copy link
Author

Anakiev2 commented Nov 6, 2024

@pcmaker401 @marques576 I've updated the guide with the new information. @it0it0 I can't help you with 32-bit libraries.

@it0it0
Copy link

it0it0 commented Nov 6, 2024

@pcmaker401 @marques576 I've updated the guide with the new information. @it0it0 I can't help you with 32-bit libraries.

@Anakiev2 thanks for the reply. As I see the 32 bit Nvidia package being downloaded which includes the libraries and assume these are not recompiled , I would expect to copy them to /use/local/lib and run ldconfig, but it didn't work for me. Steam no longer showed the missing libgl error but still crashed. Any suggestions what I could do.

@marques576
Copy link

Has anyone been able to get cuda 9.2 working with driver nvidia-390?

@grosioso
Copy link

works with lmde 6 with debian 12.1?

@Anakiev2
Copy link
Author

According to the web site LMDE 6 is based on Debian 12 Bookworm. Then it should work.

@grosioso
Copy link

works with lmde 6 with debian 12.1?

nvm it did. Anyways thanks for the tutorial bro, I finally been able to install it without being stuck in initramfs

@grosioso
Copy link

another question: is it okay to use the latest nvidia-settings package or should I use the 340xx version?

@estapeluo
Copy link

estapeluo commented Jan 10, 2025

Thx. Although I still get this error:
systemd-modules-load[301]: modprobe: FATAL: Module nvidia-legacy-340xx not found in directory /lib/modules/6.11.10+bpo-amd64
systemd-modules-load[274]: Error running install command 'modprobe -i nvidia-legacy-340xx ' for module nvidia: retcode 1
systemd-modules-load[274]: Failed to insert module 'nvidia': Invalid argument

Any insights for it?

I'm just using this GT240 for a headless old pc (core2duo E8400) - I'm happy as long fan cooler work.

@estapeluo
Copy link

Well... I rebuild everything. I think doing the build as root did breaks something, also changed the CPU to a core2quad Q8300.
-Debian 6.11.10-1~bpo12+1 (2024-12-19)
-core2quad Q8300, GT240 1Gb VRAM, 8gb ram ddr2

@MaximSAzh
Copy link

Well... I rebuild everything. I think doing the build as root did breaks something, also changed the CPU to a core2quad Q8300. -Debian 6.11.10-1~bpo12+1 (2024-12-19) -core2quad Q8300, GT240 1Gb VRAM, 8gb ram ddr2

Faced the same issue...
Could you comment, what was the remedy)

@Anakiev2
Copy link
Author

@grosioso I don't know and why you want that? Everything you need to set is done in the xorg config file. You have to expect compatibility issues.

@estapeluo @MaximSAzh First you shouldn't compile as root. Only the commands starting with sudo should. Second the information you provide is not enough for me to understand what's wrong. The most probable reasons I can think of are:

You don't have the kernel headers - install the kernel header from the backports.
The backports kernel is not supported - install the older one.
Your source is too old - re download.
You don't have dkms installed.

@MaximSAzh
Copy link

@estapeluo @MaximSAzh First you shouldn't compile as root. Only the commands starting with sudo should. Second the information you provide is not enough for me to understand what's wrong. The most probable reasons I can think of are:

You don't have the kernel headers - install the kernel header from the backports. The backports kernel is not supported - install the older one. Your source is too old - re download. You don't have dkms installed.

I'm following your guide for a proxmox 8.3 installation, if it makes sense.
And "yes", I've done debuild from a root.. Will try to compile from another user.

@MaximSAzh
Copy link

Thank you very much, that helped!

@spacecdr
Copy link

spacecdr commented Feb 1, 2025

It goes perfect on a fresh minimal Debian 12 install and GeForce9400 nvidia340
The only question i have is related to X11, that was the auto-selected environment for my Gnome. Is it working even with wayland? I don't want to break the system just for this thing...
Anyway, my performance with youtube are really horrible with firefox... instead the system flies in any other aspect

@Anakiev2
Copy link
Author

Anakiev2 commented Feb 2, 2025

Wayland is not supported.

@Mawfyy
Copy link

Mawfyy commented Feb 24, 2025

Someone makes this work with VA-API? I installed many times but I can't run vainfo command using https://wiki.debian.org/HardwareVideoAcceleration

Output:

libva info: VA-API version 1.17.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
vaInitialize failed with error code -1 (unknown libva error),exit

@Anakiev2
Copy link
Author

You can use VDPAU only.

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