OPINIONATED OMARCHY
TROUBLESHOOTING CORPUS
790
RECORDS
790
AUDITED
0
UNCHECKED
2388
SOURCES
LIVE
gpu-drivers medium rare DISPUTE

Hotplug an NVIDIA eGPU on Wayland without rebooting

archomarchyendeavouroscachyosnvidiawaylandhyprlandlaptop
CORRECTED An auditor found the fix wrong or incomplete and rewrote it.
AUDIT NOTE

The core sequence is lifted correctly from Arch's External_GPU#'Hotplugging NVIDIA eGPU'. The 1 MB-per-EGL-program explanation, /etc/environment.d/50_mesa.conf, the exact rmmod order (uvm, drm, modeset, nvidia), modprobe nvidia-drm to reload, and the four-variable offload string are all the wiki's own. What is missing will stop most readers cold. (1) The Thunderbolt device must be authorized (boltctl / BIOS setting), and the record says 'wait for Thunderbolt to authorise it' without saying how. (2) Many laptops need PCIe hotplug kernel parameters before an eGPU is enumerated at all. (3) If the nvidia modules are early-loaded from the initramfs (which records [0] and [2] tell users to configure) or modeset/fbdev has bound a console, rmmod fails no matter how many EGL clients you kill, and the record's only answer to that is lsof.

The cause above was not rewritten and may still contain the error described. The fix below is the corrected version.
RISK

Unloading nvidia_drm while the compositor is running on the NVIDIA GPU will kill your session. Do this only when the internal iGPU drives the display, and preferably from a TTY. Physically hot-unplugging a Thunderbolt eGPU while the driver holds it can hang the kernel.

Symptom

A Thunderbolt eGPU enclosure plugged in after boot is not picked up: nvidia-smi does not list it, or the driver grabs it but every application still renders on the internal GPU. Unplugging and replugging changes nothing.

Cause

The NVIDIA modules must not be in use when the eGPU is attached, and stray EGL clients hold the internal dGPU (each EGL program pins ~1 MB of dGPU memory even while rendering on the iGPU), so the modules cannot be unloaded and the new device is never enumerated.

Fix

Default everything to Mesa so nothing pins the internal dGPU:


sudo tee /etc/environment.d/50_mesa.conf >/dev/null <<'EOF'
__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json
EOF

If the enclosure never appears in lspci -d ::03xx at all, add the PCIe hotplug kernel parameters (Arch External GPU) and reboot:


pcie_ports=native pci=assign-busses,hpbussize=0x33,realloc,hpmmiosize=128M,hpmmioprefsize=16G

Ensure the nvidia modules are NOT early-loaded, or they cannot be unloaded later:


ls /etc/mkinitcpio.conf.d/nvidia.conf 2>/dev/null && sudo rm /etc/mkinitcpio.conf.d/nvidia.conf && sudo mkinitcpio -P

Log out and back in, then with the eGPU **unplugged**:


sudo modprobe -r nvidia_uvm nvidia_drm nvidia_modeset nvidia

If that fails with 'Module nvidia is in use', find the holders and stop them:


sudo lsof +c0 /dev/nvidia*

Plug in the eGPU and authorize the Thunderbolt device (skip if your firmware is set to auto-authorize):


boltctl list
boltctl authorize <uuid>      # add --enroll to remember it
lspci -d ::03xx               # the eGPU should now be listed

Reload and confirm:


sudo modprobe nvidia_drm
nvidia-smi

Run a program on the eGPU by re-enabling the NVIDIA vendor for that process only:


__GLX_VENDOR_LIBRARY_NAME=nvidia \
__NV_PRIME_RENDER_OFFLOAD=1 \
__VK_LAYER_NV_optimus=NVIDIA_only \
__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json \
<command>

Hyprland also needs to be told the eGPU exists. See the AQ_DRM_DEVICES record.

Verify

nvidia-smi lists the eGPU. The offload command above reports the eGPU in glxinfo | grep "OpenGL renderer".

Sources

egpu-nvidia-hotplug-wayland