Skip to content

Instantly share code, notes, and snippets.

@shehzan10
Last active February 1, 2024 13:39
Show Gist options
  • Save shehzan10/8d36c908af216573a1f0 to your computer and use it in GitHub Desktop.
Save shehzan10/8d36c908af216573a1f0 to your computer and use it in GitHub Desktop.
Remote OpenGL Without Display

Remote OpenGL Setup without X

A full OpenGL profile requires X to be running. For X to run, it requires a display to be connected to the machine. Given that most server machines do not have this, it becomes difficult to run OpenGL.

This document details how to get OpenGL and X up and running without having a display connected to the sevrer.

Requirements

You will need access to the remote system over SSH. To run the tool, you will need libGL.so and libX11.so. These are installed when X and the NVIDIA Drivers are installed. So there is nothing special required to install these.

Another tool I would recommend strongly is glewinfo. Most linux distributions ship this with the glew-utils package. An alternate to glewinfo is glxinfo which is present on all systems with X. You can substitute glewinfo with glxinfo in all the commands below if needed. To install glew-utils on ubuntu, run sudo apt-get install glew-utils

Configuring X

To get X to running on NVIDIA cards, we need to make changes to the xorg.conf file. Before making the change, make sure you create a back up of the current version on your system (name it xorg.conf.stable).

Now run this command:

# nvidia-xconfig -a --use-display-device=None --virtual=1280x1024

Restart the system.

Note: To abort trying this, just copy xorg.conf.stable back to xorg.conf and restart.

Start X

On restart, run the command

# /usr/bin/X :0 &

Ideally, this command should give an output similar to:

X.Org X Server 1.13.0
Release Date: 2012-09-05
X Protocol Version 11, Revision 0

<Some more output here>

Loading extension GLX
Loading extension NV-GLX
Loading extension NV-CONTROL

This means X has started successfully on the virtual display. If it fails, restart the system and try again. You can also look at /var/log/Xorg.0.log for the log of the failure.

Known issue with Starting X

If the output is not similar to the one shown above, run the verification section below. If the output shows an error with NV-GLX, run the following commands:

sudo mv /usr/lib/xorg/modules/extensions/libglx.so /usr/lib/xorg/modules/extensions/libglx.so.orig
sudo ln -s /usr/lib/xorg/modules/extensions/libglx.so.XXX.YY /usr/lib/xorg/modules/extensions/libglx.so

Where XXX.YY is the NVIDIA driver version.

Now try starting X again.

Verify X Has Started Successfully

Once X has started successfully, run echo $DISPLAY. It is very likely that the output of this will be empty. If you have glewinfo installed, run the following command env DISPLAY=:0 glewinfo | less.

The goal of this command is to run glewinfo having temporarily set DISPLAY to :0 (virtual display on remote system). If this command runs successfully, you should be able to see the graphics card on the remote system along with the full OpenGL profile. And now you are ready to deploy applications using X.

If you want to set DISPLAY for the entire session, run export DISPLAY=:0. To set DISPLAY permanently, add the same line to your bashrc file.

GLEW Info with Success

$ env DISPLAY=:0 glewinfo
---------------------------
    GLEW Extension Info
---------------------------

GLEW version 1.6.0  
Reporting capabilities of display :0, visual 0x2b
Running on a GeForce GTX 690/PCIe/SSE2 from NVIDIA Corporation
OpenGL version 4.4.0 NVIDIA 340.24 is supported
<more text>

GLEW Info with Failure because of NV-GLX

$ env DISPLAY=:0 glewinfo
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  137 (NV-GLX)
  Minor opcode of failed request:  4 ()
  Resource id in failed request:  0x200004
  Serial number of failed request:  39
  Current serial number in output stream:  39
@harveyslash
Copy link

Can I do this on a server that has a display? When I run /usr/bin/X :0 & the physical display goes blank.

@MutableLoss
Copy link

Just an update to this for 440 on Titan vGPUs, when creating the Xorg config, I had to ditch the virtual setting (caused "no screen" errors), and added the "enable all GPUs", and set the BusID of the GPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment