Your path to becoming an Ethical Hacker! Hacking Academy Try It Now!

Differences of Termux from Linux

Termux: A powerful Linux-like environment for Android. Learn about its differences, setup, and limitations. Ideal for development and experimentation.
In Termux, setting up the environment is like doing it in a modern Linux system. But because Termux runs on Android, there are some key differences to keep in mind.

Differences of Termux from Linux

Termux is not FHS compliant

Termux does things a bit differently from regular Linux systems, which can affect how you use it. Unlike most Linux distributions, Termux doesn't stick to the Filesystem Hierarchy Standard (FHS). This means you won't find familiar directories like /bin, /etc, or /usr in their usual places. Because of this, programs need to be adjusted and recompiled to work correctly in the Termux environment, or they won't be able to find their configuration files or other necessary data.

If you try to run scripts with standard shebangs (like #!/bin/sh), you might encounter issues. To fix this, you can use the termux-fix-shebang script to modify these files before running them. Alternatively, recent versions of Termux include a special package (termux-exec) that allows the use of standard shebangs.

Many packages also have dependencies on shared libraries, which Termux installs in $PREFIX/lib. On devices running Android versions before 7, Termux uses the $LD_LIBRARY_PATH variable to tell the linker where to find these shared library files. For Android 7 and higher, the DT_RUNPATH ELF header attribute is used instead of LD_LIBRARY_PATH.

If you really need a more traditional Linux file system layout for some reason, you can use the termux-chroot utility from the 'proot' package. This utility sets up a chroot environment that provides standard paths like /tmp, /etc, and /usr:

$ pkg install proot
$ termux-chroot
$ ls /usr
bin  doc  etc  include  lib  libexec  share  tmp  var

Using termux-chroot can be helpful if you're using custom software that requires these standard paths to be available.

Termux uses Bionic libc


Differences of Termux from Linux
Shell could seem to be stupid saying that file does not exist but you know it exists. However in this case shell is actually right. The dynamic linker is not available at standard path. Use strace to see what's going on.

To ensure our packages work well with Android and to avoid the need for custom toolchains, we compile everything using the Android NDK. The resulting binaries are linked against the Bionic libc (files like libc.so, libm.so, libdl.so from /system/lib or /system/lib64).

Due to the differences between Android's libc and the standard Linux libc, it's not possible to directly run native packages copied from Linux distributions:

1. Dynamically linked programs won't run because the linker is expected in a location that doesn't exist (/lib), and the libc Application Binary Interface (ABI) doesn't match.
2. Statically linked programs (only networking ones) won't be able to resolve DNS names because GNU libc doesn't normally allow static linking with the resolver. Additionally, the file /etc/resolv.conf, which is used for DNS resolution, doesn't exist on Android.
3. On non-rooted Android devices running version 8 or newer, statically linked programs won't run due to issues with the seccomp filter, a security feature.

To work around these restrictions, you can set up a Linux distribution root filesystem using PRoot, which allows you to run Linux binaries on Android.

Root file system is stored as ordinary application data

The root file system and user home directory in Termux are stored in a private application data directory on the /data partition. This directory is accessible through the $PREFIX and $HOME variables. It's crucial to note that you cannot move $PREFIX to another location because all programs expect it to remain unchanged. Additionally, you cannot store binaries, symlinks, or other files from $PREFIX on an sdcard due to the filesystem not supporting Unix permissions, symlinks, sockets, etc.

It's important to back up all important data before uninstalling the Termux application or wiping its data, as this will also remove the directories $PREFIX and $HOME, along with their contents.

Termux is single-user

Android applications, including Termux, are sandboxed and run with their own Linux user ID and SELinux label. In Termux, everything is executed with the same user ID as the Termux application itself, which typically looks like u0_a231 and cannot be changed.

To enhance security, all Termux packages (except root-only ones) are patched to drop any multiuser, setuid/setgid, and similar functionality. Additionally, default ports for server packages like ftpd, httpd, and sshd are changed to 8021, 8080, and 8022, respectively.

You have free read-write access to all application components, including $PREFIX. However, be cautious, as it's easy to accidentally delete or overwrite files in $PREFIX, which can lead to issues.

Conclusion

Termux provides a powerful environment on Android for running Linux packages and commands. While it mimics a Linux distribution in many ways, there are important differences to be aware of, such as its non-compliance with the Filesystem Hierarchy Standard. Understanding these distinctions and the limitations of Termux, such as its sandboxed nature and restrictions on file system access, is crucial for effective and safe use of the platform.

إرسال تعليق

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.