Introduction: This is a guide to make work an Ubuntu GNU/Linux container inside an Android operating system session, and by this way have the desktop computer functionality without loosing performance. This is a very detailed guide, also useful to people who wants to create a wizard or improve the procedure.

Notes:

At the moment of writing this guide (november 2011), Canonical still doesn't have its own solucion ready. The best working version for the default desktop (Unity) is the 12.04 (Precise)

The total downloads proposed can reach to 1GiB of data; if you do all from the device, take care of the data plan prices that applies the internet access provider.

Superuser permissions (root)

It's a requirement to have "su" access to manage the operating system.
Es un requisito tener acceso "su" para administrar el sistema operativo. You can see the guide Open permissions in Android

Terminal access

Local terminal

It's advisable always to have a Terminal application (that you can get freely with F-Droid) available to can do managements with mobility, but it's more comfortable to do the long and complex preparations from a desktop computer, controlling the device connected through USB.

Remote control

In the Ubuntu GNU/Linux distribution, since version 12.01 in the universal repository there is available the package android-tools-adb that allows the remote control to a device with Android in USB debug mode. There is also an independent repository that provides android-tools for previous versions.

To use the Android Debug Bridge (ADB) you must have the device working, plugged through USB, and with the mode "USB debug" enabled in the developer preferences of Android.

ADB through USB

To check the connectivity:

adb devices

(must show a "list" with a rare identifier that says it's a device)

To open a terminal session in the device:

adb shell

To start a superuser (root) session, and have Android administration permissions:

su

To end as superuser and after also close the terminal session:

exit
exit

ADB through network

Many connections through USB aren't much stable (break often and you realize that are writing in your computer), and in these cases it's solved with net (Wifi). When this is done, it's important that the device hasn't direct internet connection (for example with the telephony provider) and it's working in a communication through the local Wifi.

From Android, to see the enabled network devices (default... dev -->):

ip route list

From Android, to see the IP address of a network device (for example wlan0):

ifconfig wlan0

From the computer, to set the communication to be through network (for example to the IP 192.168.1.122):

adb connect 192.168.1.122

To open a terminal session in the device:

adb shell

To start a superuser (root) session, and have Android administration permissions:

su

To end as superuser and after also close the terminal session:

exit
exit

Additional notes

In this guide, where written commands are indicated, they are to be run in a local or remote terminal window.

If you get messages as "Operation not permitted" , it's often because you didn't begin as superuser (su)

Take note of the architecture

The processor generation used by Android can be looked with one of the following commands:

uname -m
cat /proc/cpuinfo

If the device's ARM processor supports floating-point (ARMv7 or superior, for example armv7l matches), then you can use "armhf" instead of "armel". This enhaces some processes speed.

Prepare the space

To allow working of the links and device accesses is needed that the new container resides in a properly partition for GNU/Linux, such as Ext3 or Ext4. With the mount command you can see the format of each volume, and with the following syntax it's seen very clear:

Once seen the compatible paths, you must value the free space available with this command:

df

If in the free space there isn't mention of the measurement unity (100K, 100M, 100G), this means that it's expressed in K (KiB). Care that the path /cache works as an "internal trash" and its content can be deleted automatically.

You need at least 100MiB for an elemental installation (only core), or near 250MiB for a debootstrap, but can be reached a use of 2 or 3GiB if you install all the big desktop applications of common use, and apart counting some working space. Also installations "for all the pockets" can be done.

For the rest of the guide we will suppose that you choosed the partition /data , and then you put the new operating system in /data/ubuntu . Then you must enable permissions for writing, executing, devices and superuser in the partition, and create the subdirectory:

Get an operating system base

To trainsport the directory tree from a device to another, must be copied qith superuser permissions, to not loose the files and directories attributes. To open in this way a folder explorer with Ubuntu, you can execute (Alt+F2) "gksudo nautilus".

But here we also propose the way to do it completely from the Android device: downloading a prepared base (from official website) with only one of the following commands, depending on version and variant you need (more versions are published in cdimage.ubuntu.com):

Enable graphical interface

Although it appeared some X-Server tool to use applications directly in the screen without remote control, for the moment we expose the traditional method 2011-2012 (supposing in the example the device screen has a resolution of 1280x720):

Open Ubuntu desktop from Android

Connect to the address localhost and with the normal port 5900. Without user (nickname) nor password. You have an enough secure access because it only will allow connections from the same device (-localhost).

Exit

If you want to use Android again it's enough with closing VNC, or simply minimize to do other things. If you shutdown the device with Android don't worry; it's as you also close the Ubuntu desktop as it was a computer.

If you want to stop the Ubuntu system without stopping nor restarting Android, you must exit from the session in the same Ubuntu desktop, same as you do it from a normal computer: with the graphical shutdown button, but with the user logout option. If you see a terminal window, also closing it the session is closed. With the following indications you will do a completely clean exit from the container.

Stopping services: In the Terminal window where you had the x11vnc waiting for connections, if it's still waiting, you can break it with {Control} + {C}. After this the rest:

To repeat the experience

If you haven't ended the session from inside Ubuntu, you can simply connect again with the CNV client program.

The best, of course, is to have direct icons in the Android desktop, both to mount the container and to connect to the desktop via VNC. This wiki will thank the contributions about this.

In other cases, such as you have stopped the device or stopped the Ubuntu container completely, write these instructions in a Terminal window (data from the same example in this page, which must be customized):

Connect with the VNC client application to the address localhost and with the normal port 5900. Without user nor password.

Obviously the best is to have the commands in scripts (executable text files): from the first "mount" until the "chroot" in an Android script (for example /system/bin/m) and the rest in a script in UBuntu (for example /usr/local/bin/x). By this way, the only steps in a terminal could be:

su
m
x

And to do is in a single command, you can change the line chroot "$RootPoint" /bin/su by chroot "$RootPoint" /bin/su -c /usr/local/bin/x , and then also write a script in Android (/system/bin/u) that contents a single line with su -c m . With this, the service starts with a single command in the terminal:

Launchers in Android desktop

With SL4A you can prepare a Bash script (Shell script) that can also be run without showing the terminal window (in background). With this you can replace "u" that we have written as an example, creating a script called for example Ubuntu.sh and with content su -c m

To crate an icon on the desktop (Home) to launch Ubuntu in background, press the desktop background during some time until it opens an options menu, and select to create a customized link/launcher (Custom shortcut). Select the activity "Scripts" that has the shining-eyes icon (LS4A), select your program "Ubuntu.sh" and select that it starts in background (gear button). You can finish customizing a title as "Ubuntu 0" and press Ok.

You can use the same technique to create a launcher that connects directly through VNC: long-pressing on the desktop background, Customized launcher (Custom shortcut), select activity (Pick your activity), VNC connection, select the "localhost:5900", give it a title as "Ubuntu 1" and Ok.

With these 2 launchers, you already have Ubuntu in 2 taps: first to the SL4A icon that works in background, and after the VNC icon that connects. Don't launch again the SL4A icon if you aren't sure that it's stopped. You can connect and disconnect as many times as you want, while Ubuntu is launched in background with SL4A.

A known issue: If the menu opens but the option to create a launcher/link/shortcut doesn't appear in the desktop (it only offers to change background), you are probably using the "Trebuchet" desktop that lacks some feature. You can install the desktop manager AnDerWeb to fix it, but it doesn't maintain the previously set icons.

How to see the things bigger

There are pocket devices that have a high point density in a touchscreen, that is, much resolution in a so small screen. Taking all the resolution in these situations makes difficult to hit the desktop elements with a finger.

If in this guide example you want to see the things twice larger, change the resolution of 1280x720 by 640x360, and the scale of 1/1 by 2/1. This means to divide by 2 the resolution and increasing the small image to double to it fills the screen. The operation can be done in any proportion; here an example to do it at two thirds (that implies a 50% of growth):