Debian + NVIDIA + obs
Setting up NVIDIA to work in Debian x84_64 without a drop of sweat.
Motivation
Just recently bought a new desktop with an NVIDIA RTX 4070.
To be honest I should have spent more time researching about GPUs in Linux, but I didn’t. So I end up spending some (good) time learning on how to make this work in Debian.
The following is everythin you need in 2024 to have nvenc support in Debian.
You can updated version of packages and specifications here
Show me the code!
-
I will assume you have installed Debian bookworm already.
-
I will assume you use the root user.
-
Suggestions to go through the details to learn more about CUDA
-
Install CUDA packages
wget https://developer.download.nvidia.com/compute/cuda/12.5.0/local_installers/cuda-repo-debian12-12-5-local_12.5.0-555.42.02-1_amd64.deb
sudo dpkg -i cuda-repo-debian12-12-5-local_12.5.0-555.42.02-1_amd64.deb
cp /var/cuda-repo-debian12-12-5-local/cuda-*-keyring.gpg /usr/share/keyrings/
add-apt-repository contrib
apt-get update
apt-get -y install cuda-toolkit-12-5
- Install open kernel NVIDIA driver (say yes to disable nouveau module during installation)
apt-get install -y nvidia-kernel-open-dkms
apt-get install -y cuda-drivers
- Restart your machine so the new driver is enabled
After restart you should have working the driver. Check all is good(you have to be running a Linux display manager):
- In your terminal:
nvidia-smi
-
Or open the
NVIDIA settings
app in your desktop. -
Check if nvidia-uvm is enabled
ls /dev/nvidia-uvm*
If you see /dev/nvidia-uvm
and /dev/nvidia-uvm-tools
you are all set otherwise continue reading.
So you are almost there, all you have to do now is to enable nvidia-uvm.
If you don’t enable this OBS will fail to connect to the GPU. Still don’t know why this is not setup by default in debian.
The following is a simplification of a Reddit post you can find here
- Create an init file
/lib/systemd/system/nvidia-uvm-init.service
and add the following content:
#!/bin/bash
## Script to initialize nvidia device nodes.
## https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#runfile-verifications
/sbin/modprobe nvidia-uvm
if [ "$?" -eq 0 ]; then
# Find out the major device number used by the nvidia-uvm driver
D=`grep nvidia-uvm /proc/devices | awk '{print $1}'`
mknod -m 666 /dev/nvidia-uvm c $D 0
mknod -m 666 /dev/nvidia-uvm-tools c $D 0
else
exit 1
fi
- Make sure it can be executed
chmod +x /lib/systemd/system/nvidia-uvm-init.service
- Run the service
systemctl start nvidia-uvm-init.service
- Enable service execution at startup
systemctl enable nvidia-uvm-init.service
At this moment you should (almost) done!
- Check if nvidia-uvm is enabled (you should see 2 entries)
ls /dev/nvidia-uvm*
If this is the case, you can now configure OBS to use x264_nvenc encoder!
You can also download an mp4 file and test encoding in the terminal:
- Install ffmpeg if you don’t have it
apt install ffmpeg
- Download any file and name it input.mp4 and run
ffmpeg -i input.mp4 -c:v h264_nvenc -b:v 5M output.mp4
Hope this helps!