Update build.func
Some checks failed
Bump build.func Revision / bump-revision (push) Has been cancelled

This commit is contained in:
CanbiZ 2025-09-29 11:12:29 +02:00
parent 8538a6c107
commit 1b207c3c38

View File

@ -2178,39 +2178,41 @@ build_container() {
AMD_DEVICES=() AMD_DEVICES=()
NVIDIA_DEVICES=() NVIDIA_DEVICES=()
# Check for Intel/AMD GPUs via DRI devices # Check for Intel GPU
if [[ -d /dev/dri ]]; then if lspci 2>/dev/null | grep -iq "VGA.*Intel\|Display.*Intel"; then
# Intel GPU detection msg_info "Detected Intel GPU"
if lspci | grep -iq "VGA.*Intel\|Display.*Intel"; then if [[ -d /dev/dri ]]; then
for d in /dev/dri/renderD* /dev/dri/card*; do for d in /dev/dri/renderD* /dev/dri/card*; do
[[ -e "$d" ]] && INTEL_DEVICES+=("$d") [[ -e "$d" ]] && INTEL_DEVICES+=("$d")
done done
[[ ${#INTEL_DEVICES[@]} -gt 0 ]] && msg_info "Detected Intel GPU"
fi fi
fi
# AMD GPU detection # Check for AMD GPU
if lspci | grep -iq "VGA.*AMD\|Display.*AMD\|VGA.*ATI\|Display.*ATI"; then if lspci 2>/dev/null | grep -iq "VGA.*AMD\|Display.*AMD\|VGA.*ATI"; then
msg_info "Detected AMD GPU"
if [[ -d /dev/dri ]]; then
for d in /dev/dri/renderD* /dev/dri/card*; do for d in /dev/dri/renderD* /dev/dri/card*; do
[[ -e "$d" ]] && AMD_DEVICES+=("$d") [[ -e "$d" ]] && AMD_DEVICES+=("$d")
done done
[[ ${#AMD_DEVICES[@]} -gt 0 ]] && msg_info "Detected AMD GPU"
fi fi
fi fi
# NVIDIA GPU detection # Check for NVIDIA GPU
if lspci | grep -iq "VGA.*NVIDIA\|3D.*NVIDIA"; then if lspci 2>/dev/null | grep -iq "VGA.*NVIDIA\|3D.*NVIDIA"; then
for d in /dev/nvidia*; do msg_info "Detected NVIDIA GPU"
for d in /dev/nvidia* /dev/nvidiactl /dev/nvidia-modeset; do
[[ -e "$d" ]] && NVIDIA_DEVICES+=("$d") [[ -e "$d" ]] && NVIDIA_DEVICES+=("$d")
done done
if [[ ${#NVIDIA_DEVICES[@]} -eq 0 ]]; then if [[ ${#NVIDIA_DEVICES[@]} -eq 0 ]]; then
msg_warn "NVIDIA GPU detected but no /dev/nvidia* devices found" msg_warn "NVIDIA GPU detected but no /dev/nvidia* devices found"
msg_warn "Please install NVIDIA drivers on host: apt install nvidia-driver" msg_warn "Please install NVIDIA drivers on host: apt install nvidia-driver"
else
msg_info "Detected NVIDIA GPU"
fi fi
fi fi
} }
# Configure USB passthrough for privileged containers # Configure USB passthrough for privileged containers
configure_usb_passthrough() { configure_usb_passthrough() {
if [[ "$CT_TYPE" != "0" ]]; then if [[ "$CT_TYPE" != "0" ]]; then
@ -2245,9 +2247,21 @@ EOF
# Count available GPU types # Count available GPU types
local gpu_count=0 local gpu_count=0
local available_gpus=() local available_gpus=()
[[ ${#INTEL_DEVICES[@]} -gt 0 ]] && { available_gpus+=("INTEL"); ((gpu_count++)); }
[[ ${#AMD_DEVICES[@]} -gt 0 ]] && { available_gpus+=("AMD"); ((gpu_count++)); } if [[ ${#INTEL_DEVICES[@]} -gt 0 ]]; then
[[ ${#NVIDIA_DEVICES[@]} -gt 0 ]] && { available_gpus+=("NVIDIA"); ((gpu_count++)); } available_gpus+=("INTEL")
gpu_count=$((gpu_count + 1))
fi
if [[ ${#AMD_DEVICES[@]} -gt 0 ]]; then
available_gpus+=("AMD")
gpu_count=$((gpu_count + 1))
fi
if [[ ${#NVIDIA_DEVICES[@]} -gt 0 ]]; then
available_gpus+=("NVIDIA")
gpu_count=$((gpu_count + 1))
fi
if [[ $gpu_count -eq 0 ]]; then if [[ $gpu_count -eq 0 ]]; then
msg_info "No GPU devices found for passthrough" msg_info "No GPU devices found for passthrough"
@ -2293,19 +2307,23 @@ EOF
for dev in "${devices[@]}"; do for dev in "${devices[@]}"; do
if [[ "$CT_TYPE" == "0" ]]; then if [[ "$CT_TYPE" == "0" ]]; then
# Privileged container # Privileged container
local major=$(stat -c '%t' "$dev") local major minor
local minor=$(stat -c '%T' "$dev") major=$(stat -c '%t' "$dev" 2>/dev/null || echo "0")
echo "lxc.cgroup2.devices.allow: c $((0x$major)):$((0x$minor)) rwm" >>"$LXC_CONFIG" minor=$(stat -c '%T' "$dev" 2>/dev/null || echo "0")
echo "lxc.mount.entry: $dev dev/$(basename "$dev") none bind,optional,create=file" >>"$LXC_CONFIG"
if [[ "$major" != "0" && "$minor" != "0" ]]; then
echo "lxc.cgroup2.devices.allow: c $((0x$major)):$((0x$minor)) rwm" >>"$LXC_CONFIG"
echo "lxc.mount.entry: $dev dev/$(basename "$dev") none bind,optional,create=file" >>"$LXC_CONFIG"
fi
else else
# Unprivileged container - use generic GID, will be fixed after start # Unprivileged container - use generic GID, will be fixed after start
echo "dev${dev_idx}: $dev,uid=0,gid=44" >>"$LXC_CONFIG" echo "dev${dev_idx}: $dev,uid=0,gid=44" >>"$LXC_CONFIG"
((dev_idx++)) dev_idx=$((dev_idx + 1))
fi fi
done done
# Mount entire /dev/dri for privileged containers # Mount entire /dev/dri for privileged containers
if [[ "$CT_TYPE" == "0" ]]; then if [[ "$CT_TYPE" == "0" && -d /dev/dri ]]; then
echo "lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir" >>"$LXC_CONFIG" echo "lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir" >>"$LXC_CONFIG"
fi fi
@ -2321,10 +2339,14 @@ EOF
for dev in "${NVIDIA_DEVICES[@]}"; do for dev in "${NVIDIA_DEVICES[@]}"; do
if [[ "$CT_TYPE" == "0" ]]; then if [[ "$CT_TYPE" == "0" ]]; then
local major=$(stat -c '%t' "$dev") local major minor
local minor=$(stat -c '%T' "$dev") major=$(stat -c '%t' "$dev" 2>/dev/null || echo "0")
echo "lxc.cgroup2.devices.allow: c $((0x$major)):$((0x$minor)) rwm" >>"$LXC_CONFIG" minor=$(stat -c '%T' "$dev" 2>/dev/null || echo "0")
echo "lxc.mount.entry: $dev dev/$(basename "$dev") none bind,optional,create=file" >>"$LXC_CONFIG"
if [[ "$major" != "0" && "$minor" != "0" ]]; then
echo "lxc.cgroup2.devices.allow: c $((0x$major)):$((0x$minor)) rwm" >>"$LXC_CONFIG"
echo "lxc.mount.entry: $dev dev/$(basename "$dev") none bind,optional,create=file" >>"$LXC_CONFIG"
fi
else else
msg_warn "NVIDIA passthrough on unprivileged container may not work properly" msg_warn "NVIDIA passthrough on unprivileged container may not work properly"
fi fi