gpu passtrough moved to separate file

This commit is contained in:
Dobromir Popov
2025-11-22 14:48:58 +02:00
parent 23b4e1a8ee
commit 185d4f520b
6 changed files with 414 additions and 25 deletions

View File

@@ -0,0 +1,79 @@
#!/bin/bash
# Manually bind the AMD GPU to VFIO for Windows container passthrough
# Run this BEFORE starting the Windows container
set -e
if [ "$EUID" -ne 0 ]; then
echo "Please run as root: sudo $0"
exit 1
fi
echo "=== Binding AMD GPU to VFIO ==="
echo ""
GPU_PCI="0000:c5:00.0"
AUDIO_PCI="0000:c5:00.1"
# Check if vfio-pci module is loaded
if ! lsmod | grep -q vfio_pci; then
echo "Loading vfio-pci module..."
modprobe vfio-pci
fi
# Unbind GPU from amdgpu
echo "Unbinding GPU from amdgpu..."
if [ -e /sys/bus/pci/devices/$GPU_PCI/driver ]; then
echo "$GPU_PCI" > /sys/bus/pci/devices/$GPU_PCI/driver/unbind
echo "✓ GPU unbound from amdgpu"
else
echo "GPU not bound to any driver"
fi
# Unbind audio from snd_hda_intel
echo "Unbinding audio from snd_hda_intel..."
if [ -e /sys/bus/pci/devices/$AUDIO_PCI/driver ]; then
echo "$AUDIO_PCI" > /sys/bus/pci/devices/$AUDIO_PCI/driver/unbind
echo "✓ Audio unbound"
else
echo "Audio not bound to any driver"
fi
# Bind to vfio-pci
echo ""
echo "Binding to vfio-pci..."
echo "1002 1586" > /sys/bus/pci/drivers/vfio-pci/new_id 2>/dev/null || echo "GPU ID already registered"
echo "1002 1640" > /sys/bus/pci/drivers/vfio-pci/new_id 2>/dev/null || echo "Audio ID already registered"
sleep 1
# Verify
GPU_DRIVER=$(lspci -nnk -s c5:00.0 | grep "Kernel driver in use" | awk '{print $5}')
AUDIO_DRIVER=$(lspci -nnk -s c5:00.1 | grep "Kernel driver in use" | awk '{print $5}')
echo ""
echo "=== Status ==="
if [ "$GPU_DRIVER" = "vfio-pci" ]; then
echo "✓ GPU bound to vfio-pci"
else
echo "✗ GPU bound to: ${GPU_DRIVER:-none}"
fi
if [ "$AUDIO_DRIVER" = "vfio-pci" ]; then
echo "✓ Audio bound to vfio-pci"
else
echo "✗ Audio bound to: ${AUDIO_DRIVER:-none}"
fi
echo ""
if [ "$GPU_DRIVER" = "vfio-pci" ] && [ "$AUDIO_DRIVER" = "vfio-pci" ]; then
echo "✓ Ready for GPU passthrough!"
echo ""
echo "Now start the Windows container:"
echo " cd /mnt/shared/DEV/repos/d-popov.com/scripts/portainer-compose-stacks/windows"
echo " docker compose up -d"
else
echo "✗ Binding failed. Check errors above."
fi