Are you stuck with the dreaded
xhost: unable to open display ":0"
when trying to run cgminer / bfgminer on a headless machine?
After banging my head against the wall for a few hours I figured this out and decided to try and pass the knowledge onto anyone else that may be having a difficult time.
My goal was to have a completely headless setup which means:
Start the pc with no monitor, keyboard, or mouse plugged in whatsoever and be able to mine.
I followed both Xubuntu guides to get bfgminer and the ati drivers installed & enabled (more from the 12.10 one because that had the bfgminer instructions):
"Installed - Xubuntu 13.04, Raring Ringtail"
1.
https://docs.google.com/document/d/1Gw7YPYgMgNNU42skibULbJJUx_suP_CpjSEdSi8_z9U/preview?sle=true2.
https://docs.google.com/document/d/1a1T3j5Vr5mAmet47VnVfZ2ba4XVQkwLrYarl6PpUs_E/editThe instructions assume you aren't headless. The command that makes it all possible is 'xhost +'. The problem is 'xhost +' from a headless machine gives you something similar to the following (even as root):
miner@rig:~$ export DISPLAY=:0
miner@rig:~$ xhost +
xhost: unable to open display ":0"
miner@rig:~$ sudo aticonfig --adapter=all --odgt
ERROR - X needs to be running to perform AMD Overdrive(TM) commands
miner@rig:~$
miner@rig:~$ cgminer -n
[2013-04-18 14:16:18] CL Platform 0 vendor: Advanced Micro Devices, Inc.
[2013-04-18 14:16:18] CL Platform 0 name: AMD Accelerated Parallel Processing
[2013-04-18 14:16:18] CL Platform 0 version: OpenCL 1.2 AMD-APP (1016.4)
[2013-04-18 14:16:18] Error -1: Getting Device IDs (num)
[2013-04-18 14:16:18] clDevicesNum returned error, no GPUs usable
[2013-04-18 14:16:18] 0 GPU devices max detected
But if you run
netstat -l
you can clearly see that X is running.
What you will need to do is:
1. Install x11vnc
sudo apt-get install x11vnc
2. Create a password to connect
sudo x11vnc -storepasswd /etc/x11vnc.pass
3. Start it on ":0" referencing your magic cookie
sudo /usr/bin/x11vnc -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /tmp/x11vnc.log -display :0
4. Connect to your headless machine via VNC on port 5900 (example using realvnc: 192.168.0.100:5900)
5. Open a terminal via the VNC session and type:
xhost +
6. Either connect via ssh and try to run your miner or try to start it via the VNC session.
Troubleshooting:
If the x11vnc password is giving your problems you can skip step 2 and run this in step 3 (to connect insecurely with no password)
sudo /usr/bin/x11vnc -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -forever -bg -rfbport 5900 -o /tmp/x11vnc.log -display :0
If you are having issues connecting via VNC, you can try the following (although I only used it with tightvncserver):
Edit using vi or pico, etc:
/home/youruser/.vnc/xstartup
Comment out:
#/etc/X11/Xsession
Add the following to the end of the file:
unset SESSION_MANAGER
exec startxfce4
Close & save the file, then issue the following command:
sudo coldreboot
Please donate LTC if this helped :-) @ LTgWjHtzgkLiXSDDBFdh8XwWJw3x6Hv5qu