No Way! Run Ubuntu Inside Termux inside a Unrooted Android Phone..

In this crazy rabbit-hole for funsies we install Ubuntu inside Termix inside the JRE of the controlled Android Google phone!

No Way! Run Ubuntu Inside Termux inside a Unrooted Android Phone..
Yes. I ran Ubuntu inside a Unrooted Android Phone and it Worked.

I have no purpose shopping at the mall. But my coparts love shopping at the mall and want me to come.  Therefore I buy coffee and go putter at the coffee shop with my android phone. Out of pure boredom I hooked it to a bluetooth keyboard and reexplored a popular old terminal emulator - namely Termux.  The idea was how much serious computing can I do from this phone?? The result was actually shocking.

Step 1: Install F-Droid and allow it to download and install 'untrusted' applications (side-loading)

Once you have that done from the search glass you will find Termux which you can install:

Once you have it installed you have a unrooted terminal emulator that can actually do a lot!

An example screen shot that shows it working.

Installing Ubuntu inside Termux and running it - it was shockingly simple:

termux-setup-storage
pkg install proot-distro
proot-distro list
proot-distro install ubuntu
proot-distro login ubuntu

And the prompt quickly changed:

Here is were it gets wild...

Ubuntu is running virtually inside Termux which is running virtually inside a JRE inside the Android system (I know crazy right!)  But what is really wild is you can remote ssh into Termux. But going one level deeper we wanted to see if we could ssh into Ubuntu inside Termux inside ... you get the idea..

Strange bizarre things start to happen.  For instance we now can see the full stack of ip devices as in:

But we cannot bind to any port of the 192.168.1.104 that requires root. Modifying our ssh file

nano /etc/ssh/sshd_config

And chaning it's port to 2200 and then restarting ssh with:

service ssh --full-restart

It worked!

We now were able to login the virtual Ubuntu with a virtual User we created at port 2200!

A list of available distros (they installed very quickly and cleanly)

Some problems.  We did find that Ubuntu did get corrupted and ended up wiping and reinstalling Termux.  Because it is specialized, the termux repository was rebuilding and would not reinstall.  But as a POC (Proof of Concept) it worked and was very eye popping in that you have a full VM inside a single application inside your usually very locked down and hyper-controlled android phone.  

For those that don't mind sticking around the non-gui console and like working in raw Linux - it offers a real game-changer in that you potentially can have a full compute-edge device inside your own pocket!

Possibilities:

Amazing possibilites arise from being able to set this up. Consider:

  • ssh -R (reverse tunnel) with option keep-alive to a VM with an exteral IP would allow you to ssh access your phone via the public internet!  That is pretty powerful for a 'roll-your own' solution.
  • It seemed that emulation was occuring.  In essence when the Ubuntu was working we had full access to the Ubuntu repositories normally offered.  Which offered that you could run hypotheticlaly Python3.9 or golang or even a full gcc compiler.
  • termux-location (Find your phone from remote.)
  • termux-camera-photo (Turn your phone into a remote picture taking sensor) With the right script it would take a photo and upload automatically to the internet.
  • termux-microphone-record (Turn your phone into a remote audio recording device). Again the possiblities are endless here.

Even More Potential Can be Realized.

  • Couple this remote managed phone to a Raspberry Pi and start controlling real world circuits from anywhere in the world over the cellular network.
Controlling Raspberry Pi GPIO using Android App over Bluetooth
In this DIY tutorial we are going to control Raspberry Pi GPIO Pin through an Android app using Bluetooth.
Linux Rocks Every Day