Determine which graphics driver Xorg uses
You can check the Xorg startup log file, usually /var/log/Xorg.0.log
and look at which modules it is loading. By default Xorg can try to autodetect but you can manually force a driver by putting a Device
stanza in an Xorg conf file. Here is what the Xorg startup log will look like for an nvidia card and the nvidia proprietary driver.
[ 3702.470] (II) xfree86: Adding drm device (/dev/dri/card0)
[ 3702.472] (--) PCI:*(0:3:0:0) 10de:1184:3842:3774 rev 161, Mem @ 0xfa000000/16777216, 0xd8000000/134217728, 0xd6000000/33554432, I/O @ 0x0000cc00/128, BIOS @ 0x????????/524288
[ 3702.472] (II) LoadModule: "glx"
[ 3702.473] (II) Loading /usr/lib64/opengl/nvidia/extensions/libglx.so
[ 3702.476] (II) Module glx: vendor="NVIDIA Corporation"
[ 3702.476] compiled for 4.0.2, module version = 1.0.0
[ 3702.476] Module class: X.Org Server Extension
[ 3702.476] (II) NVIDIA GLX Module 355.11 Wed Aug 26 16:02:11 PDT 2015
[ 3702.476] (II) LoadModule: "nvidia"
[ 3702.476] (II) Loading /usr/lib64/xorg/modules/drivers/nvidia_drv.so
[ 3702.476] (II) Module nvidia: vendor="NVIDIA Corporation"
[ 3702.476] compiled for 4.0.2, module version = 1.0.0
[ 3702.476] Module class: X.Org Video Driver
[ 3702.476] (II) NVIDIA dlloader X Driver 355.11 Wed Aug 26 15:38:55 PDT 2015
[ 3702.476] (II) NVIDIA Unified Driver for all Supported NVIDIA GPUs
[ 3702.476] (++) using VT number 7
One solution that I have found is to check what drivers are actually loaded while X is running. On my system, the drivers are installed under
/usr/lib/xorg/modules/drivers/
/usr/lib/x86_64-linux-gnu/nvidia/xorg/
so I can check what is currently loaded with
sudo lsof +D /usr/lib/xorg/modules/drivers/ +D /usr/lib/x86_64-linux-gnu/nvidia/xorg/
Right now I get
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Xorg 4473 root mem REG 253,0 90360 536108 /usr/lib/xorg/modules/drivers/modesetting_drv.so
so I guess I'm using the modesetting
driver.
Here's an attempt to automatize the analysis of the log:
#!/bin/bash
if [ -z "$1" ]; then
logfile=/var/log/Xorg.0.log
else
logfile="$1"
fi
sed -n 's@.* Loading .*/\(.*\)_drv.so@\1@p' "$logfile" |
while read driver; do
if ! grep -q "Unloading $driver" "$logfile"; then
echo $driver
break
fi
done
Any ideas how to make it simpler are welcome. Ideally I'd like to have a direct solution — by a query to Xorg instead of parsing its logs.