Fix NVIDIA passthrough logic in container build
Some checks failed
Bump build.func Revision / bump-revision (push) Has been cancelled

Refactored the NVIDIA GPU passthrough configuration to ensure device entries and related settings are only added when /dev/nvidia* devices are present. This prevents passthrough configuration attempts when no NVIDIA devices are detected, improving reliability and error messaging.
This commit is contained in:
CanbiZ 2025-09-30 09:13:44 +02:00
parent 2d0b42ae45
commit e7936a686a

View File

@ -2198,6 +2198,7 @@ build_container() {
msg_info "Fix NVIDIA drivers on host, then recreate container or passthrough manually."
return 0
fi
for d in /dev/nvidia* /dev/nvidiactl /dev/nvidia-modeset; do
[[ -e "$d" ]] && NVIDIA_DEVICES+=("$d")
done
@ -2205,7 +2206,7 @@ build_container() {
if [[ ${#NVIDIA_DEVICES[@]} -eq 0 ]]; then
msg_warn "NVIDIA GPU detected but no /dev/nvidia* devices found"
msg_warn "Please install NVIDIA drivers on host: apt install nvidia-driver"
fi
else
if [[ "$CT_TYPE" == "0" ]]; then
cat <<EOF >>"$LXC_CONFIG"
# NVIDIA GPU Passthrough (privileged)
@ -2216,7 +2217,7 @@ build_container() {
lxc.mount.entry: /dev/nvidia-uvm dev/nvidia-uvm none bind,optional,create=file
lxc.mount.entry: /dev/nvidia-uvm-tools dev/nvidia-uvm-tools none bind,optional,create=file
EOF
fi
if [[ -e /dev/dri/renderD128 ]]; then
echo "lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file" >>"$LXC_CONFIG"
fi
@ -2229,7 +2230,7 @@ build_container() {
return 0
fi
fi
}
fi
# Debug output
msg_debug "Intel devices: ${INTEL_DEVICES[*]}"