Share:

Alternate script for eGPU (automated detection @ boot, configure X)  

  RSS

(@tara_fitzgerald)
Active Member
Joined: 3 months ago
Posts: 10
February 12, 2019 2:41 am  

Hi, folks,

Thought I'd share the config/setup that I'm using for my eGPU automatic detection at boot, and change of xorg.conf files before starting the DM. Hopefully somebody will find it useful.

Why I did it: Because I can. But also because I don't like sebulon's script for a few reasons - I don't run a debian-based distro, and while it's possible to install a .deb on my distro of choice it can be problematic especially as it comes to dependencies. As I'm on a rolling release distro especially, a PPA is impossible and installing a .deb that doesn't change leaves the possibility of it getting broken by a future update. I also don't even have qt installed, so his gui is a non-starter, and don't really like having to manually change the configuration. This way, if I want to use the eGPU, I just plug it in & reboot - it'll detect the presence of the eGPU on boot and configure X accordingly. That said, if you are using his script, the /usr/bin/egpu script can be tweaked to use his script instead of manually changing the configuration. (ed: You don't actually have to use a PPA or .deb to use Sebulon's script - he has provided other ways to obtain it 🙂 )

The how:
There's 3 scripts that you need to create/install on your system, and a service you need to create/enable.
/usr/bin/egpu:    https://pastebin.com/tdXQzzCU
/etc/systemd/system/egpu.service:   https://pastebin.com/swxKCAyR
/etc/X11/xorg.conf.d/disabled/21-egpu.conf:  https://pastebin.com/UxaTf0Dn   (you'll likely have to create the disabled subfolder)

That's it, that's all. You'll need to tweak the 21-egpu.conf for your specific system/configuration, but otherwise you should be good to go. Just enable the egpu service, and it'll detect on boot & configure xorg appropriately.

To enable the service:

sudo systemctl enable egpu

As for how to tweak the 21-egpu.conf file, you need to make sure it has the right drivers for your GPU, and the right BusID, in decimal form. If you type

lspci | grep VGA

it'll give you a list of your video cards & their identifiers. Such as:

00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07)

In this case, as you can see from my 21-egpu.conf file, the Intel (modesetting) graphics driver is PCI:0:2:0. To get the BusID, change any hexadecimal numbers into decimal, and replace the dot with a colon.

It's important to set your integrated graphics to modesetting if you're using displays that are plugged into it (such as on a laptop) - otherwise some applications can render using the wrong GPU, even if you're launching using DRI_PRIME=1. In my case, for example, I have an XFX RX580 GTS Black Edition OC+ 8GB video card in a Razer Core X eGPU enclosure. On a 2560x1080 panel I was getting 7-10fps on the Unigine Heaven (medium) benchmark before I set modesetting. After setting it, I got framerates in the range you'd expect them to be - 40+fps on ultra. (the card's capable of better in a desktop configuration, but an eGPU on Thunderbolt3 only has 4 PCIe lanes). By setting modesetting, you'll use the integrated graphics as a canvas that the eGPU can draw to.

One last configuration that's entirely optional, but is harmless, is to add a line to your ~/.profile

export DRI_PRIME=1

This setting is 100% optional. It'll save you having to specifically edit the launchers for applications you want to run using PRIME, but at the expense of having everything (including your desktop environment) render using the eGPU. For me, that's not a problem - if I am booting up with the eGPU connected in the first place, it's because I intend to use it. Somewhat counterintuitively, the frame rates I saw in Heaven actually improved slightly when I made this change but your mileage may vary. The environment variable will be ignored if there is only one GPU connected.

Hope somebody finds this useful. 🙂 It's possible to use on a system that's using System V or upstart instead of systemd, but I didn't see the need as most distros are going with systemd these days. If you need help getting it running on one of the other systems, just ask 🙂

This topic was modified 2 months ago

System: Tuxedo InfinityBook Pro 13", i5-8250u, 16GB RAM, 1TB NVMe
eGPU: Razer Core X, 8GB XFX RX580 GTS Black Edition OC+
OS: Arch Linux


Quote
nu_ninja
(@nu_ninja)
Estimable Member
Joined: 1 year ago
Posts: 147
February 12, 2019 3:30 am  

Nice, systemctl is a better tool than what I was originally using. FYI, I wrote a more complicated script I posted here for figuring out if the eGPU is attached. Instead of just counting the number (which could be thrown off by a dGPU laptop) it tries to find a match for the BusID from the config file. You should be able to just change the file path and if/else contents.

Mid-2012 13" Macbook Pro (MacBookPro9,2) TB1 -> RX 460/560 (AKiTiO Node/Thunder2)
+ macOS 10.14.2+Win10
+ Linux Mint 19.1


ReplyQuote
(@tara_fitzgerald)
Active Member
Joined: 3 months ago
Posts: 10
February 12, 2019 1:29 pm  

Thank you 🙂

You could just change the expected count to 3 for the eGPU check script if you're in a laptop that has a dGPU, iGPU, and eGPU. I'll be honest, it hadn't even occurred to me that you might be in a situation where you're using an eGPU to offload from a system that already has a dGPU. If you need a different xorg.conf file for the 2-gpu vs. 3-gpu configuration, the same egpu script can be tweaked as well.

I can provide instructions for how to do that, if folks need. The short version is create a 2nd xorg conf file for the no-eGPU configuration, and have it swap the conf files instead of copying or deleting the conf.

System: Tuxedo InfinityBook Pro 13", i5-8250u, 16GB RAM, 1TB NVMe
eGPU: Razer Core X, 8GB XFX RX580 GTS Black Edition OC+
OS: Arch Linux


ReplyQuote
(@michael_watkins)
New Member
Joined: 2 months ago
Posts: 4
February 17, 2019 3:14 pm  

I am struggling with this. I'm newer to Linux at a lot of this. My issue is that I have no xorg in X11. Would it be possible to get a full tutorial on start to finish from install of Ubuntu to getting external monitors working. Also when your doing all of this do you the have thunderbolt 3 cable plugged in? If not at what point do you plug it in. For me every time I try to save x configuration it fails. Says I have no xorg server or something like that .

This post was modified 2 months ago

Pending: 2018 Lenovo X1 Extreme / Razer Core v2 my signature to give context to my posts


ReplyQuote
nu_ninja
(@nu_ninja)
Estimable Member
Joined: 1 year ago
Posts: 147
February 17, 2019 7:12 pm  

See my build guide in my signature. If you want to use them, the scripts from this thread would replace steps 3 and 4. You can leave the eGPU plugged in the whole time.

Edit: Also note these steps are only for X11, not wayland. If at the login screen, clicking the gear icon shows "Ubuntu on Wayland" selected, then that would be the problem.

This post was modified 2 months ago

Mid-2012 13" Macbook Pro (MacBookPro9,2) TB1 -> RX 460/560 (AKiTiO Node/Thunder2)
+ macOS 10.14.2+Win10
+ Linux Mint 19.1


ReplyQuote
Sebulon
(@sebulon)
Eminent Member
Joined: 5 months ago
Posts: 36
February 22, 2019 6:55 pm  
Posted by: Tara FitzGerald

But also because I don't like sebulon's script for a few reasons

Resistance is futile. You will be assimilated 🙂

Posted by: Tara FitzGerald

- I don't run a debian-based distro, and while it's possible to install a .deb on my distro of choice it can be problematic especially as it comes to dependencies. As I'm on a rolling release distro especially, a PPA is impossible and installing a .deb that doesn't change leaves the possibility of it getting broken by a future update. I also don't even have qt installed, so his gui is a non-starter, and don't really like having to manually change the configuration.

Just a few very general clarifications here:

  • I have in my top post linked to the GitHub repository where the base "gswitch" command is just a plain shell-script, with an equally plain setup script that comes with it. You can if you want just wget the setup-script that wget's the rest of files needed for it. No .deb's as far as the eye can see 😉
  • I completely share your view on PPA's, a point I myself have made in my thread, but you just can't beat the on-boarding experience for beginners coming (most likely) to Ubuntu, from Windows. But I designed it specifically not being dependent on the PPA. That's why I have described in each of the repo's how you can clone and build the .deb's locally on your own machine if that's what you want.
  • Just because I have "seen the light" of KDE doesn't mean I want to force my preference onto others, so I designed it so that the base "gswitch" package doesn't depend on the GUI. But of course, the GUI does depend on it's base 🙂
Posted by: Tara FitzGerald

There's 3 scripts that you need to create/install on your system, and a service you need to create/enable.

I think your scripts look great, a lot similar to what @nu_ninja has done. We've talked a bit about giving this boot feature to "gswitch" and I'm not totally against it. I'd be happy to see a pull request some day from either of you. It would be great if we could join forces 🙂

By the way, what is your distro of choice?

Pending: Add my system information and expected eGPU configuration to my signature to give context to my posts


ReplyQuote
(@tara_fitzgerald)
Active Member
Joined: 3 months ago
Posts: 10
February 23, 2019 6:26 am  

Just a few very general clarifications here:

  • I have in my top post linked to the GitHub repository where the base "gswitch" command is just a plain shell-script, with an equally plain setup script that comes with it. You can if you want just wget the setup-script that wget's the rest of files needed for it. No .deb's as far as the eye can see 😉
  • I completely share your view on PPA's, a point I myself have made in my thread, but you just can't beat the on-boarding experience for beginners coming (most likely) to Ubuntu, from Windows. But I designed it specifically not being dependent on the PPA. That's why I have described in each of the repo's how you can clone and build the .deb's locally on your own machine if that's what you want.

Fair points... 🙂 I'll edit the original post to make it clear.

  • Just because I have "seen the light" of KDE doesn't mean I want to force my preference onto others, so I designed it so that the base "gswitch" package doesn't depend on the GUI. But of course, the GUI does depend on it's base 🙂

As it happens, KDE was one of the first graphical DE's I used, but that goes back more than 20 years and I've never really sat down with KDE Plasma. I used XFCE for a while, but prefer Gnome these days (which I find hilarious, as I despised Gnome in its original iteration)... I have faith that one day you, too, will come to the dark side 😉

Posted by: Tara FitzGerald

There's 3 scripts that you need to create/install on your system, and a service you need to create/enable.

I think your scripts look great, a lot similar to what @nu_ninja has done. We've talked a bit about giving this boot feature to "gswitch" and I'm not totally against it. I'd be happy to see a pull request some day from either of you. It would be great if we could join forces 🙂

By the way, what is your distro of choice?

Thank you 🙂 I'm not averse to joining forces, and either my script or nu_ninja's boot config could very easily be changed to invoke gswitch as needed. Mostly it's a question of time - my schedule's quite busy in that respect.

My distro of choice is Arch... though I cut my teeth on Slackware, and have used many other distributions over the years, including Debian-based. 🙂

System: Tuxedo InfinityBook Pro 13", i5-8250u, 16GB RAM, 1TB NVMe
eGPU: Razer Core X, 8GB XFX RX580 GTS Black Edition OC+
OS: Arch Linux


theitsage liked
ReplyQuote
Sebulon
(@sebulon)
Eminent Member
Joined: 5 months ago
Posts: 36
February 25, 2019 1:34 pm  
Posted by: Tara FitzGerald

As it happens, KDE was one of the first graphical DE's I used, but that goes back more than 20 years and I've never really sat down with KDE Plasma. I used XFCE for a while, but prefer Gnome these days (which I find hilarious, as I despised Gnome in its original iteration)... I have faith that one day you, too, will come to the dark side 😉

That's funny, my story is quite the opposite! I started out using many window managers and DE's, mostly used GNOME and then MATÉ (new GNOME sucks) but always liked KDE just because the code behind it, Qt, is so much more elegant than GTK, but it has always looked so...visually unappealing, to put it mildly 🙂 Now with Plasma 5, it looks great and feels great at the same time!

I actually started out with Slackware, it was great back then to have to learn everything by yourself and then have that knowledge as a base. Since then, I've tried every big distro there is and, for now, settled with KDE Neon. Thinking of switching to Kubuntu, because it's a little too "new", wouldn't put it on any important production system that's supposed to be boring and just work, but it's been OK so far. Some minor inconveniences, but nothing big. For my servers however, my love is for FreeBSD. It reminds me of Slackware or Gentoo or Arch but scales as much as you want. You get to build your own packages, tweak every knob, but also distribute that to hundreds of VM's with ease. I could write a whole essay, but I'll hold that off, for now 🙂

Posted by: Tara FitzGerald

Mostly it's a question of time - my schedule's quite busy in that respect.

No kidding, you have a life too? 😉 Yeah, I totally get it, that's why I'm feeling pretty satisfied with it so far. I'm thinking letting it percolate for a while until I get an itch again.

Posted by: Tara FitzGerald

My distro of choice is Arch... though I cut my teeth on Slackware, and have used many other distributions over the years, including Debian-based. 🙂

I must be blind, it says so right there in your signature... Well, if you're feeling adventurous, we could get this into AUR?

This post was modified 2 months ago

Pending: Add my system information and expected eGPU configuration to my signature to give context to my posts


theitsage liked
ReplyQuote
(@tara_fitzgerald)
Active Member
Joined: 3 months ago
Posts: 10
February 25, 2019 7:31 pm  
Posted by: Sebulon

Well, if you're feeling adventurous, we could get this into AUR?

That's not impossible... it's fairly low maintenance, especially if there's no software compilation involved. I have done packages in the past (for a while, I was maintaining the SLiM package on a now-defunct 3rd party package repo for Slackware). Just a few things I would want to make happen before I'd be willing to make a package out of it:
 - Need a way to automate the xorg.conf build. Right now both yours and mine rely on the user to manually build the conf file, but if it's going in an AUR package, it'd have to be automated.
 - Need a better way to detect the eGPU on boot. My script is relying on counting the number of GPU's that're plugged in. It'd have to be tweaked to check the actual bus location to see if it's plugged in/active.
 - Need to implement a user-definable setting for whether to activate on boot. In an ideal world, the user could open a GUI and click "yes" or "no" to whether to switch X configs on boot. That's probably best handled with a conf file, and let the systemd service run on every boot rather than toggling the service.

anything to add? I can probably find time around Easter to make it happen, though not likely before, lol. 😉

System: Tuxedo InfinityBook Pro 13", i5-8250u, 16GB RAM, 1TB NVMe
eGPU: Razer Core X, 8GB XFX RX580 GTS Black Edition OC+
OS: Arch Linux


theitsage liked
ReplyQuote
Sebulon
(@sebulon)
Eminent Member
Joined: 5 months ago
Posts: 36
February 26, 2019 7:32 am  
Posted by: Tara FitzGerald
Posted by: Sebulon

Well, if you're feeling adventurous, we could get this into AUR?

That's not impossible... it's fairly low maintenance, especially if there's no software compilation involved. I have done packages in the past (for a while, I was maintaining the SLiM package on a now-defunct 3rd party package repo for Slackware). Just a few things I would want to make happen before I'd be willing to make a package out of it:
 - Need a way to automate the xorg.conf build. Right now both yours and mine rely on the user to manually build the conf file, but if it's going in an AUR package, it'd have to be automated.
 - Need a better way to detect the eGPU on boot. My script is relying on counting the number of GPU's that're plugged in. It'd have to be tweaked to check the actual bus location to see if it's plugged in/active.
 - Need to implement a user-definable setting for whether to activate on boot. In an ideal world, the user could open a GUI and click "yes" or "no" to whether to switch X configs on boot. That's probably best handled with a conf file, and let the systemd service run on every boot rather than toggling the service.

anything to add? I can probably find time around Easter to make it happen, though not likely before, lol. 😉

Sounds great, I agree on all points! One question I have though, is why you'd want a service that doesn't do it's job? I mean, you say you want a service but not do anything. If so, what's the point? 🙂 I think the service should be disabled by default and people who wants it should know how to "systemctl enable/start ${SERVICE}"?

I was thinking the boot-routine could be activated by having like, "gswitch boot", that would be the command put in the service file. So that the manual "egpu" and "internal" arguments stays how they are and create a new function for the boot stuff. How about that?

I would very much like to see the GUI be packaged as well. It just needs Qt5 basically and really only two commands to compile it, it's nothing complicated at all. I've described the process over on GitHub, check it out! I mean, the package names surely differ but nothing too different.

Nothing to hurry about and if you don't get the time by easter, that's fine to, but it would be cool if you did 🙂

Pending: Add my system information and expected eGPU configuration to my signature to give context to my posts


theitsage liked
ReplyQuote
(@tara_fitzgerald)
Active Member
Joined: 3 months ago
Posts: 10
February 26, 2019 11:39 pm  
Posted by: Sebulon

I was thinking the boot-routine could be activated by having like, "gswitch boot", that would be the command put in the service file. So that the manual "egpu" and "internal" arguments stays how they are and create a new function for the boot stuff. How about that?

That much is easy... you can just take the service file in my first post, and instead of the instructions to either copy or delete the xorg .conf file, have it instead invoke gswitch egpu/internal.

I would very much like to see the GUI be packaged as well. It just needs Qt5 basically and really only two commands to compile it, it's nothing complicated at all. I've described the process over on GitHub, check it out! I mean, the package names surely differ but nothing too different.

Personal preference 😉 I'm not a big fan of Qt - as I say, I don't even have it installed on my system, and forcing it as a requirement would be a hard pass from me. If I were doing it myself, I'd probably use zenity with bash scripts to accomplish what I want to do. Maybe split it into 3 packages - one for the core functionality, which is called as a dep from either the Qt or GTK front end (zenity is a utility to create GTK GUIs with bash scripts).

GTK is a much safer bet for actually existing on somebody's computer than Qt - KDE is the only desktop environment where you're reasonably assured of having Qt installed. Everything else that's even remotely mainstream uses a GTK base - Gnome (obviously, that's what the G in GTK is), but also XFCE, Cinnamon, LXDE, Unity, etc... according to the KDE man pages, KDE itself also has GTK integration/as a dep, specifically because nobody else is using Qt.

System: Tuxedo InfinityBook Pro 13", i5-8250u, 16GB RAM, 1TB NVMe
eGPU: Razer Core X, 8GB XFX RX580 GTS Black Edition OC+
OS: Arch Linux


ReplyQuote
Sebulon
(@sebulon)
Eminent Member
Joined: 5 months ago
Posts: 36
February 27, 2019 7:07 pm  
Posted by: Tara FitzGerald

Personal preference 😉 I'm not a big fan of Qt - as I say, I don't even have it installed on my system, and forcing it as a requirement would be a hard pass from me.

Yeah, I totally get that, but just because it's not your fancy doesn't mean that no one else wants it either. Is there a way in Arch to set up a container/chroot/whatever to build on so you don't "poison" your system and you can just nuke it from orbit when you're done? 🙂 Something similar to this*

Posted by: Tara FitzGerald

GTK is a much safer bet for actually existing on somebody's computer than Qt - KDE is the only desktop environment where you're reasonably assured of having Qt installed. Everything else that's even remotely mainstream uses a GTK base - Gnome (obviously, that's what the G in GTK is), but also XFCE, Cinnamon, LXDE, Unity, etc... according to the KDE man pages, KDE itself also has GTK integration/as a dep, specifically because nobody else is using Qt.

I won't argue with that, GTK is by far dominant in terms of use. I will say however that integration/dependency you speak of is because they care about that GTK apps look and feel quite the same in GNOME as in KDE. One could wish for the same openness in GNOME for Qt... Diversity isn't a weakness, it's one of open source's biggest strengths, in my opinion.

Pending: Add my system information and expected eGPU configuration to my signature to give context to my posts


ReplyQuote
(@tara_fitzgerald)
Active Member
Joined: 3 months ago
Posts: 10
February 27, 2019 9:18 pm  

Not really a question of strength/weakness... it's a case of which language has broader reach and is more likely to be present without forcing additional installs? We can wax poetic about how it might be nice, but at the end of the day there's much less assurance that some random person out there even has Qt installed. Relying on it as a dependency for what should be a pretty simple set & forget configuration is counter-productive.

Having multiple options isn't out of the question though - if folks want Qt, they can use that front end. If they want GTK, they can use that. If somebody wants to roll an ncurses front end, more power to them. If somebody wants to make an emacs plugin that manipulates butterflies in China to evoke just the right cosmic rays to make it happen, I'm fine with them doing that, too. I just have a problem with forcing somebody to install 60mb of dependencies to support 3kb of actual scripts. Zenity (for GTK) is only 6mb, and is called as a dependency for multiple desktop environments (Gnome, Deepin, Budgie, Cinnamon, MATE... it's also a dependency for Steam.) Considering what most of us actually use an eGPU for, there's a pretty good guarantee that it's already installed, along with GTK.

I'm not denying that Qt can be a useful language for defining interfaces, I'm just pointing out that a utility like this isn't the place you want to stake out as the hill to die on, ideologically. If this is going to happen, then having the broadest reach possible should be a key design goal from the beginning. I've been using Linux for decades (plural). The only tools that really catch on and stick around for a long time are the ones that do what you want, get out of the way, and minimize the additional stuff the user needs to install/futz with just to keep it running.

System: Tuxedo InfinityBook Pro 13", i5-8250u, 16GB RAM, 1TB NVMe
eGPU: Razer Core X, 8GB XFX RX580 GTS Black Edition OC+
OS: Arch Linux


ReplyQuote
Sebulon
(@sebulon)
Eminent Member
Joined: 5 months ago
Posts: 36
February 28, 2019 6:03 am  

Whoa there crusader, calm down. I was just pointing out that there are, believe or not, people on Arch, rocking KDE 🙂

I'm totally for a GTK frontend and if you can do that with Zenity, awesome! Though it might be easier to start with what we have and work from there, don't you agree?

Pending: Add my system information and expected eGPU configuration to my signature to give context to my posts


ReplyQuote