Solved How to startx with a specific config as a user

I have laptop with 2 GPUs.
The first one is Intel for embedded screen, and the second one is Nvidia for external displays.
I have xorg configs files for both scenarios.
When I load proper drivers I am able to run X on either the embedded display or an external one.
However, right now I manually empty the /usr/local/etc/X1/xorg.conf.d/ directory, copy the proper config file there as root, and then startx as user.
This is time consuming and I would like automate the task.
I would like to have two shell scripts startx-embedded and startx-external that would start X session on embedded or external displays respectively.
The Xorg has the -config parameter.
However, this parameter can be provided only if Xorg is started by the root.

I wonder what is the proper solution for my problem.
I would like to startx with a specific config as a user.
What is more, I also would like to load proper driver, as a user, in my startx-XXX scripts, so that no unnecessary modules are loaded.
 
docs say that will work for non root if the config is in the "config search path"

" -config file
Read the server configuration from file. This option will work
for any file when the server is run as root (i.e, with real-uid
0), or for files relative to a directory in the config search
path for all other users."
 
I will try later. However, there is still a problem of loading a specific GPU driver as a user.
 
I will try later. However, there is still a problem of loading a specific GPU driver as a user.
I'm not sure about that. I've always used startx as nonroot, don't think I've ever seen an issue where the driver would not load.
Unless you are not talking about "X" drivers?
 
I presume this is about kldload(8) and i915kms.ko or nvidia-modeset.ko. As only root can load kernel modules.

But you should be able to have both kernel modules loaded, so there would be no need to "switch" between them. It's your xorg.conf that actually defines which of those drivers are used (Device section; Driver {...}). That part of the X configuration doesn't actually load a driver (not a kernel module in any case), it just tells it which one it should use.
 
I presume this is about kldload(8) and i915kms.ko or nvidia-modeset.ko. As only root can load kernel modules.

But you should be able to have both kernel modules loaded, so there would be no need to "switch" between them. It's your xorg.conf that actually defines which of those drivers are used (Device section; Driver {...}). That part of the X configuration doesn't actually load a driver (not a kernel module in any case), it just tells it which one it should use.
That's what I'm hoping, but "...if it's not explicitly stated..." and assuming things often goes badly.
 
I presume this is about kldload(8) and i915kms.ko or nvidia-modeset.ko. As only root can load kernel modules.

But you should be able to have both kernel modules loaded, so there would be no need to "switch" between them. It's your xorg.conf that actually defines which of those drivers are used (Device section; Driver {...}). That part of the X configuration doesn't actually load a driver (not a kernel module in any case), it just tells it which one it should use.
I just wouldn't like to waste memory for nvidia-modeset and nvidia. Together they are relatively "heavy" modules.
 
I just wouldn't like to waste memory for nvidia-modeset and nvidia. Together they are relatively "heavy" modules.
This statement: is the reason for root so you can do kldload nvidia-modeset|i915kms? You still haven't explicitly told us what modules you need to be root for. You say in your original post that you need to be root to swap config files, but that is not loading modules.


So this is a laptop, how much RAM does it have? Are you using ZFS (asking because this is another potentially big consumer of memory)?

But if loading nvidia stuff and i915 from rc.conf lets you get around the "root" problem, why not at least think about it?
Or you write an suid script that does the kldload, calls startx with the appropriate config, then calls kldunload after startx exits.
I think that would work, but seems like overcomplication
 
I have two config files in /usr/local/etc/X11/xorg.conf.d/, intel.conf and nvidia.conf.
Their content is as follows:
Code:
Section "Device"
    Identifier "Card0"
    Driver     "Intel"
EndSection
Code:
Section "Device"
    Identifier "Card1"
    Driver     "nvidia"
    BusID      "PCI:1:0:0"
EndSection
If I remove one of them and run startx, the behavior is as expected.
WM starts on embedded display or an external one.

However, if I keep both of them in the xorg directory, and try to start X using startx -- -config intel.conf, the process fails with the following log:
Code:
[   460.804]
X.Org X Server 1.21.1.18
X Protocol Version 11, Revision 0
[   460.805] Current Operating System: FreeBSD riis 14.3-RELEASE FreeBSD 14.3-RELEASE releng/14.3-n271432-8c9ce319fef7 GENERIC amd64
[   460.805] 
[   460.805] Current version of pixman: 0.46.2
[   460.805]     Before reporting problems, check http://wiki.x.org
    to make sure that you have the latest version.
[   460.805] Markers: (--) probed, (**) from config file, (==) default setting,
    (++) from command line, (!!) notice, (II) informational,
    (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[   460.805] (==) Log file: "/var/log/Xorg.0.log", Time: Fri Aug 29 09:06:12 2025
[   460.805] (++) Using config file: "/usr/local/etc/X11/xorg.conf.d/intel.conf"
[   460.805] (==) Using config directory: "/usr/local/etc/X11/xorg.conf.d"
[   460.805] (==) Using system config directory "/usr/local/share/X11/xorg.conf.d"
[   460.805] (==) No Layout section.  Using the first Screen section.
[   460.805] (==) No screen section available. Using defaults.
[   460.805] (**) |-->Screen "Default Screen Section" (0)
[   460.805] (**) |   |-->Monitor "<default monitor>"
[   460.805] (==) No device specified for screen "Default Screen Section".
    Using the first device section listed.
[   460.805] (**) |   |-->Device "Card0"
[   460.805] (**) |   |-->GPUDevice "Card0"
[   460.805] (**) |   |-->GPUDevice "Card0"
[   460.805] (==) No monitor specified for screen "Default Screen Section".
    Using a default monitor configuration.
[   460.805] (**) Allowing byte-swapped clients
[   460.805] (==) Automatically adding devices
[   460.805] (==) Automatically enabling devices
[   460.805] (==) Automatically adding GPU devices
[   460.805] (==) Automatically binding GPU devices
[   460.805] (==) Max clients allowed: 256, resource mask: 0x1fffff
[   460.805] (==) FontPath set to:
    /usr/local/share/fonts/misc/,
    /usr/local/share/fonts/TTF/,
    /usr/local/share/fonts/OTF/,
    /usr/local/share/fonts/Type1/,
    /usr/local/share/fonts/100dpi/,
    /usr/local/share/fonts/75dpi/,
    catalogue:/usr/local/etc/X11/fontpath.d
[   460.805] (==) ModulePath set to "/usr/local/lib/xorg/modules"
[   460.805] (II) The server relies on udev to provide the list of input devices.
    If no devices become available, reconfigure udev or disable AutoAddDevices.
[   460.805] (II) Module ABI versions:
[   460.805]     X.Org ANSI C Emulation: 0.4
[   460.805]     X.Org Video Driver: 25.2
[   460.805]     X.Org XInput driver : 24.4
[   460.805]     X.Org Server Extension : 10.0
[   460.809] (II) xfree86: Adding drm device (/dev/dri/card0)
[   460.809] (II) Platform probe for /dev/dri/card0
[   460.816] (!!) More than one possible primary device found
[   460.816] (--) PCI: (0@0:2:0) 8086:3e9b:1d05:1043 rev 0, Mem @ 0xa4000000/16777216, 0x80000000/268435456, I/O @ 0x00007000/64, BIOS @ 0x????????/65536
[   460.816] (--) PCI: (1@0:0:0) 10de:1c20:1d05:1043 rev 161, Mem @ 0xa5000000/16777216, 0x90000000/268435456, 0xa0000000/33554432, I/O @ 0x00006000/128, BIOS @ 0x????????/65536
[   460.816] (II) LoadModule: "glx"
[   460.816] (II) Loading /usr/local/lib/xorg/modules/extensions/libglx.so
[   460.818] (II) Module glx: vendor="X.Org Foundation"
[   460.818]     compiled for 1.21.1.18, module version = 1.0.0
[   460.818]     ABI class: X.Org Server Extension, version 10.0
[   460.818] (II) LoadModule: "intel"
[   460.818] (II) Loading /usr/local/lib/xorg/modules/drivers/intel_drv.so
[   460.818] (II) Module intel: vendor="X.Org Foundation"
[   460.818]     compiled for 1.21.1.18, module version = 2.99.917
[   460.818]     Module class: X.Org Video Driver
[   460.818]     ABI class: X.Org Video Driver, version 25.2
[   460.818] (II) LoadModule: "nvidia"
[   460.819] (II) Loading /usr/local/lib/xorg/modules/drivers/nvidia_drv.so
[   460.819] (II) Module nvidia: vendor="NVIDIA Corporation"
[   460.819]     compiled for 1.6.99.901, module version = 1.0.0
[   460.819]     Module class: X.Org Video Driver
[   460.819] (II) intel: Driver for Intel(R) Integrated Graphics Chipsets:
    i810, i810-dc100, i810e, i815, i830M, 845G, 854, 852GM/855GM, 865G,
    915G, E7221 (i915), 915GM, 945G, 945GM, 945GME, Pineview GM,
    Pineview G, 965G, G35, 965Q, 946GZ, 965GM, 965GME/GLE, G33, Q35, Q33,
    GM45, 4 Series, G45/G43, Q45/Q43, G41, B43
[   460.820] (II) intel: Driver for Intel(R) HD Graphics
[   460.820] (II) intel: Driver for Intel(R) Iris(TM) Graphics
[   460.820] (II) intel: Driver for Intel(R) Iris(TM) Pro Graphics
[   460.820] (II) NVIDIA dlloader X Driver  570.169  Thu Jun 12 19:58:22 UTC 2025
[   460.820] (II) NVIDIA Unified Driver for all Supported NVIDIA GPUs
[   460.820] (--) Using syscons driver with X support (version 2.0)
[   460.820] (--) using VT number 9

[   460.834] (II) Loading sub module "fb"
[   460.834] (II) LoadModule: "fb"
[   460.834] (II) Module "fb" already built-in
[   460.834] (II) Loading sub module "wfb"
[   460.834] (II) LoadModule: "wfb"
[   460.834] (II) Loading /usr/local/lib/xorg/modules/libwfb.so
[   460.834] (II) Module wfb: vendor="X.Org Foundation"
[   460.834]     compiled for 1.21.1.18, module version = 1.0.0
[   460.834]     ABI class: X.Org ANSI C Emulation, version 0.4
[   460.835] (WW) VGA arbiter: cannot open kernel arbiter, no multi-card support
[   460.835] (EE) Screen 0 deleted because of no matching config section.
[   460.835] (II) UnloadModule: "nvidia"
[   460.835] (II) UnloadSubModule: "wfb"
[   460.835] (EE) Device(s) detected, but none match those in the config file.
[   460.835] (EE)
Fatal server error:
[   460.835] (EE) no screens found(EE)
[   460.835] (EE)
Please consult the The X.Org Foundation support
     at http://wiki.x.org
 for help.
[   460.835] (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
[   460.835] (EE)
[   460.837] (EE) Server terminated with error (1). Closing log file.

According to the man xorg.conf, the /usr/local/etc/X11/xorg.conf.d/ path is in the search path when user starts X.
I have no idea why it does not work as expected.
 
try moving nvidia.conf and intel.conf to /usr/local/etc/X11/
Now it works.
However, I don't know why Xorg could not find files in the xorg.conf.d subdirectory.
The man xorg.conf states:
Code:
       Additional configuration    files are searched for in the following    direc-
       tories when the server is started as a normal user:

       /etc/X11/<cmdline>
       /usr/local/etc/X11/<cmdline>
       /etc/X11/xorg.conf.d
       /usr/local/etc/X11/xorg.conf.d
 
Back
Top