objective: make nautilus .
command work in a headless server.
install nautilus
$ sudo apt install nautilus
I’ve tried installing a display manager, but instead I succeeded with directly starting the x server with xinit
. related link
install xinit
$ sudo apt install xinit
create new xorg.conf
if it is a headless server, then the default xorg confs(located at /usr/share/X11/xorg.conf.d
) is not going to work because it doesn't have a real physical screen.
To be specific, I’ve tried launching the X server with lightdm
.
$ sudo systemctl start lightdm
However, this does not work. We can see why it doesn’t work inside the xorg log file located in /var/log/Xorg.0.log
This log file loggs the procedure of launching Xorg. If the conf file is wrong, it will say that parsing conf file cause the error. If an error occured due to no screens, it will be said so inside this file. So it is important to keep checking this log file whenever X server does not seem to start properly.
Since the default confs do not work, we need to create a new one. reference link
$ sudo Xorg :0 -configure
a file named xorg.conf.new
will be created in your current location.
If you have multiple GPU, then the very first section which defines ServerLayout
will have multiple screens like below
Section "ServerLayout"
Identifier "X.org Configured"
Screen 0 "Screen0" 0 0
Screen 1 "Screen1" RightOf "Screen0"
Screen 2 "Screen2" RightOf "Screen1"
Screen 3 "Screen3" RightOf "Screen2"
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
EndSection
The default setting will create a screen for each GPU and will attach them along side-by-side. But since this configuration will be using precious GPU resources, we can reduce to using just one. Remove all screen definition blocks except screen0
. So this section will look like:
Section "ServerLayout"
Identifier "X.org Configured"
Screen 0 "Screen0" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
EndSection
Since we use only Screen0
, delete all sections for Screen1-3
. If you don't delete them it will cause an error when parsing.
Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
SubSection "Display"
Viewport 0 0
Depth 1
EndSubSection
Looking at the Screen0
section, we notice that it uses the device named Card0
. Checking out the Card0
section,
Section "Device"
Identifier "Card0"
Driver "nvidia"
BusID "PCI:5:0:0"
EndSection
we can see that this is directing to one of the nvidia GPU cards.
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.81 Driver Version: 384.81 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 TITAN Xp Off | 00000000:05:00.0 Off | N/A |
| 23% 26C P8 7W / 250W | 11645MiB / 12188MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 TITAN Xp Off | 00000000:06:00.0 Off | N/A |
| 23% 26C P8 8W / 250W | 11602MiB / 12189MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 2 TITAN Xp Off | 00000000:09:00.0 Off | N/A |
| 23% 24C P8 8W / 250W | 11604MiB / 12189MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 3 TITAN Xp Off | 00000000:0A:00.0 Off | N/A |
| 23% 26C P8 8W / 250W | 11602MiB / 12189MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
Cross-referencing with nvidia-smi
, we can see that Card0
is pointing to the first GPU in the list. (it has Bus-Id
value of 00000000:05:00.0
which matches the value in the BusId
value of Card0
section)
Also in order to ignore the fact that there is no physical screen attached to the server, we add the AllowEmptyInitialConfiguration
option inside the Card0
section.(reflink1 , reflink2)
It should look like:
Section "Device"
Identifier "Card0"
Driver "nvidia"
BusID "PCI:5:0:0"
Option "AllowEmptyInitialConfiguration"
EndSection
BTW, AllowEmptyInitialConfiguration
option may not work with old nvidia GPU cards, according to reflink2. But I haven't tested if this is true or not, so just keep this in notice.
Another option needs to be added to the Monitor0
section. (reflink)
Please add the IgnoreEDID
option. It should look like this:
Section "Monitor"
Identifier "Monitor0"
VendorName "Monitor Vendor"
ModelName "Monitor Model"
Option "IgnoreEDID"
EndSection
We have finished modifying the new configuration file. Copy or move this file to /etc/X11
$ sudo mv xorg.conf.new /etc/X11/xorg.conf
By renaming it to xorg.conf
under /etc/X11
directory, this file will be used as the default configuration file.
Now try starting the X server
$ sudo xinit
If successful, it will not show any errors and it will keep running. The terminal will not be returned to the user since the xinit
is still occupying it.
You can cross-check that X server is running well with ps
.
$ ps -e | grep x
214 ? 00:00:00 ixgbe
407 ? 00:00:00 ext4-rsv-conver
898 ? 00:00:00 ext4-rsv-conver
909 ? 00:00:00 ext4-rsv-conver
1121 ? 00:00:14 lxcfs
21439 ? 00:00:00 xfsalloc
21440 ? 00:00:00 xfs_mru_cache
27182 ? 00:00:00 xinit <---HERE IT IS!
27198 ? 00:00:00 xterm
Now we are sure that x server works, we need to run this in the background. Cancel the process that we launched above, and rerun it in the background.
$ sudo xinit &
make sure that X11 Forwarding is enabled
Even after configuring all of this, I faced an error when executing nautilus
$ nautilus .
Gtk-WARNING **: cannot open display:
In this case, there is a high possibility that your ssh connection did not have X11 Forwarding enabled. Kill you current ssh connection, ensure X11 Forwarding is enabled, and reconnect to the server.
For me, this solved the problem.