These instructions are based on the notes from the NA-MIC Project week 31 - GCP setup for Slicer project. The original notes were copied here for more convenient maintenance and refinement.
Replicate Slicer running GCP machine with instructions and write them down for the public
You have two options to access VNC:
Configure Firewall to open the noVNC port:
Configure prerequisites on your machine:
$ gcloud init
$ gcloud compute ssh <VM instance name>
sudo apt-get -y update && \
sudo apt install -y ubuntu-drivers-common && \
sudo ubuntu-drivers autoinstall && \
sudo apt install -y xinit && \
sudo apt-get install -y x11vnc && \
sudo apt-get install -y xterm && \
sudo apt-get install -y libpulse-dev libnss3 libglu1-mesa && \
sudo nvidia-xconfig && \
sudo apt-get install -y python && \
git clone https://github.com/novnc/noVNC
Execute the following and take note of the BusID
sudo nvidia-xconfig --query-gpu-info
Open the X11 configuration file
sudo vim /etc/X11/xorg.conf
and insert the following BusID
line using the BusID value you retrieved earlier into this Section:
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BusID "PCI:0:4:0"
EndSection
or if /etc/X11/xorg.conf does not exist, create a file in /usr/share/X11/xorg.conf.d/xorg.conf
with the contents listed above.
To set the size of the virtal display you can edit the Screen section as shown below.
Section "Screen"
Identifier "Screen0"
Device "Device0"
DefaultDepth 24
Option "UseDisplayDevice" "none"
SubSection "Display"
Virtual 1920 1080
Depth 24
EndSubSection
EndSection
Note: if the Slicer font and icons size is too small, run xrandr
to find the max resultion and use that as the Virtual setting. Then use xrandr
or install axrandr
to resize the desktop to a comfortable size.
On some devices (e.g. nvidia A100) xinit will fail if you have the Option "UseDisplayDevice" "none"
option, so delete that line for that device.
Each reboot (e.g. after doing 'start' on the google cloud console). The commands below are set up so you can cut and paste them into the ssh terminal from the google interface, but if you want to debug more easily them you might want to paste each in its own terminal.
sudo xinit -- +extension GLX &
./noVNC/utils/launch.sh --vnc localhost:5900 &
while true; do x11vnc -forever -display :0; sleep 1; done
Note that the while true ...
part in the instructions above is needed to address the possible intermittent crashes of x11vnc. You can improve stability by building x11vnc
from source (see Troubleshooting section).
Here using a specific revision, but any version should work
wget http://slicer.kitware.com/midas3/download/item/435293/Slicer-4.10.2-linux-amd64.tar.gz
tar xvzf Slicer-4.10.2-linux-amd64.tar.gz
Note: this is a very raw linux machine and you are running as root. There is also a user account under your name that is automatically created by the google VM boot process. Pretty much anything from the last few decades of linux development should run the same here as it does on a local workstation.
cd Slicer-4.10.2-linux-amd64
./Slicer
It is better to start Slicer as a non-root, since otherwise it will not be possible to install extensions. You can do this with
$ su <user name> && ./Slicer
gcloud compute ssh <your VM name> --project <your GCP project name> --zone <your VM zone> -- -L 6080:localhost:6080
If anyone works on these issues please write them up and let us know:
sudo apt-get install -y openbox && openbox-session
in the terminal window is one way to start. A lot of things won't work out of the box but you can configure the files in /etc/xdg/openbox
. (E.g. edit /etc/xdg/openbox/menu.xml and change the <execute>
section to xterm
.If you have trouble with the x11 server disconnecting when openning menus or resizing files, you are probably hitting this bug which is not yet fixed in ubuntu.
You can replace with a patched version like this (as root):
curl "https://drive.google.com/uc?id=1FCTxYPAPf58AqchST0SLYfZFZoVANCfL&export=download" -o x11vnc -L
sudo cp x11vnc /usr/bin/x11vnc
sudo apt-get install x11-xserver-utils
and then xset r rate 300 10
(you also need run xset r on
twice to override the -norepeat option of x11vnc)You can also build x11vnc
from source using the instructions below.
sudo cp /etc/apt/sources.list /etc/apt/sources.list~
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt-get update
x11vnc
build dependencies, checkout source, configure and build (as in the x11vnc
build instructions).
sudo apt-get build-dep x11vnc
git clone https://github.com/LibVNC/x11vnc.git
cd x11vnc
autoreconf -fiv
make
The binary will be in the src
directory!
Some recipes, such as this one, recommend using vncserver
, which is a wrapper around xvnc
. Based on this post on NVIDIA forum, xvnc
does not support GLX, and will not work with Slicer.
If you experiment with alternative VNC implementations, please share your experience via PR!
If something is not working, you can debug individual components.
On the server:
xinit
in the foreground mode and check if there are no errors.x11vnc
in a separate terminal window, and check there are no errors.x11vnc
is listening on port 5900 after startup:
$ nc localhost 5900
On the client:
x11vnc
directly bypassing noVNC. If you are on mac, do NOT use the default macOS VNC client! We confirmed that Chicken open source VNC client can establish connection under the same conditions where default macOS client cannot.By default there is no swap space allocated on the machines. You can add this using standard linux commands such as these:
sudo fallocate -l 90G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
To make this persist across boots, add this to the /etc/fstab
/swapfile swap swap defaults 0 0
Check your swap status with these commands
sudo swapon --show
sudo free -h