Created
May 14, 2026 13:16
-
-
Save KokoseiJ/25712137bc82bf0724de059fa3971e89 to your computer and use it in GitHub Desktop.
eGPU detection and Xorg configuration script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description="eGPU Xorg configuration" | |
| Before=display-manager.service | |
| [Service] | |
| Type=oneshot | |
| RemainAfterExit=yes | |
| ExecStart=/usr/local/bin/egpu-detect | |
| [Install] | |
| RequiredBy=display-manager.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| TIMEOUT=10 | |
| BUS='0000:08:00.0' | |
| VID='0x1002' | |
| PID='0x73ff' | |
| CONFIG_PATH='/etc/X11/xorg.conf.d/00-egpu.conf' | |
| bus_path="/sys/bus/pci/devices/${BUS}" | |
| rm -rf "${CONFIG_PATH}" | |
| udevadm wait -t 1 "${bus_path}" | |
| egpu_not_there=$? | |
| if [ ${egpu_not_there} -eq 1 ] || \ | |
| [ "$(cat "${bus_path}/vendor")" != "${VID}" ] || \ | |
| [ "$(cat "${bus_path}/device")" != "${PID}" ] | |
| then | |
| echo "eGPU not detected" | |
| exit 0 | |
| fi | |
| echo "eGPU detected" | |
| udevadm wait -t ${TIMEOUT} "/dev/dri/by-path/pci-${BUS}-card" | |
| card_path="$(find "${bus_path}/drm/" -maxdepth 1 -name "card*" -print -quit)" | |
| monitor_detect="$(find "${card_path}" -name "status" \ | |
| -execdir sh -c '[ "$(cat "$0")" = "connected" ] && echo "1"' {} \;)" | |
| if [ -n "${monitor_detect}" ] | |
| then | |
| echo "Monitor plugged in" | |
| cat > ${CONFIG_PATH} <<EOF | |
| Section "ServerFlags" | |
| Option "AutoAddGPU" "Off" | |
| EndSection | |
| Section "Device" | |
| Identifier "DeviceEGPU" | |
| Driver "amdgpu" | |
| BusID "PCI:8:0:0" | |
| Option "TearFree" "On" | |
| Option "Monitor-HDMI-A-1" "MonitorMain" | |
| Option "Monitor-DisplayPort-6" "MonitorSub" | |
| EndSection | |
| Section "Monitor" | |
| Identifier "MonitorMain" | |
| Option "Primary" "On" | |
| Option "PreferredMode" "1920x1080" | |
| Option "Position" "1200 420" | |
| EndSection | |
| Section "Monitor" | |
| Identifier "MonitorSub" | |
| Option "Primary" "Off" | |
| Option "PreferredMode" "1920x1200" | |
| Option "Rotate" "left" | |
| Option "Position" "0 0" | |
| EndSection | |
| Section "Screen" | |
| Identifier "ScreenMain" | |
| Device "DeviceEGPU" | |
| Monitor "MonitorMain" | |
| SubSection "Display" | |
| Depth 24 | |
| Virtual 8192 8192 | |
| EndSubSection | |
| EndSection | |
| EOF | |
| else | |
| echo "No monitor plugged in" | |
| cat > ${CONFIG_PATH} <<EOF | |
| Section "Device" | |
| Identifier "DeviceEGPU" | |
| Driver "amdgpu" | |
| BusID "PCI:8:0:0" | |
| EndSection | |
| Section "Device" | |
| Identifier "DeviceIGPU" | |
| Driver "amdgpu" | |
| BusID "PCI:196:0:0" | |
| Option "TearFree" "On" | |
| EndSection | |
| Section "Screen" | |
| Identifier "ScreenMain" | |
| Device "DeviceIGPU" | |
| GPUDevice "DeviceEGPU" | |
| SubSection "Display" | |
| Depth 24 | |
| Virtual 8192 8192 | |
| EndSubSection | |
| EndSection | |
| EOF | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment