You are not logged in.

#1 2014-08-15 19:06:17

MrOats
Member
Registered: 2014-08-02
Posts: 12

[X11] Auto Detect Driver Config

So I have this External HDD I use to boot my Arch Linux install from, so that I can carry Arch around with me everywhere. So far I've gotten everything configured correctly to work 100% on my laptop. My laptop is using a intel integrated Graphics card, and so I had to create a "20-intel.conf" file inside xorg.conf.d so that changing brightness would work. After all that, I went to test out the external HDD on a different computer that's using a Nvidia GTS Geforce 450, I had issues booting, but I just fixed the FStab to load up partitions by UUID. Now I'm having trouble displaying my X Environment.

Doing some troubleshooting, I found if I removed the 20-intel.conf, the Nvidia computer would display the X environment just fine, so I thought, hey I could put the 20-intel.conf and the 10-nvidia.conf inside the xorg.conf.d folder, X would detect which one to use. Sadly neither the Intel Laptop and the Nvidia computer could display the X enironment after having both those configurations in that folder. Is there any way to make this happen? Or would I just have to remove the graphic devices config files whenever I want to use a different computer?

Last edited by MrOats (2014-08-15 19:07:36)

Offline

#2 2014-08-15 19:32:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [X11] Auto Detect Driver Config

I just did a quick search, and I can't find any indication that xorg.conf files can have any conditional structures, which is what you would need.

You could have a script that runs during startup (service file perhaps) that will copy or link the appropriate conf file into etc/X11/xorg.conf.d at boot.

For example:

lspci | grep -q "VGA.*Intel" && \
  ln -s /etc/X11/xorg.conf.d/display.intel /etc/X11/xorg.conf.d/20-intel.conf || \
  ln -s /etc/X11/xorg.conf.d/display.nvidia /etc/X11/xorg.conf.d/20-nvidia.conf

Note that I just made this up - so I've never tested it.  But in principle it should work well.

Last edited by Trilby (2014-08-15 19:44:01)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2014-08-15 19:35:19

MrOats
Member
Registered: 2014-08-02
Posts: 12

Re: [X11] Auto Detect Driver Config

Ah I see what you mean, too bad I really have basic skills of Bash. I can see the layout of it though. I guess I will just do it the old fashioned way as I mentioned. Unless somebody else knows something we don't?

Offline

#4 2014-08-15 19:44:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [X11] Auto Detect Driver Config

I just editted to add an example.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2014-08-15 19:52:51

MrOats
Member
Registered: 2014-08-02
Posts: 12

Re: [X11] Auto Detect Driver Config

Woah, I had this whole

If <args>

elseif <args>

else

thing going on in my head.

So what it looks like from your script is that it searches for a intel card, if a intel device is found, then it will link the differently intel.conf into the correct name, and run X11 from there, else it will just run the Nvidia card. Question is, what if I need to link an ATI card?

Offline

#6 2014-08-15 19:58:58

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [X11] Auto Detect Driver Config

Then you'd need a more complex conditional.  Here's a better starting point for that:

if lspci | grep -q "VGA.*Intel"; then
   ln -s /etc/X11/xorg.conf.d/display.intel /etc/X11/xorg.conf.d/20-intel.conf
else if lspci | grep -q "VGA.*NVIDIA"; then
   ln -s /etc/X11/xorg.conf.d/display.nvidia /etc/X11/xorg.conf.d/20-nvidia.conf
else if lspci | grep -q "VGA.*ATI"; then
   ln -s /etc/X11/xorg.conf.d/display.ati /etc/X11/xorg.conf.d/20-ati.conf
fi

I'm not sure if ATI would need a config - but you could do this for as many different config entries as you might need.  You'd want to check the output of lscpi and see that those tests actually match - I only have an intel card handy to test it on so I was guessing a bit for the others.

EDIT:
A slightly more complex starting point that is easier to modify might be the following:

gpu=$(lspci | awk '/VGA/ { print $5; }')

case $gpu in
   Intel) ln -s ... ;;
   Nvidia) ln -s ... ;;
   Ati) ln -s ... ;;
esac

As above, the "Nvidia" and "Ati" strings would have to be checked - and of course the ellipses would need the same lines as above.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2014-08-15 20:44:21

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [X11] Auto Detect Driver Config

You'd also need to remove the existing symlink if it's for the wrong card. I would do something like:

1) determine card type
2) determine existing .conf link
3a) Correct .conf link: exit
3b) Incorrect .conf link: unlink it and link the correct one


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#8 2014-08-15 20:50:14

MrOats
Member
Registered: 2014-08-02
Posts: 12

Re: [X11] Auto Detect Driver Config

Oh so I was on the correct logic of using that script skeleton. I've tested the lspci output and it works. I'm going to put that code inside a .sh file and dump it into the "/etc/rc.d"directory. (I read somewhere thats where start up scripts like this would go?).

Also, good point Alphaniner, I'll see if I can modify it later to do so.

Thank you all! I'll let you know soon on how it worked out.

Last edited by MrOats (2014-08-15 20:50:48)

Offline

#9 2014-08-15 21:08:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [X11] Auto Detect Driver Config

alphaniner wrote:

You'd also need to remove the existing symlink if it's for the wrong card.

ln -sf <file> <target>

Though this wouldn't work for any card that *doesn't* need a config file.  So just make an empty config file for any cards that don't require configuration.  Then ln -sf this empty file to the target.

Also, /etc/rc.d/ is only for sysvinit and related init systems, it does not apply in archlinux.  You could make a systemd service, but perhaps the simplest would be to put this script wherever you start X (and *before* X starts).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2014-08-15 21:14:39

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [X11] Auto Detect Driver Config

Trilby wrote:

ln -sf <file> <target>

But you suggested a different link name for each gpu type: 20-intel.conf, 20-nvidia.conf, etc. Presumably you wouldn't want more than one of those at a time?


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#11 2014-08-15 21:20:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [X11] Auto Detect Driver Config

Oops, you're quite right.  In one version in my brain at least, they all used the same target file - which would seem the most sensible given these concerns.

So an excerpt:

  Intel) ln -sf /etc/X11/xorg.conf.d/display.intel /etc/X11/xorg.conf.d/20-display.conf ;;
  Nvidia) ln -sf /etc/X11/xorg.conf.d/display.nvidia /etc/X11/xorg.conf.d/20-display.conf ;;
  ATI) ln -sf /etc/X11/xorg.conf.d/display.ati /etc/X11/xorg.conf.d/20-display.conf ;;

Or now even simpler full script:

gpu=$(lspci | awk '/VGA/ { print $5; }')

ln -sf /etc/X11/xorg.conf.d/display.$gpu /etc/X11/xorg.conf.d/20-display.conf

And just create a display.Intel, display.Nvidia, and display.ATI file, but also create an empty "display." file with the dot at the end of the name for anytime no matching gpu is found.

Note that Xorg doesn't care what these files are called.  It reads any file in that directory ending in ".conf" and ignores anything else.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2014-08-15 21:55:29

MrOats
Member
Registered: 2014-08-02
Posts: 12

Re: [X11] Auto Detect Driver Config

Before I started getting into putting it as a start up script. I realized I should test the 10-nvidia.conf by itself on the Nvidia computer, I just did and it didn't work. Realized that the config file was calling for the nvidia driver when it should be calling for the nouveau driver for Nvidia GFXs... so I fixed that and that nvidia.conf is working now.

"Note that Xorg doesn't care what these files are called.  It reads any file in that directory ending in ".conf" and ignores anything else."
Does that mean I don't have to name it "20-intel.conf", it could be named "SirEisenHower.conf" and it would still work? That does make things easier!

Now all that makes sense, I just need to get into the path of creating a service file to open up that shell!

Offline

#13 2014-08-15 22:30:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [X11] Auto Detect Driver Config

MrOats wrote:

Does that mean I don't have to name it "20-intel.conf", it could be named "SirEisenHower.conf" and it would still work? That does make things easier!

Yup, that's why in my last example, they all just linked to 20-display.conf.  But SirEisenHower.conf should work perfectly fine too.  The numbers you'll commonly see at the start of the name only ensure they are parsed in numerical order so, for example, 99-mine.conf could be read after settings in 10-evdev.conf but the numbers are not required.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#14 2014-08-15 23:12:44

MrOats
Member
Registered: 2014-08-02
Posts: 12

Re: [X11] Auto Detect Driver Config

So I tested out the script manually, and it worked perfectly. So I went ahead and made the script executable via "chmod +x" and placed it inside "/usr/lib/systemd/system/scripts" and created the .service file, placed it "usr/lib/systemd/system", and enabled it and it came out clean in the terminal. Made sure the end result file didn't exist, and rebooted, the service ran perfectly! It created the config like it was supposed to.

Contents of the .service file

[Unit]
Description=Detect GPU

[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/DetectGFXatBoot.sh
RemainAfterExit=yes


[Install]
WantedBy=multi-user.target

Thanks Trilby and alphaniner!

Offline

#15 2014-08-15 23:13:43

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [X11] Auto Detect Driver Config

Cool, glad that's working.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB