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

@averagenokiauser
Copy link

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

What do i need to change on this config to use iGPU as the default GPU? Now my system is just using Nvidia GPU and never the integrated one to save power.

@Anakiev2
Copy link
Author

I am not sure if it's possible with driver version 340/390. You can read about different methods here.
https://wiki.archlinux.org/title/NVIDIA_Optimus#Using_PRIME_render_offload

@DanHolli
Copy link

DanHolli commented Apr 8, 2025

Just followed the instructions and I'm not able to get a working X display with lightdm, sddm, or gdm on my old macbook after the install

@Anakiev2
Copy link
Author

Anakiev2 commented Apr 8, 2025

It's been tested with lxdm but shouldn't be a problem. Did you configure /etc/X11/xorg.conf as shown? What's the output in /var/log/Xorg.0.log?

@DanHolli
Copy link

DanHolli commented Apr 8, 2025

I've configured it with both of the provided xorg.conf
Just installed and tested with lxdm, but the DM just keeps trying to start but crashes as well

following is the whole Xorg.0.log
[ 51503.575] Current Operating System: Linux Debi-Mac 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64
[ 51503.575] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-6.1.0-32-amd64 root=UUID=3c6172cd-95ac-4ff2-9cd9-1a3b42e97d76 ro reboot=acpi quiet nomodeset
[ 51503.575] xorg-server 2:21.1.7-3+deb12u9 (https://www.debian.org/support) 
[ 51503.575] Current version of pixman: 0.42.2
[ 51503.575] 	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.
[ 51503.575] Markers: (--) probed, (**) from config file, (==) default setting,
	(++) from command line, (!!) notice, (II) informational,
	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[ 51503.576] (==) Log file: "/var/log/Xorg.0.log", Time: Tue Apr  8 10:15:51 2025
[ 51503.576] (==) Using config directory: "/etc/X11/xorg.conf.d"
[ 51503.576] (==) Using system config directory "/usr/share/X11/xorg.conf.d"
[ 51503.577] (==) No Layout section.  Using the first Screen section.
[ 51503.577] (==) No screen section available. Using defaults.
[ 51503.577] (**) |-->Screen "Default Screen Section" (0)
[ 51503.577] (**) |   |-->Monitor ""
[ 51503.577] (==) No device specified for screen "Default Screen Section".
	Using the first device section listed.
[ 51503.577] (**) |   |-->Device "Device0"
[ 51503.577] (==) No monitor specified for screen "Default Screen Section".
	Using a default monitor configuration.
[ 51503.577] (**) Option "IgnoreABI" "1"
[ 51503.577] (**) Ignoring ABI Version
[ 51503.577] (==) Automatically adding devices
[ 51503.577] (==) Automatically enabling devices
[ 51503.577] (==) Automatically adding GPU devices
[ 51503.577] (==) Automatically binding GPU devices
[ 51503.577] (==) Max clients allowed: 256, resource mask: 0x1fffff
[ 51503.577] (WW) The directory "/usr/share/fonts/X11/cyrillic" does not exist.
[ 51503.577] 	Entry deleted from font path.
[ 51503.578] (==) FontPath set to:
	/usr/share/fonts/X11/misc,
	/usr/share/fonts/X11/100dpi/:unscaled,
	/usr/share/fonts/X11/75dpi/:unscaled,
	/usr/share/fonts/X11/Type1,
	/usr/share/fonts/X11/100dpi,
	/usr/share/fonts/X11/75dpi,
	built-ins
[ 51503.578] (**) ModulePath set to "/usr/lib/xorg/modules/linux,/usr/lib/xorg/modules"
[ 51503.578] (II) The server relies on udev to provide the list of input devices.
	If no devices become available, reconfigure udev or disable AutoAddDevices.
[ 51503.578] (II) Loader magic: 0x5625ef148f00
[ 51503.578] (II) Module ABI versions:
[ 51503.578] 	X.Org ANSI C Emulation: 0.4
[ 51503.578] 	X.Org Video Driver: 25.2
[ 51503.578] 	X.Org XInput driver : 24.4
[ 51503.578] 	X.Org Server Extension : 10.0
[ 51503.584] (++) using VT number 7

[ 51503.584] (II) systemd-logind: logind integration requires -keeptty and -keeptty was not provided, disabling logind integration
[ 51503.585] (II) xfree86: Adding drm device (/dev/dri/card0)
[ 51503.585] (II) Platform probe for /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0
[ 51503.591] (--) PCI:*(1@0:0:0) 10de:0407:106b:00a4 rev 161, Mem @ 0xd2000000/16777216, 0xc0000000/268435456, 0xd0000000/33554432, I/O @ 0x00007000/128, BIOS @ 0x????????/131072
[ 51503.591] (II) "glx" will be loaded by default.
[ 51503.591] (II) LoadModule: "modesetting"
[ 51503.591] (II) Loading /usr/lib/xorg/modules/drivers/modesetting_drv.so
[ 51503.592] (II) Module modesetting: vendor="X.Org Foundation"
[ 51503.592] compiled for 1.21.1.7, module version = 1.21.1
[ 51503.592] Module class: X.Org Video Driver
[ 51503.592] ABI class: X.Org Video Driver, version 25.2
[ 51503.592] (II) LoadModule: "glx"
[ 51503.592] (II) Loading /usr/lib/xorg/modules/linux/libglx.so
[ 51503.618] (II) Module glx: vendor="NVIDIA Corporation"
[ 51503.618] compiled for 4.0.2, module version = 1.0.0
[ 51503.618] Module class: X.Org Server Extension
[ 51503.618] (II) NVIDIA GLX Module 340.108 Wed Dec 11 14:26:50 PST 2019
[ 51503.618] (II) LoadModule: "nvidia"
[ 51503.618] (II) Loading /usr/lib/xorg/modules/drivers/nvidia_drv.so
[ 51503.619] (II) Module nvidia: vendor="NVIDIA Corporation"
[ 51503.619] compiled for 4.0.2, module version = 1.0.0
[ 51503.619] Module class: X.Org Video Driver
[ 51503.619] ================ WARNING WARNING WARNING WARNING ================
[ 51503.619] This server has a video driver ABI version of 25.2 that this
driver does not officially support. Please check
http://www.nvidia.com/ for driver updates or downgrade to an X
server with a supported driver ABI.
[ 51503.619] =================================================================
[ 51503.619] (WW) NVIDIA: The driver will continue to load, but may behave strangely.
[ 51503.619] (WW) NVIDIA: This driver was compiled against the X.Org server SDK from commit e6ef2b12404dfec7f23592a3524d2a63d9d25802 and may not be compatible with the final version of this SDK.
[ 51503.619] (II) modesetting: Driver for Modesetting Kernel Drivers: kms
[ 51503.619] (II) NVIDIA dlloader X Driver 340.108 Wed Dec 11 14:06:00 PST 2019
[ 51503.619] (II) NVIDIA Unified Driver for all Supported NVIDIA GPUs
[ 51503.619] (WW) Falling back to old probe method for modesetting
[ 51503.619] (WW) Falling back to old probe method for modesetting
[ 51503.619] (EE) No devices detected.
[ 51503.619] (EE)
Fatal server error:
[ 51503.619] (EE) no screens found(EE)
[ 51503.620] (EE)
Please consult the The X.Org Foundation support
at http://wiki.x.org
for help.
[ 51503.620] (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
[ 51503.620] (EE)
[ 51503.624] (EE) Server terminated with error (1). Closing log file.

edit: also here is LXDE's log
[ 51503.575] Current Operating System: Linux Debi-Mac 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64
[ 51503.575] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-6.1.0-32-amd64 root=UUID=3c6172cd-95ac-4ff2-9cd9-1a3b42e97d76 ro reboot=acpi quiet nomodeset
[ 51503.575] xorg-server 2:21.1.7-3+deb12u9 (https://www.debian.org/support) 
[ 51503.575] Current version of pixman: 0.42.2
[ 51503.575] 	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.
[ 51503.575] Markers: (--) probed, (**) from config file, (==) default setting,
	(++) from command line, (!!) notice, (II) informational,
	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[ 51503.576] (==) Log file: "/var/log/Xorg.0.log", Time: Tue Apr  8 10:15:51 2025
[ 51503.576] (==) Using config directory: "/etc/X11/xorg.conf.d"
[ 51503.576] (==) Using system config directory "/usr/share/X11/xorg.conf.d"
[ 51503.577] (==) No Layout section.  Using the first Screen section.
[ 51503.577] (==) No screen section available. Using defaults.
[ 51503.577] (**) |-->Screen "Default Screen Section" (0)
[ 51503.577] (**) |   |-->Monitor ""
[ 51503.577] (==) No device specified for screen "Default Screen Section".
	Using the first device section listed.
[ 51503.577] (**) |   |-->Device "Device0"
[ 51503.577] (==) No monitor specified for screen "Default Screen Section".
	Using a default monitor configuration.
[ 51503.577] (**) Option "IgnoreABI" "1"
[ 51503.577] (**) Ignoring ABI Version
[ 51503.577] (==) Automatically adding devices
[ 51503.577] (==) Automatically enabling devices
[ 51503.577] (==) Automatically adding GPU devices
[ 51503.577] (==) Automatically binding GPU devices
[ 51503.577] (==) Max clients allowed: 256, resource mask: 0x1fffff
[ 51503.577] (WW) The directory "/usr/share/fonts/X11/cyrillic" does not exist.
[ 51503.577] 	Entry deleted from font path.
[ 51503.578] (==) FontPath set to:
	/usr/share/fonts/X11/misc,
	/usr/share/fonts/X11/100dpi/:unscaled,
	/usr/share/fonts/X11/75dpi/:unscaled,
	/usr/share/fonts/X11/Type1,
	/usr/share/fonts/X11/100dpi,
	/usr/share/fonts/X11/75dpi,
	built-ins
[ 51503.578] (**) ModulePath set to "/usr/lib/xorg/modules/linux,/usr/lib/xorg/modules"
[ 51503.578] (II) The server relies on udev to provide the list of input devices.
	If no devices become available, reconfigure udev or disable AutoAddDevices.
[ 51503.578] (II) Loader magic: 0x5625ef148f00
[ 51503.578] (II) Module ABI versions:
[ 51503.578] 	X.Org ANSI C Emulation: 0.4
[ 51503.578] 	X.Org Video Driver: 25.2
[ 51503.578] 	X.Org XInput driver : 24.4
[ 51503.578] 	X.Org Server Extension : 10.0
[ 51503.584] (++) using VT number 7

[ 51503.584] (II) systemd-logind: logind integration requires -keeptty and -keeptty was not provided, disabling logind integration
[ 51503.585] (II) xfree86: Adding drm device (/dev/dri/card0)
[ 51503.585] (II) Platform probe for /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0
[ 51503.591] (--) PCI:*(1@0:0:0) 10de:0407:106b:00a4 rev 161, Mem @ 0xd2000000/16777216, 0xc0000000/268435456, 0xd0000000/33554432, I/O @ 0x00007000/128, BIOS @ 0x????????/131072
[ 51503.591] (II) "glx" will be loaded by default.
[ 51503.591] (II) LoadModule: "modesetting"
[ 51503.591] (II) Loading /usr/lib/xorg/modules/drivers/modesetting_drv.so
[ 51503.592] (II) Module modesetting: vendor="X.Org Foundation"
[ 51503.592] compiled for 1.21.1.7, module version = 1.21.1
[ 51503.592] Module class: X.Org Video Driver
[ 51503.592] ABI class: X.Org Video Driver, version 25.2
[ 51503.592] (II) LoadModule: "glx"
[ 51503.592] (II) Loading /usr/lib/xorg/modules/linux/libglx.so
[ 51503.618] (II) Module glx: vendor="NVIDIA Corporation"
[ 51503.618] compiled for 4.0.2, module version = 1.0.0
[ 51503.618] Module class: X.Org Server Extension
[ 51503.618] (II) NVIDIA GLX Module 340.108 Wed Dec 11 14:26:50 PST 2019
[ 51503.618] (II) LoadModule: "nvidia"
[ 51503.618] (II) Loading /usr/lib/xorg/modules/drivers/nvidia_drv.so
[ 51503.619] (II) Module nvidia: vendor="NVIDIA Corporation"
[ 51503.619] compiled for 4.0.2, module version = 1.0.0
[ 51503.619] Module class: X.Org Video Driver
[ 51503.619] ================ WARNING WARNING WARNING WARNING ================
[ 51503.619] This server has a video driver ABI version of 25.2 that this
driver does not officially support. Please check
http://www.nvidia.com/ for driver updates or downgrade to an X
server with a supported driver ABI.
[ 51503.619] =================================================================
[ 51503.619] (WW) NVIDIA: The driver will continue to load, but may behave strangely.
[ 51503.619] (WW) NVIDIA: This driver was compiled against the X.Org server SDK from commit e6ef2b12404dfec7f23592a3524d2a63d9d25802 and may not be compatible with the final version of this SDK.
[ 51503.619] (II) modesetting: Driver for Modesetting Kernel Drivers: kms
[ 51503.619] (II) NVIDIA dlloader X Driver 340.108 Wed Dec 11 14:06:00 PST 2019
[ 51503.619] (II) NVIDIA Unified Driver for all Supported NVIDIA GPUs
[ 51503.619] (WW) Falling back to old probe method for modesetting
[ 51503.619] (WW) Falling back to old probe method for modesetting
[ 51503.619] (EE) No devices detected.
[ 51503.619] (EE)
Fatal server error:
[ 51503.619] (EE) no screens found(EE)
[ 51503.620] (EE)
Please consult the The X.Org Foundation support
at http://wiki.x.org
for help.
[ 51503.620] (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
[ 51503.620] (EE)
[ 51503.624] (EE) Server terminated with error (1). Closing log file.

@Anakiev2
Copy link
Author

Anakiev2 commented Apr 9, 2025

Your driver is installed properly and loaded. You either have Nvidia Optimus but you haven't configured it properly or your GPU needs different driver/version.

[ 51503.619] (EE) No devices detected.
Fatal server error:
[ 51503.619] (EE) no screens found(EE)

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