From a7ebf7b457db9c7a6c9aab80f93dcf9e64af9144 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Wed, 14 Oct 2026 14:38:56 +0200 Subject: [PATCH 1/3] nvidiactl: Only create device nodes if NVIDIA controllers are counted `N` is the result of an arithmetic expansion, so it is never empty, and `[ ! -z $N ]` is always true. Even with zero counted controllers, /dev/nvidiactl is created and nvidia-uvm, nvidia-modeset and nvidia-drm are loaded: $ N=$(( 0 + 0 )); if [ ! -z $N ]; then echo "taken, N=$N"; fi taken, N=0 Test for a positive count instead. Assisted-by: claude-opus-5.5 (Claude Code) --- nvidiactl/nvidiactl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvidiactl/nvidiactl b/nvidiactl/nvidiactl index 7944b08..d791136 100755 --- a/nvidiactl/nvidiactl +++ b/nvidiactl/nvidiactl @@ -82,7 +82,7 @@ NVDEVS=$(lspci | grep -i NVIDIA) N3D=$(echo "$NVDEVS" | grep "3D controller" | wc -l) NVGA=$(echo "$NVDEVS" | grep "VGA compatible controller" | wc -l) N=$(( $N3D + $NVGA )) -if [ ! -z $N ]; then +if [ $N -gt 0 ]; then N=$(( $N - 1 )) for i in $(seq 0 $N); do mknod -m 666 /dev/nvidia$i c 195 $i From 600ba7365019dd68b6ccb02003daf4ccac9da277 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Wed, 14 Oct 2026 14:39:08 +0200 Subject: [PATCH 2/3] nvidiactl: Replace existing device nodes `mknod` fails if the node already exists, for example when the service is restarted: mknod: /dev/nvidiactl: File exists Add the helper `make_chardev`, which removes an existing node before creating it. Recreating it, instead of skipping it, also makes sure the node has the current major number, which is assigned dynamically for nvidia-uvm. Assisted-by: claude-opus-5.5 (Claude Code) --- nvidiactl/nvidiactl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nvidiactl/nvidiactl b/nvidiactl/nvidiactl index d791136..4ff6a19 100755 --- a/nvidiactl/nvidiactl +++ b/nvidiactl/nvidiactl @@ -16,6 +16,12 @@ use_nouveau () { exit 1 } +# Replace an existing node, for example from an earlier run of the service. +make_chardev () { + rm -f "$1" + mknod -m 666 "$1" c "$2" "$3" +} + if [ -d /sys/module/nouveau ] ; then echo >&2 "NOTE: nouveau driver loaded already, using 'mxgfx-generic'." set_generic_mxgfx_link @@ -85,16 +91,16 @@ N=$(( $N3D + $NVGA )) if [ $N -gt 0 ]; then N=$(( $N - 1 )) for i in $(seq 0 $N); do - mknod -m 666 /dev/nvidia$i c 195 $i + make_chardev /dev/nvidia$i 195 $i done - mknod -m 666 /dev/nvidiactl c 195 255 + make_chardev /dev/nvidiactl 195 255 # CUDA if [ -e ${nvlink}/nvidia-uvm.ko ]; then insmod ${nvlink}/nvidia-uvm.ko D=$(grep nvidia-uvm /proc/devices | awk '{print $1}') if [ ! -z $D ]; then - mknod -m 666 /dev/nvidia-uvm c $D 0 + make_chardev /dev/nvidia-uvm $D 0 fi fi test -e ${nvlink}/nvidia-modeset.ko && insmod ${nvlink}/nvidia-modeset.ko From adf974bac4223467eb7cc5159a81b2ead9b7a13d Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Wed, 14 Oct 2026 14:39:19 +0200 Subject: [PATCH 3/3] nvidiactl: Do not reuse nvver for the PCI ID The variable `nvver` first holds the PCI ID of the first NVIDIA card, and is later reused for the driver version. Store the PCI ID in `pciid` instead. Also, fill the array with `mapfile` instead of word splitting, which shellcheck warns about: In nvidiactl/nvidiactl line 29: nvidiacards=( $(lspci -n | grep " 030[0,2]: 10de:" | cut -d ' ' -f 3) ) ^-- SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting). While at it, quote the variable in the emptiness test. Assisted-by: claude-opus-5.5 (Claude Code) --- nvidiactl/nvidiactl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nvidiactl/nvidiactl b/nvidiactl/nvidiactl index 4ff6a19..1a3cfbc 100755 --- a/nvidiactl/nvidiactl +++ b/nvidiactl/nvidiactl @@ -32,17 +32,17 @@ PCIIDHINT_DIR=/usr/share/nvidia/pciidhints kver=$(uname -r) -nvidiacards=( $(lspci -n | grep " 030[0,2]: 10de:" | cut -d ' ' -f 3) ) +mapfile -t nvidiacards < <(lspci -n | grep " 030[0,2]: 10de:" | cut -d ' ' -f 3) -nvver=${nvidiacards[0]} +pciid=${nvidiacards[0]} -if [ -z ${nvver} ] ; then +if [ -z "${pciid}" ] ; then echo >&2 "WARNING: no nvidia card found.." set_generic_mxgfx_link exit 0 fi -pciids="${PCIIDHINT_DIR}/${kver}-${nvver} ${PCIIDHINT_DIR}/${nvver}" +pciids="${PCIIDHINT_DIR}/${kver}-${pciid} ${PCIIDHINT_DIR}/${pciid}" for leglvlhint in ${pciids} ; do if [ -h "${leglvlhint}" ] ; then