Many owners of Android-backgrounds have difficulties with the launch of this Linux-software on their devices. By all laws, he seems to be working here, but for some reason root rights are only needed to install it, it itself is distributed in some self-made installers, and the choice of programs is severely limited. This article will offer the answer to the question of why this happened, and will prompt the solution - a convenient way to install and run almost any Linux software on Android.
Linux or not Linux?
As you know, android is based on the Linux kernel and includes a set of standard libraries and command line utilities inherent in the usual Linux distribution. However, launching classic Linux software is very difficult here due to a variety of reasons, including ABI incompatibility, the lack of a package manager, its own security system, and the absence of many components of a standard Linux system.
')
So, despite the availability of the standard libc library and others in Android, their implementation is in most cases incompatible with the libraries from the GNU project and severely curtailed in functionality. For this reason, Linux-software needs at least to be recompiled specifically for Android and an ARM processor, and in many cases also a patch, adding functionality that is missing from the libraries.
BotBrew: list of supported devices
BotBrew was tested on the following devices: Barnes & Noble Color NOOK, LG P970 Optimus Black, Huawei Ascend M860, HTC Desire, HTC Evo 4G, HTC Evo 3D, HTC Inspire 4G, HTC Droid Eris, HTC Hero, Samsung Galaxy Nexus, Samsung Galaxy S2 (GT-I9100), Samsung Galaxy Y (GT-S5360), Motorola Atrix 4G, Motorola Droid / Milestone, Sony Ericsson Xperia X8, Asus EeePad Transformer TF101.
The Android security system, which cuts applications in full privileges and does not allow them to go beyond their own directory, also seriously hampers the work of standard Linux software. Therefore, it is often required to obtain root rights that remove these restrictions. The absence of a package manager that would allow the installation of regular Linux software, and not just Java applications, forces developers to write applications that are needed only to install other applications. So all these custom installers appear.
Well, the picture is completed by the fact that Android simply does not have many standard Linux components, including, for example, even such integral components as the X Window Graphics Stack or the GTK + library. Some attempts to bring all this here, of course, are being made, but the matter does not move beyond the half-working alpha versions.
Nevertheless, the ability to transfer the full-fledged Linux system functionality to Android is too tempting an idea for enthusiasts not to try to solve the problems arising in the process and give us a full-fledged universal solution. The most obvious and simplest way is to run a “virtualized” version of a full-featured Linux distribution, which we have already written about in detail. This method is interesting, but suffers from the problem of separating the system into two areas, each of which operates independently of the other.
The
BotBrew project looks much more interesting - it is developing a package manager and a repository that is quite common for Linux systems, with which you can install Linux software into a single directory inside Android. Also, at one time, many different scripts were invented, which make it easy and without any problems to assemble suitable for work inside Android Linux-software on a big brother. These two projects will be devoted to the rest of the article.
Botbrew
The BotBrew project is designed to solve many problems with installing Linux software that a user may encounter, and prepare the Android system for accepting applications that are foreign to it. In essence, the system consists of four components:
- repository with precompiled Android applications, using which you can install many Linux applications with one command;
- package manager, which is used as a lightweight Opkg or dpkg along with apt-get in the experimental version of BotBrew Bazil;
- process manager runit, necessary in order to properly run and maintain the work of demons, if any, will be installed;
- own build system, which contains all the tools needed for cross-compiling applications using any desktop Linux distribution.
To work, this miracle of programmer thought requires nothing at all: the rights of root and some free space in the internal memory of the smartphone or on the memory card. And the first option is preferable, since in the case of SD files will be dumped on a virtual disk, work with which is far from being supported by all cores.
Initial initialization
List of installed applications
Currently, the classic version of BotBrew, which uses its own repository, allows you to install software such as dcron, GCC, Git, dropbear SSH server, Lynx console browser, Nmap security scanner, rsync backup tool, Vim editor, lighttpd web server, scripting languages Python and Ruby, as well as dozens of other packages. This is all set, by the way, to the selected directory in the internal memory of the smartphone / tablet and does not litter the main system. In other words, you can get rid of BotBrew and everything that you have installed by simply deleting one directory.
We put software
So, how do you use BotBrew to install Linux software? First we need a package with the program itself. It is on Google Play (note that you need a BotBrew root, not an experimental Bazil) and weighs less than a megabyte. After installation, we launch and press the “Proceed” button at the bottom of the screen so that the software can download all the components necessary for its operation, such as the console package manager, and other utilities (in terms of Debian Linux - bootstrap). They weigh only a few megabytes, so they will not have to wait long. After the installation is completed, BotBrew will display a window with the official project web page, which can be safely closed.
Now on the screen you should see a list of packages available for installation. There are quite a few of them, but for the reasons described above, you will not find them among them. But there are variegated servers, compilers and interpreters, so that anyone who wants to seriously "play" with a smartphone will have where to turn. To install the package, just click on its name and on the next screen containing information about the application, click the Install button.
Dances with tambourines
If you encounter problems during the BotBrew bootstrap, you can try installing it manually with the following command:
wget http://repo.botbrew.com/anise/bootstrap/install.sh -O - | su
If this does not help, you can try to delete all the settings (“Remove BotBrew” in the settings) and then try to run this command.
After that, the package will appear on the “Installed” tab, but you will not see any “Run” button or the like. The application will have to run independently from the console, which, however, is logical. The application itself is installed inside the / data / botbrew directory structure, in which the real environment of the Linux distribution with the / etc, / usr and other directories is “emulated”. And in order not to torment users with the need to dial the full path to the team, the BotBrew developers provided for the same-name wrapper command. In order to use it to launch, for example, the installed Lynx console browser, type the following command:
$ botbrew lynx http://xakep.ru
Alternatively, the / data / botbrew / bin directory can be added to the PATH environment variable, but this will have to be done after each launch of the terminal:
Log site in Lynx console browser
Package Installation Process
$ export PATH="$PATH:/data/botbrew/bin"
With demons and different network services, by the way, things are much better. After the start, the demons will be launched immediately, and you can control their activation through a graphical interface, accessible by clicking on the “Play” button at the bottom of the BotBrew interface. Some applications may require creating additional users and changing their settings, this can be done the same way as in a regular Linux system:
- Create user:
$ botbrew adduser vasya
- Opening user access to the Internet:
$ botbrew addgroup vasya inet
- Switch BotBrew to another user:
$ botbrew su vasya
Please note that all these changes will apply only to the BotBrew virtual environment and will not affect the main system in any way. The console can also be used to install applications bypassing the graphical interface. To do this, use the Opkg console package manager, the command syntax of which is fully compatible with apt-get:
$ botbrew opkg install dropbear
Reverse operation:
$ botbrew opkg remove dropbear
In order to remain “on the cutting edge of progress”, the BotBrew repository needs to be updated from time to time by clicking on the corresponding button in the graphical interface (you will not confuse it with anything). New versions of packages will be displayed on the “Upgradable” tab. It is enough to tap on his name and click "Upgrade".
Managing BotBrew services is really easy.
Botbrew basil
In the market you can also find an application called BotBrew Basil, marked as experimental. In fact, this is still the same BotBrew, but with one very important difference. Instead of his own repositories and the Opkg package manager, he uses the Debian Linux ARM repositories and the apt-get package manager. This means that the amount of software that can be installed using the “Brazilian version” of the application is much larger. Ten times more.
In addition to using Debian repositories, Basil also has a slightly modified interface. For example, immediately after launching it offers to select the installation directory. The default is / data / botbrew-basil, which, in my opinion, is quite logical, but you can choose any other one, including on the ext2 section of the memory card (FAT will not work).
The second important difference is the ability to choose how to use the application, which appears immediately after clicking "Proceed". There are four options:
- Use BotBrew on the command line - in fact, an analogue of the installation in the style of the usual BotBrew.
- Use the dpkg / APT system - installation along with apt-get and Debian repositories. Recommended installation option.
- Run Python programs - analogue of the first version with automatic installation of Python.
- Install a minimal Debian is a minimal Debian install.
Let me explain the second and fourth paragraphs. The first BotBrew and the first item on this list do nothing more than installing a minimalist Linux system (consisting of just a few commands and libraries), within which Linux software is launched. However, apt-get, unlike the minimalist Opkg, requires a more or less complete installation of Linux. Therefore, choosing the second item, you will receive on your smartphone a sort of micro-Linux. And if we can install microversion, why not install a more or less full distribution. For this, there is a fourth point.
After the BotBrew Basil bootstrap, the same application management interface will appear on the screen, familiar to us from the classic version of the application, and the botbrew2 command will appear in the system, with which you can run the software. There are no significant differences in management here, except perhaps the apt-get commands instead of opkg and the ability to connect additional repositories (including the repository of the first BotBrew) directly through the application installation interface.
BotBrew Basil offers several installation options.
Take matters into your own hands
Precompiled applications and repositories with ready-made packages are fine, but what if the necessary application is not among those available for installation? After all, even the same BotBrew Basil, which allows you to connect Debian repositories with a huge amount of software, by virtue of its experimental nature, not every smartphone will work.
In this case, we can try to build the application yourself. However, there are several difficulties waiting for us at once: the fact is that in order to build software for a smartphone, you will need to prepare the necessary cross-compilation tools, then take into account all the dependencies of the application being built and, finally, in some cases make the necessary changes to the code. All this is quite troublesome, which are hardly worth spending time on them.
Nevertheless, we can take advantage of the practices of other people to automate the process of building software. One of the most developed and interesting solutions from this area is the set of
SCRIPTSET scripts developed by user smitna with XDA Developers. It allows literally in a couple of commands to assemble a variety of various applications, including htop, ImageMagick, iptables, ELinks, Screen, mc, node.js, Samba, strace, QEMU, Parted, SANE (it can be used for direct printing on a printer with phone!) and many others. The script itself will download the cross-compiler, all the necessary dependencies and applications, apply patches where necessary, and generate an archive ready for unpacking on the phone.
SCRIPTSET only works on Linux, but if you have Windows, you can install Ubuntu in a virtual machine. Next, open the terminal and install the necessary tools to build a cross-compiler:
$ sudo apt-get install build-essential cmake autoconf2.13 scons
After that you can get the SCRIPTSET itself and unpack it:
$ cd ~ $ wget http://goo.gl/zvnom -O scriptset-2.6.zip $ unzip scriptset-2.6.zip
As a result of unpacking, we get ... another archive: scriptset-2.6.tar.bz2. But that's not all, the archive is packed without the traditional tar root directory, so you need to create it yourself. And already in it to make unpacking:
$ mkdir scriptset $ cd scriptset $ tar -xjf ../scriptset-2.6.tar.bz2
After unpacking, several scripts, configs, and an impressive size README file containing instructions on how to use scripts will appear in the catalog. The scripts are not worth the performance bits (which is not surprising, given the previous troubles), so it must be put on its own:
$ chmod 755 *.sh
Run application build
Next, open the configuration.conf file for editing and change the following lines in it:
This will be enough for the correct assembly of any application; The target processor will be a standard ARMv7 with an additional set of instructions NEON. This is installed in any smartphone released over the past three or four years. The / data / sysroot directory will be used to install applications on the smartphone, however, oddly enough, it will also have to be created on the desktop machine:
$ sudo mkdir -p /data/sysroot $ sudo chown user:users /data/sysroot $ sudo chmod 777 /data/sysroot
As the author of the scripts explains, such an action is necessary because the paths for the key directories in some applications are stitched at the assembly stage. Therefore, if we collected the application using the current and any other directory as the root, it simply would not work on the smartphone due to the difference in the paths. I am sure that it would be more correct to solve this problem with the help of chroot, but it is easier and faster to create the necessary directory, and at the end of the work - to delete it.
Next, we must specify the list of applications that we plan to build. To do this, open the package_selection.conf file and change no to yes in the necessary options. For example, to build bash, ImageMagick and Screen, you need to change the following three lines:
Keep in mind that settings that are between the # ALWAYS NEEDED lines cannot be changed. These applications and libraries are always needed, and without them other applications are simply not built. Now you can compile the application. To do this, simply run the build.sh script with no arguments:
$ ./build.sh
If all the necessary packages were installed and the compiler did not generate any errors during the build, as a result of the build, two archives will appear in the current directory: cs-sysroot.tar.bz2 and android-mysysroot.tar.bz2. The first is the environment required for launching applications created by the cross-compiler, and the second is the set of applications itself. Both of these archives must be dropped onto the smartphone's memory card, and then, running the terminal emulator on it or connecting via ADB, execute two commands:
$ tar xjf /sdcard/cs-sysroot.tar.bz2 $ tar xjf /sdcard/android-mysysroot.tar.bz2
As a result, the / data / sysroot directory will appear in the internal memory of the smartphone, in which the applications will be placed. They should be run from the same terminal, indicating the full path. For example:
$ /data/sysroot/usr/bin/bash
Well, or after starting the terminal, add / data / sysroot / usr / bin to the PATH:
$ export PATH="$PATH:/data/sysroot/usr/bin"
findings
Despite the rather serious differences between Android and a typical Linux distribution, installing Linux console applications on a smartphone is not so difficult. Unfortunately, we are not talking about graphic applications yet, but there are already projects to port the Qt library and Wayland graphics server to Android, and soon, I hope, we will get a working solution.
First published in the magazine "Hacker" from 08/2013.
Publication on Issuu.com
Subscribe to "Hacker"
