Using External GPUs with Linux

Today’s mainstream Linux distributions have outstanding stability and compatibility. Distributions like Manjaro and Ubuntu have a plug-and-play aspect that can give their closed source alternatives a run for their money. That said, you still occasionally run into hiccups. External GPUs, or eGPUs, have increased in popularity with the adoption of Thunderbolt, whose standard allows for a convenient, external, PCIe IO. Unfortunately, their support is still wanting.

In most major distributions external GPUs are recognized and the GPU’s drivers are properly downloaded, but they’re held to compute only workloads. This means if you have monitors plugged into the GPU, by default, they’re unused. When a GPU is detected by the kernel it’s typically left up to the display manager to initialise and use that resource. The most popular display manager, Xorg, by default does not initialize or use eGPUs. Xorg’s replacement, Wayland, doesn’t support eGPUs at all.

If Xorg supports eGPUs why is it disabled by default? I’m guessing part of it has to do with Thunderbolt’s hotplug ability. External GPUs are, by their nature, external. Most are connected via a detachable connection. Any program using a resource when that resource is disconnected will have issues. This is very true for GPUs. Xorg in its default settings will let you plug and unplug your GPU without issues. This can be useful for those using their eGPUs for computing only tasks. Imagine writing a machine learning program while on a plane, coming home and plugging your computer into an eGPU to run the program, then unplugging it to run to a meeting. If Xorg is initialized at plug then you’d need to spend time deinitializing it or just risk the consequences of unplugging your GPU. I’ve seen this first hand; while using Windows I have accidentally unplugged my GPU mid-game. Try explaining that to your teammates.

Okay, so Xorg doesn’t initialize on eGPUs by default. How do you go about telling Xorg to initialize on an eGPU? Michael Hertig, a Swiss coder, made a fantastic tool called egpu-switcher.

It’s available on Github for free. Following the program’s documentation will walk you through setting up the egpu-switcher script. After the initial setup, the script can almost completely automate the process. You’ll still need to tell the script to switch to the internal GPU before unplugging your eGPU. This, however, is as easy as typing egpu-switcher switch internal into your console. With a bit of coding skill and ingenuity, you could make a shortcut to do it.

If you’re like me however and wanted to mess around with Xorg and eGPUs yourself the Arch Linux Wiki is a fantastic resource. Their eGPU page covers almost everything you need to know to get started and can point you in the direction of many more resources. That said, I’ve taken the liberty of compiling a short list of helpful resources below.

Resources:

This article was updated on March 19, 2024

My name is Hunter and I’m a senior computer science student at New College of Florida. I spend much of my free time working on my homelab and personal, tech-related, projects. I hope this blog will fix a great error of mine; I almost never record my adventures, solutions, or projects. I have relied heavily on tech blogs growing up and I feel it would be irresponsible not to give back to that community now that I have the knowledge to.