Linux Fu: The Linux Android Convergence

The Android phone that you carry in your pocket is basically a small computer running Linux. So why is it so hard to get to a usable Linux environment on your phone? If you could run Linux, you could turn your cell phone into an ultra-portable laptop replacement.

Of course, the obvious approach is just to root the phone and clean-slate install a Linux distribution on it. That’s pretty extreme and, honestly, you would probably lose a lot of phone function unless you go with a Linux-specific phone like the PinePhone. However, using an installer called AnLinux, along with a terminal program and a VNC client, you can get a workable setup without nuking your phone’s OS, or even having root access. Let’s see what we can do.

AnLinux

AnLinux takes advantage of the fact that Android is really Linux underneath. It lets you mount an image file that contains a root file system from any of several distributions including Ubuntu, Kali, Fedora, CentOS, OpenSuse, Arch, Alpine, and others. In addition to creating a script that does a chroot to “mount” the image, the installer also uses PRoot to simulate root access.

PRoot intercepts any calls you make that would normally require root access and makes them work in the current context. It uses the ptrace system call to effectively debug your software in order to do this. With PRoot, you can do things like a chroot without being root and PRoot also provides fake user permissions on your pseudo-file system.

AnLinux itself isn’t a big program. It installs operating system images and creates scripts that can start the environment for you. Then you’ve got a fake Linux computer running inside your Android phone while Android is still running. Simply connect to it from the outside Android OS using a terminal program or a VNC viewer, and you’re good to go.

Sounds kludgey, and it is, but it also works. Is it perfect? No. Some things need real root access to work. But it does work surprisingly well if you temper your expectations.

What You Need

Obviously, you are going to need an Android device. It must run at least Lollipop, but it can be a 32- or 64-bit Arm or x86 device. You’ll also need a lot of free storage for the disk image, so an SDCard or a big device is pretty important.

You’ll also need:

  • AnLinux (easy to install from Google Play)
  • Termux (also on Play)
  • VNC Client (I suggest VNC Viewer)
  • Bluetooth keyboard (optional)
  • Bluetooth mouse (optional)
  • HDMI output cable for your phone (optional)

Termux and VNC Client are all you really need to access the fake Linux box. The last three items are creature comforts.

You’ll probably be happier with an external keyboard, even if it is a tiny foldable one. Bluetooth keyboards are the simplest way to go, although you could probably also use a USB host cable and a hub to plug in USB devices, but that’s less portable and I haven’t actually tested that theory.

An HDMI output cable gets you connected to a big display if you aren’t happy with your device screen. Still, the VNC client can zoom in and out, so it is workable without an external screen. At the least, you should have a kickstand or holder to keep the phone upright.

About the only hitch I’ve found is that the cables for video output don’t charge my phone at the same time, leaving it running on batteries. This isn’t true of all phones and maybe even not of all cables, so you might want to check if you can charge at the same time for longer sessions.

Getting Started

Once you install Termux, you can use it to get a normal terminal into your Android device. You aren’t root — well, you could be if you rooted your device, but I’ll assume you haven’t. The next order of business is to install an image for a Linux distribution.

To do that, open AnLinux and select the Dashboard from the menu. There are three buttons, but you’ll only be able to press the first one. When you push that button you can select what distros you want to install. It is possible to install more than one, but you’ll need lots of storage and you’ll have to repeat the steps for each one you want to install.

Once you select your distro, the other two buttons will light up. The second button lets you load the clipboard with the commands needed to download and install the Linux system. That will typically be some pkg commands, some wget commands, and a shell script to execute.

The third button launches Termux so you can paste the commands in the terminal window. Once it completes, you’ll find a shell script that allows you to launch the distro environment. The install will be minimal to save space. There are similar button setup screens to enable an ssh server, and set up various desktop environments. Once you’ve done the install, you don’t have to repeat it. You can simply open Termux and run the shell script to launch your fake Linux system.

Get Graphical

If you want to run a graphical environment, you just have to select the menu for desktop environment and push more buttons. Your choices will vary based on the distribution you are using. For Ubuntu, for example, you can select Xfce4, Mate, LXQt, or LXDE. You can do a similar set of steps to pick your favorite window manager, for example, Awesome or IceWM.

To start, you’ll have to use the script that the installer leaves to launch the distro. Then there’s another script to start a VNC server. The names of the scripts depend on what you install, but the AnLinux installer will tell you what you need to know.

After launching the VNC server,  you connect your VNC viewer to the specified port the script mentions on the localhost address, and you’re inside the virtual Linux machine. Performance on my Pixel 2XL is really not bad, although it won’t replace my giant Linux desktop by any means.

Not a Toy

This might seem like a toy and, as I’ve said, it isn’t going to replace a real Linux box for most people. But sometimes you need to pull over on the side of the road and log into a server. Having a complete set of tools that you are used to can be helpful. Can you just install something like JuiceSSH and connect to the remote box directly? Of course. Or use VNC with a remote server. But if someone sends you an OpenOffice spreadsheet you need to look at on your phone and you want to use sshfs to mount your remote drive full of macros at the same time, this is the solution.

If you carry a small portable monitor, a keyboard, and a mouse, this could also stop you from having to lug around a laptop as much, too. Even more so when you are somewhere you can borrow all of those items. Sure it is a compromise, but it is workable and often better than having nothing with you.

63 thoughts on “Linux Fu: The Linux Android Convergence

  1. It certainly isn’t lost on me that my phone is a heck of a lot more computer than what I used to have on my desktop not that many years ago. And for sure, linux is corked up deep inside. All of this is interesting. My first objection is always the need for a keyboard, but I should perhaps try a bluetooth keyboard as you suggest.

    Then the question is — what can I do with it? Can I install ghc (the Haskell compiler) and work on learning Haskell while I am sitting at red lights in traffic? Even if I could (or would or should), it would be more of a parlor trick than anything really useful.

    1. There are lot of apps (think home automation, file server, media server, network gateways, hotspot) which do not require fast CPU and can run on old cell phone. Bonus is cellphones have battery so they can work even with flaky power or when power it out.

    2. If you have a real high end phone its more than capable of running pretty much anything a laptop can, some software still won’t exist for arm, the storage limits might make it impractical, but the hardware performance in those little gadgets is really quite stupid for the use they actually get..

      That said for me just carry a damn laptop/netbook and use that, its going to be a far better experience and yet more potent. (partly as I’m too cheap to spend enough of a high end phone with such locked down hardware and awkward awful ergonomics. The more open native linux capable phones are not that high spec and I won’t buy until I need to actually replace my current phone – and only after I’m 100% sure it will do the things I want.)

    3. “work on learning Haskell while I am sitting at red lights in traffic”

      Where I live, you are breaking the law if the driver uses their phone while your car is on the roadway, regardless of whether you are moving or not. And maybe the safety of those around you is more important than your urge to hack.

          1. Stop complaining while pretending to be against complaining.

            You’re NOT against complaining, you ARE complaining.

            Your feelings might have been hurt, but you had no cause. You were not wronged.

    4. Android works fine with USB keyboards and mice. Just grab on OTG adapter and maybe a passive hub and you’re all set.

      As for what you can do with it, almost anything you could do on a Linux laptop or a Raspberry Pi with a screen. Whether than includes anything useful is up to you, but I find it useful to be able to work on things when I’m not able to sit at my desk. Write documents, write and run code, whatever.

      1. So, I’ve been out of the Android loop for a while, in that I haven’t downloaded any apps to my phone in years, (yes, really!) but Android OpenOffice (or whatever it was) was useless on my phone back then. Is there now a decent working/useful version of an “open office software suite”? That isn’t Google spyware, I mean.

  2. A pity there’s not a framework out there to allow Android drivers to function in Linux. I’m no programmer… IDK what hurdles would be involved in that nor if it’s even realistically possible, but I know it would be useful and nice. IIRC Android is technically Linux (although admittedly not much more than “technically”), using a version of the kernel that’s been sat in that tub of goo at the end of the first Fallout game for a bit too long…

    IDK, maybe?

    I don’t even know what to call it, except that I’m enough of a nerd that it’d probably involve an extremely dark bit of Star Trek humor.

    1. No, your view of things is wrong — and/or you have never been inside of an Android phone. There is a full honest to goodness linux kernel running inside. Android is just “wrapped around it”. Even that isn’t very accurate, Android is just the only application that kernel is running that you have access to. As a normal user anyway.

      1. Not exactly true either, as much of the hardware relies on googles secret glue to make it work, so its not like you can just not run the android app and run something else instead as large amounts of functionality require the Android elements that are not part of the normal Linux Kernel..

        If it was that easy to have full fat system on a phone’s hardware it would be wonderful, but it isn’t that simple to take the ‘droid out. Which depending on your point of view/priorities makes both of you right and wrong simultaneously.

        1. Seems like that barring some proprietary kernel modules used as drivers, the problem is the people automatically assume the GNU parts of GNU/Linux (or SystemD parts of SystemD/Linux if nobody stops the affluent lunatic Lennart Poettering) to be automatically bundled in, when Google scraped that away as they deemed it unessesary.

          Although I don’t blame people for triggering Richard Stallman, because verbally naming that cocktail does make you look stupid compared to just saying Linux, but it does confuse some people in situations like this.

  3. “if someone sends you an OpenOffice spreadsheet you need to look at on your phone”

    There’s an app for that.

    “and you want to use sshfs to mount your remote drive full of macros”

    Why not just copy them onto your phone?

    Oh I get it, waste as much time as possible, get all involved in nerdy stuff and the original goal is just a pretense.

    1. Copies are bad – you will need sync them so every time you update one end all the devices keep up. Which is where just having them mountable from anywhere so you can use your environment and setup on anything in theory is nice.

      You also might not want to use ‘the app’ for that (if it exists, which isn’t a given either).. You can be reasonably sure installing from Debian’s package library or from source that openoffice really is just that.. on the app stores… much less so.

      So having the ‘real’ linux experience available even through such awkward means might be worth it. Same reason I have a KVM GPU passthrough VM for those games that just must have windon’t (often for anticheat bollocks reasons) – its awkward sure, but better than a dedicated device I’d almost never use, and keeps everything else I do in the software I’d prefer.

      1. “Copies are bad – you will need sync them so every time you update one end all the devices keep up. ”

        But we are looking at spreadsheets that someone else sent to us (remember the premise here) so you are already working from a copy, and the “someone else” who wrote the spreadsheet will also need a copy of those macros. And there are other ways to sync files on an android device, you don’t need to install linux for that

        “You also might not want to use ‘the app’ for that (if it exists, which isn’t a given either)..”

        Yeah just because it’s in the android app store, and it has 300000 downloads, that does not mean that it actually exists

        1. As JM tried to point out the macro’s have nothing to do with the file – they are your personal productivity boosters, that define how you can interact with the file in the program you like – for example you might have a macro set that types in the unicode for ‘words’ you use often but that don’t exist on your keyboard( not in your native language’s character set, those pictogram like smiley faces etc).

          You really don’t want to have lots of duplicates of that floating around as on the device you don’t commonly use it is always going to be out of date and therefore rather less useful, maybe even an annoyance not a help at all.

          In this set up you want both the familiar program (likely not on the app stores or massively garbled by being the ‘phone’ version) and your personal user defined productivity aids. So want the proper full fat linux and experience of the laptop/desktop.

        1. I mean, even the ability to open a .pdf.
          I mean, being able to make a (small) entry to a spreadsheet, as in updating my gasoline (petrol -Jenny)
          purchases (date, mileage, #gallons, price/gallon, Station identifier)

      1. Theres no way to do serious spreadsheet work or even document editing on phone its too small, two monitors setup is small when you do financial controlling for bigger company (like min 1,5k employes). Fast look up or adding few lines is fine but anything more with pivot tables and swometimes complicated scripts (we all know how exporting data between different programs written in different decades work).

  4. The only need I still have for an actual laptop is running CAD and CAM software.

    Until someone designs a phone with mobile design software fully featured in mind, which I’d desperately love, I still need a laptop.

    Its interesting to know this can be done though.

  5. If you are using Termux what’s the point of AnLinux? Termux already has it’s own desktop-linux-like file tree, a package manager and repos. You have to take an extra step to enable the X-based repos if you want access to GUI applications but you can. I haven’t installed much more than SSH on mine though so maybe there is a reason that using AnLinux is better?

    The real problem with any of these solutions is that Google has “oh so helpfully” made Android mount the SD card with the NoExec flag and gave us no way to change this short of rooting. I suppose that makes the typical appliance user a little safer but for those of us who would like to run Linux applications mobile it means everything has to go on the phone’s main internal storage where installing too much will bog down our devices. Thanks a lot jerks at Google!

    That’s why I hesitate to install much in Termux and also why I am suspicious of the idea of installing both Termux and AnLinux. Then you get two extra file trees taking up main storage!

    “Can you just install something like JuiceSSH and connect to the remote box directly?”

    Meh. That used to be my method. I’ve been playing with Dex and have found that JuiceSSH has an intolerably small font on a Dex screen and I haven’t found any way to fix it. Thus my own switch to Termux.

  6. Old phones have become a great foundation to run projects on. They already have a screen and audio, which is a plus. Slap a kydb and mouse on it…Bob’s your uncle.

    I’ve been using Termux for a while now and it has proven to be very useful. You can run services on it (lighttp, sshd, gopher, etc) and be able to get at your chosen resources easily. I have even set up an older phone as a sort of public read only share node (see also anyfesto ) .

    I ve also had some time to muck with setting up a stable tor server on one with the services above exposed as hidden services. This has proven to be useful.

    Using an older device as a dev platform is also more doable as the “old” devices get more power under the hood. PHONK is an interesting take on this as is running you dev environ of choice under Termux.

    And that is just with Termux. With a full rootable linux install the possibilities expand. Anlinux seems worth a good long look.

    1. I use an old phone (weak battery, Android 6.something) as an Internet radio at home.
      Plugged into a wall wart, it picks up the Wi-Fi signal and plays the audio. It is working well enough to delay making a dedicated Pi/Android Internet radio.

    1. Yes. but with some caveat, like how old is your tv box. android <5.0 is no go
      and what is your use case, therefore CPU ram and rom requirement.

      If supported, it is much better running armbian than Anlinux/userland. since there will be no android overhead.

  7. This definitely jumped out at me. I’ve been wanting a workable and desktop-like experience on my phone. As others have pointed out, the amount of compute power in phones these days isn’t something to ignore and is mostly poorly utilized with most apps but thats a whole other can of worms.
    Termux is a great tool when you just need some CLI utilities on the go.
    For me, this caught my eye because my poor thinkpad had an unfortunate run in with a cup of coffee and now I’m stuck with an android tablet propped up in front of a bluetooth keyboard. Does it work? Yes, mostly, but its nowhere near as comfy as my trusty linux setup.

  8. I find UserLand much easier to use than Anlinux. I installed it on my son’s 10.1-inch android tablet. After installing LXDE, pairing it with a bluetooth keyboard and mouse, and making it fullscreen, it looks and works like a full linux desktop because it is. Performance is faster than my old 2.7GHz AMD 10GB RAM laptop, though the tablet only has 4GB of RAM. The latest LibreOffice is available and my 8-year-old son uses the tablet to learn python. Casting the screen to a miracast-capable TV would make you forget that this all runs from an android tablet.

    1. Agreed, UserLand is much easier IMO. Have been using them for sometime now.
      Having a desktop sofwares on mobile devices sure is convenient.

      If only all of the major device and software makers could collaborate on this, our android phone probably would become laptop/desktop replacements(for many use case), instead of proprietary crap like Samsung DEX.

  9. I have spent quite some time experimenting with Termux and UserLAnd. The problem is, that Google and the OEMs not only do not help to make these linux emulation packages viable, but it actively makes it more difficult by tightening the screws of process separation and security. I believe this is the reason why Samsung had to kill its Linux on DeX. It was not their decision. If the project was actively boycotted by Google, they had no other chance. Also the Android power management kicks in to slow down the Linux applications to a crawl.

    Rooting is IMHO a waste of time, one never knows what will break and the process is different for each phone device, manufacturer and system version. One is better off buying a Raspberry PI.

    A non-rooted phone is limited to proot, which is quite slow and provides incomplete emulation of chroot. Termux provides lesser chroot emulation through proot, thus it is faster, but not everything works as expected. Namely I found the GUI applications difficult. UserLAnd on the other side has a more complete chroot emulation, however that makes it slower.

    Now Android 10 API makes Linux emulation very difficult:
    > Untrusted apps that target Android 10 cannot invoke exec() on files within the app’s home directory. This execution of files from the writable app home directory is a W^X violation. Apps should load only the binary code that’s embedded within an app’s APK file.
    https://github.com/termux/termux-packages/wiki/Termux-and-Android-10

    I think that kills UserLAnd in the long term, while the Termux will likely survive, however only providing command line utilities.

    I really admire the effort of https://termux.com/ developers. It is really a three man show. These guys are putting a great effort in the project and we should support them.
    https://www.patreon.com/termux

    Android devices are cheap and ubiquitous, however the learning curve to start with the simplest application is steep even for a seasoned developer with all the GUI requirements, power management and security features the developer has to be aware of. The Termux has a chance to allow one to prototype simple command line applications for the Android environment, which I find great.

  10. This is pretty neat! I’ll have to play around with AnLinux.

    If you’re interested in this type of setup, you can also check out Maru OS for a full-fledged Linux desktop experience in on Android. Maru lets you interact with Linux on your external display while at the same time interacting with Android on your mobile screen—they are truly independent so you can, for example, watch a video on your phone while browsing the web in Linux on your external display. In addition, you have full root access, systemd is running, and all the goodies you’d expect to work… mostly work! We’re open-source so you can even hack on the project yourself. More details here: https://maruos.com/

    P.S. I am the creator :)

  11. “If you could run Linux, you could turn your cell phone into an ultra-portable laptop replacement.”

    Wrong. Ubuntu tried for years to achieve “convergence” with its “Unity” GUI, and it was a disaster. In the end Ubuntu had to abandon Unity. It’s not what the OS is (Linux or otherwise), it’s the GUI and form-factor that prevents “convergence” from happening. A small touch screen and no keyboard is a very different physical device compared with a large screen plus keyboard plus pointing device like you get with a laptop or desktop. Trying to make the two “converge” is like trying to put a square peg into a round hole. Yet the (failed) obsession with “convergence” still lives. Just look at this article.

  12. “The Android phone that you carry in your pocket is basically a small computer running Linux” Well yes, since the begining…

    Also Linux in my pocket, my still working Nokia 770 says Hi….

  13. So, in other words,
    We shouldn’t be looking for ways to put Linux on our Android phones,
    but instead, looking for ways to lop Android off of the top of the Linux that is already there!
    B^)

    1. I’d say it’s less of beheading Android, and more of lobotomizing it tactically so it isn’t limiting pro users by smothering them to death in the name of security for the borderline technically inept.

  14. If you can, ” run Linux, you could turn your cell phone into an ultra-portable laptop replacement.”

    Then why can’t you turn your computer into as cell phone replacement?

    I’ve long wondered why we can’t use a desktop, or laptop computer to use as a phone — make calls and text messages.

    From a technology point of view, should just be a bit of hardware — an appropriate radio , and drivers. Some open source software to manage contacts and history etc., And yeah some kindof contractual agreements with the phone companies. Way beyond my ken.

    Why oh why is this not doable?

    Jim

    1. jim, it’s kind-of-sort-of possible. Some modem dongles have phone/voice capability, or can accept a firmware update to allow it. Unfortunately I think this is discouraged by the hardware manufacturers and networks, because that way we wouldn’t have to double up on hardware, or on data plans.

      As an aside, does anyone else remember the free internet to SMS that were available in the early 2000s? There was one built in to ICQ, but it got shut down by (in my country) Telstra, who were pissed off that peolle could send SMS without giving them 20c per message. Note that the SMS protocol originally piggybacked on GSM control codes, so it actually cost the networks nothing to implement. Kind of like a clever hack which they then brutally monetised :-)

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.