Ubuntu eGPU Setup

Description

EGPUs are something that I really only learned about last year. My use case was playing games on my Windows 10 laptop that didn’t have graphic capabilities of it’s own that could play modern games. The key was that it had a decent CPU and a Thunderbolt 4 port. With an eGPU I was able to play many games. When I made the switch to linux I needed to find a way to accelerate X11 with the eGPU. This pulls together what my research found for Ubuntu on gdm3. Note that this is for every Ubuntu version before 22.04. In 22.04 eGPUs seem to just work without any special configurations.

Disable Wayland

First thing to do is to disable Wayland. eGPUs from what I found work the easiest with X11. Edit the file /etc/gdm3/custom.conf and ensure this line is uncommented. If it isn’t there add it in under [daemon].

WaylandEnable=false

Install Nvidia Drivers

Now install the newest Nvidia drivers using apt. You can search for it with the following command.

sudo apt search '^nvidia-driver-.*'

For me I’m using nvidia-driver-470. Now we install that package.

sudo apt install -y nvidia-driver-470

Update Xorg

Lastly edit /usr/share/X11/xorg.conf.d/10-nvidia.conf. Make sure to add the line:

Option "AllowExternalGpus" "True"

My file looks like this.

Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowExternalGpus" "True"
    Option "AllowEmptyInitialConfiguration"
    ModulePath "/usr/lib/x86_64-linux-gnu/nvidia/xorg"
EndSection

Keep in mind that this will only work with reboots. The eGPU must be plugged in when the laptop turns on.

Testing the Setup

Reboot with the eGPU connected. Then run nvidia-smi. You should see the eGPU listed.

xadlien@swift3x:~$ nvidia-smi
Sat Mar  5 07:10:07 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.103.01   Driver Version: 470.103.01   CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:07:00.0  On |                  N/A |
|  0%   24C    P3    21W / 170W |     70MiB / 12053MiB |     11%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      2598      G   /usr/lib/xorg/Xorg                 69MiB |
+-----------------------------------------------------------------------------+

Final Thoughts

From here the possibilities are endless. You could play games using the eGPU, also run computations on it for other purposes. I will be doing a post about that shortly.

UPDATE 2022/06/22

I just found out that with a new install of Ubuntu 22.04, wayland works out of the box with plug and play eGPU setups. It works so much better than X11 ever did with this configuration and I recommend using wayland with the eGPU instead.