As per the official documentation it's not possible to run Genymotion on a headless server. This is because Genymotion does the UI processing outside the VM on the host. If the host is headless, i.e. doesn't have hardware acceleration, Genymotion won't be able to render the Android OS display. As a result the VM will boot up in VirtualBox but there won't be any display.
(Note that getting a GUI via X11 Forwarding, XRDP, X2Go is not the same as a dedicated display. These are virtual displays. The Genymotion app will start but on booting an Android VM the player window will be blank.)
Quoting from https://stackoverflow.com/a/39448004/1833653
When you start a Genymotion device on the standard way from Genymotion Soft, the Android OS is starting inside a VirtualBox VM but all the UI processing (which uses OpenGL) is done outside the VM to make the rendering pipeline uses your computer's GPU. Using this hardware acceleration makes the Genymotion devices fairly smooth and fast.
When you start the Genymotion VMs directly from VirtualBox, the OS will start but the rendering won't be hardware accelerated. From 2.3 to 4.2 there is a fallback solution: the rendering will be computed by the CPU, from inside the VM. From 4.3, the soft rendering is not a good solution as it will slow down the OS too much to be acceptable, that's the reason why we've disabled it and it cannot be enabled.
However this is not entirely true. Genymotion by design is a client-server application. The Genymotion player which renders the UI is entirely a separate part from the Virtualbox VM. The player and the Android OS (running inside VirtualBox) communicate over the network. So if we separate these two parts, i.e. keep VirtualBox on the headless server and move the Genymotion app to a machine which has a dedicated display, this should be possible.
This is actually totally possible using IPtables magic and spoofing the VBoxManage
command which Genymotion uses to communicate with VirtualBox.
GENYMOTION_IP=192.168.59.102 # Host only IP of the Android VM running in VirtualBox
SERVER_IP=169.254.166.118 # IP of the machine where VirtualBox is installed
CLIENT_IP=169.254.170.151 # IP of the client where Genymotion player is running
GENYMOTION_NIC=vboxnet3
SERVER_NIC=enxd0374542b8e9
CLIENT_NIC=ens35
Run remote VBoxManage script
python remoteVBoxManage.py
Set up traffic redirection. Can be done in any of the two ways:
- Use port formwarding with socat
socat -d -d tcp4-listen:5555,reuseaddr,fork,bind=$SERVER_IP tcp:$GENYMOTION_IP:5555 socat -d -d tcp4-listen:22468,reuseaddr,fork,bind=$SERVER_IP tcp:$GENYMOTION_IP:22468 socat -d -d tcp4-listen:24810,reuseaddr,fork,bind=$SERVER_IP tcp:$GENYMOTION_IP:24810 socat -d -d tcp4-listen:24800,reuseaddr,fork,bind=$SERVER_IP tcp:$GENYMOTION_IP:24800 socat -d -d tcp4-listen:25000,reuseaddr,fork,bind=$SERVER_IP tcp:$GENYMOTION_IP:25000 socat -d -d tcp4-listen:6379,reuseaddr,fork,bind=$SERVER_IP tcp:$GENYMOTION_IP:6379
- Use iptables to set up a redirect
ORsudo iptables -t nat -A PREROUTING -i $SERVER_NIC -p tcp -d $SERVER_IP --match multiport --dports 5555,22468,24810,24800,25000,6379 -j DNAT --to-destination $GENYMOTION_IP sudo iptables -t nat -A POSTROUTING -o $GENYMOTION_NIC -p tcp -d $GENYMOTION_IP --match multiport --dports 5555,22468,24810,24800,25000,6379 -j MASQUERADE
sudo iptables -t mangle -A PREROUTING -i $SERVER_NIC -p tcp -d $SERVER_IP --match multiport --dports 5555,22468,24810,24800,25000,6379 -j MARK --set-mark 0x1337 sudo iptables -t nat -A PREROUTING -i $SERVER_NIC -p tcp -m mark --mark 0x1337 -j DNAT --to-destination $GENYMOTION_IP sudo iptables -t nat -A POSTROUTING -o $GENYMOTION_NIC -p tcp -m mark --mark 0x1337 -j MASQUERADE
Redirect traffic destined for GENYMOTION_IP
to SERVER_IP
sudo iptables -t nat -A OUTPUT -p tcp -d $GENYMOTION_IP -j DNAT --to-destination $SERVER_IP
sudo iptables -t nat -A POSTROUTING -o $CLIENT_NIC -p tcp -d $SERVER_IP -j SNAT --to-source $CLIENT_IP
For some reason MASQUERADE
doesn't work, so have to use SNAT
as above
# This doesn't work
sudo iptables -t nat -A POSTROUTING -o $CLIENT_NIC -p tcp -d $SERVER_IP -j MASQUERADE
Run genymotion, override path of VBoxManage
. Genymotion VMs can be listed by genyshell
[Source]
export SERVER_IP
PATH=/home/ec/Desktop/genymotion/plugins/:$PATH ./genyshell -c "devices list"
PATH=/home/ec/Desktop/genymotion/plugins/:$PATH ./player --vm-name "Android M"
To remove an iptables rule, list them line by line and then delete the corresponding one
sudo iptables -t nat -L --line-number
del: sudo iptables -t nat -D OUTPUT 1
remoteVBoxManage.py
Run this on server. This purpose of script is to execute the real
VBoxManage
and send the results back.