[Linux] Use eGPU as primary GPU if possible?

Hi,

I’m in a situation where I want to use eGPU as primary GPU since all displays are connected to eGPU.
But on the other than, I also want to use Intel GPU if eGPU is not present.

Currently the laptop is X1C 8th gen, while the eGPU is RX580, with mesa driver.
OS is Arch.

I have tried a lot of solutions but none of them is perfect:

  1. Fully auto config
    Automatic config will use Intel GPU as primary GPU, and use DRI3 for both GPUs. Since Intel GPU is primary one, if I close the lid of laptop, displays connected to eGPU will only refresh at 1Hz.
    This is not acceptable at all, as with eGPU my primary setup is to use external keyboard and mouse, with laptop resting in a vertical laptop stand.

  2. Device section with BusID pointing to eGPU only
    This works perfect if I’m using eGPU.
    The problem is, without eGPU connect, X will not start, with the following error:

[ 33.194] (EE) Cannot run in framebuffer mode. Please specify busIDs for all framebuffer devices

Even intel GPU is already detected and driver loaded.

Any idea to generate Xorg.conf according to if an eGPU is present?
Or even more elegant solution?

BTW, it’s not a problem for hot plug/unplug, as I’m completely fine with cold plug/unplug.
Since hot unplug will just crash amdgpu module, and hot plug won’t detect screen correctly (looks like a bug in AORUS gaming box though).

Thanks.

You could use a udev hook to run some xorg.conf parsing scripts.

I really don’t know of a way to make this “automagic” without significant tooling being built.

Udev looks kinda OK.

As hot unplug/plug doesn’t work either way, it’s more or less acceptable.

But I hope to have a way to run some hook before starting X.
We have hooks for DE to do its preparation in .xprofile/.xinitrc, but not for X itself.

Lots of display managers have pre-init hooks, read the docs on the one you’re using.

Sorry I can’t be of more help, I’m not at my desk.