Hello guys! Today I would like to share a little trick to be able to take advantage of the graphical environment in Google Colab or in other words turn 1 google colab into a linux VPS completely free by SSH and TurboVNC. I tried running some basic OpenGL applications, blender, firefox and felt pretty good.
Note: After 12 hours Colab will reset itself and have to start over, you can mount Google Drive first to save it to avoid file loss.
1. How to run OpenGL desktop programs on Google Colaboratory
More details of this procedure:
If you have questions:
1. Sign up for ngrok if you use it
- You don’t need to buy paid plans.
2. Change runtime type if you want to use OpenGL
- After you open Google Colaboratory, click “Runtime” -> “Change runtime type” in top menu and change Hardware accelerator to GPU.
3. Copy following code to a cell in Colaboratory
- ngrok!pip install git+https://github.com/demotomohiro/remocolab.git import remocolab remocolab.setupVNC()
- Argo Tunnel!pip install git+https://github.com/demotomohiro/remocolab.git import remocolab remocolab.setupVNC(tunnel = "argotunnel")
4. Click run bottom in top left
5. Copy ngrok authtoken if you use ngrok
- After the message that ask you to copy ngrok authtoken displayed, login to ngrok, click Auth on left side menu, click Copy, return to Google Colaboratory, paste it and push enter key.
6. Select ngrok region
- Probably the region closest to you is fastest.
7. Wait for TurboVNC running
- It setup OpenSSH server, VirtualGL and TurboVNC.
- When it done, passwords of root and colab user, ssh command for local port forwarding and VNC password is displayed.
8. Login to Google Colaboratory using SSH
- Login to the SSH server running on your Colaboratory’s virtual machine by executing the ssh command under “Execute following command on your local machine and login before running TurboVNC viewer:” message.
- Use the password displayed right side of “colab password: “.
- Keep logined while you use VNC.
9. Run TurboVNC Viewer
- Set server address to localhost:1 and connect.
- When password is required, copy & paste the password displayed right side of “VNC password: “.
After connecting VNC server, you will see the screen like this.
You can check the availability of NVIDIA OpenGL implementation with following command.
$ vglrun /opt/VirtualGL/bin/glxinfo | grep NVIDIA
If everything fine, you will see following output.
OpenGL vendor string: NVIDIA Corporation OpenGL core profile version string: 4.6.0 NVIDIA 418.67 OpenGL core profile shading language version string: 4.60 NVIDIA OpenGL version string: 4.6.0 NVIDIA 418.67 OpenGL shading language version string: 4.60 NVIDIA
Following steps are supposed to be run on remote desktop. TurboVNC Viewer can copy & paste between your PC and remote PC. OpengL programs need to be run with vglrun command or it uses software GLX/OpenGL implementation included in The TurboVNC and rendering can be slow.
If you want to run a program from SSH and display it on the VNC screen, add DISPLAY=:1 to your command like this:
$ DISPLAY=:1 vglrun firefox &
Open terminal and execute following commands.
$ su # apt install firefox # exit $ vglrun firefox
Then, open Shadertoy on the firefox.
Download Unigine Valley from Unigine Valley . Then, extract the file and run it like following command.
$ chmod +x Unigine_Valley-1.0.run $ ./Unigine_Valley-1.0.run $ cd Unigine_Valley-1.0 $ vglrun ./valley
Download the file for Linux 64bit from official Blender site. Then, extract the file and run it like following command.
$ tar xf blender-2.79b-linux-glibc219-x86_64.tar.bz2 $ cd blender-2.79b-linux-glibc219-x86_64 $ vglrun ./blender
Download the file for Linux 64bit from official Godot site. The, extract the file and run it like following command.
$ unzip Godot_v3.1-stable_x11.64.zip $ vglrun ./Godot_v3.1-stable_x11.64
remocolab download and install OpenSSH, TurboVNC , libjpeg-turbo, VirtualGL and Xfce . It run desktop on Google Colaboratory ‘s virtual machine and make it accessible from your PC using TurboVNC. TurboVNC send desktop screen on the server to the client PC running TurboVNC Viewer , and receive mouse and keyboard input from the client PC. TurboVNC compress desktop screen image using libjpeg-turbo before sending it. These communications are encrypted by using SSH port forwarding. remocolab configures TurboVNC so that connecting to it without using SSH is forbidden. VirtualGL allow OpenGL programs can use Hardware accelerator using a GPU on server like they are executed on normal desktop.
Open TurboVNC Viewer Options and change Encoding method to Tight + Medium-Quality JPEG or Tight + Low-Quality JPEG(WAN) . Some noise will appear but looks smoother.
Open TurboVNC Viewer Options, click Connection tab and set Remote desktop size.
* Bonus VIDEO: