[TUTORIAL] Running Linux on your Android Device
Wandering around the vast landscape of the nerdelicious stuff you can do with your Android phone, I stumbled upon this guy: Dave Bennett. Dave is a prominent YouTuber (and all-around nice guy) who does a host of interesting things on his smartphones and Android wear devices. If you visit his channel, you’ll find a metric ton of good stuff, so be sure to do so. But one of his videos particularly piqued my interest – his tutorial on running Linux on Android. So having tried this for myself, I must say this opens up a whole new dimension of functionality and versatility you can achieve on your Android phone.
So some of you must be wondering “why on Earth would anyone want to do this?” Well, easy answer would be “because you can.” But the implications of such an ability are quite far-reaching as I will discuss later on in this article (jump ahead to the conclusion if you wanna know right away,) for now let’s dive right into how you can do this on your own device.
Keep in mind that you will need a rooted phone or tablet to do this, but since you’re here, chances are your device is already rooted.
Step 1 – Preparation and Downloading apps:
I recommend starting with at least 50% or higher charge remaining on your battery since going into power-saver mode will drastically degrade emulator performance and lead to problems during installation. Another thing to note is that the process takes quite a bit of downloading from the respective repositories, so you’ll want to make sure that you’re connected to a WiFi network. You’ll also need to have at least 4GB of free space in your phone’s internal memory, since that’s the amount of space that Linux Deploy will put aside for the virtual drive that it will install Linux into.
Finally, while this is not absolutely necessary, it’s a good idea to be equipped with a Bluetooth/USB OTG keyboard and mouse. And if you’re going to be doing this on a phone or a smaller tablet, it would be a good idea to invest in a Chromecast or use MHL to connect to a larger display since the desktop environment is a bit difficult to use on a small display.
All that out of the way, let’s begin.
Start by downloading these three apps from the Play Store:
- Linux Deploy by meefik
- VNC Viewer by RealVNC Limited
- Terminal Emulator by Jack Palevich (just in case)
Step 2 – Setting up the Linux emulation server:
Launch the Linux Deploy app.
You’ll be met with a terminal like UI that looks like the image below. You’ll also notice a persistent notification with the cutesy, albeit slightly confused-looking, Linux penguin icon saying “Linux Deploy | Current profile: Linux” – this means that the app will continue running in the background with whatever it is currently emulating until you exit manually.
Begin by pressing the “download” button marked in the following image:
This will take you to the Properties menu (as shown in the images below.) Here, you’ll have to change a few parameters and make a couple of selections to set your Linux desktop up the way you like it. For the purposes of this exercise, I’ll be showing you how to install a build of Ubuntu with the LXDE desktop UI, but there are a number of different distros and desktop environments that’ll work smoothly in Android, so feel free to try your personal favorite later.
At some point during the following, Linux Deploy will ask you for Super User access, be sure to grant it.
For now, tap the “Distribution” setting and select “Ubuntu”.
Under “Distribution suite” select “trusty”.
Depending on your device, select the select the correct “Architecture” setting for your device; as a general rule, most high-end Android phones will use “armhf” for high-frequency ARM-based SoCs. If you’re using, for example, a device with a Snapdragon 810, you’ll need to select arm64, so keep that in mind.
Next, scroll down to find “Desktop environment”, for this setting select “LXDE”.
Finally (only if you’re on a phone or a small tablet) scroll down further and find the “GUI settings” sub-menu and tap it; in the subsequent menu, swap the “height” and “width” values to force landscape mode (by default, the resolution will set itself to your phone’s default orientation). Go back to the “Properties: Linux” menu when you’re done.
Leave the rest of the settings as they are for now. You can gain more fine control over how the Linux environment operates by tweaking some of these settings; most of them, I couldn’t make heads or tails of to be honest… So…
Anyway, now that everything is configured, scroll back to the top of the Properties menu and click “Install”. Grab a cup of coffee and sit back… This is gonna take a while! You’ll know you’re done when you see “[##: ##: ##] <<< end: install” in the terminal window like the image below.
Now, admittedly this process is rather finicky and can be quite troublesome (especially in Android 5.0 onwards); should you run into problems during this part of the guide, there is a troubleshooting section in the later part of this article that might help you. Some errors are common in Android 5.1.1, so don’t fret if you get held up…
If installation went without a hitch however, click “START” to load the Linux emulation into your physical memory. If there are no errors up to the “<<<<end: start” prompt, you’re good to go.
Step 3 – Connecting to the Emulated Desktop:
Start the VNC Viewer app. (It’s okay to leave the Linux Deploy app running in the background; even if you remove it from recents, it will remain running in the background until you exit manually from within the app itself.)
From here on in, the process is pretty simple…
Click the “+” button at the bottom left of the screen.
In the following prompt, under address type “localhost:5900″ (take care not to inadvertently add a space after the port number, it’ll screw things up.) Under name type anything you like, I went with “Linux”, because… reasons. Check “Save Password” if you don’t want to have to enter a password every time you enter the Linux desktop environment.
A VNC viewer profile is now created to access the Linux environment that you had created in Step 2. To connect, tap… well… “Connect”.
A prompt will appear asking for a password – the default password is “changeme”. Enter the password and Voilà! There you have it – your very own, full-blown, no compromises build of Linux running on your Android device! If everything went according to plan, you should see something like this:
If you don’t, don’t worry… Just refer to the following section for troubleshooting.
So you’re getting errors? It’s probably not you who f**ked up… Like I mentioned earlier, the whole process is a bit finicky and can often take a bit of shaking and rattling before everything works as its supposed to. I spent a good couple of hours troubleshooting during my attempts, and based on those experiences here is what I’ve learned:
- Errors during Linux installation or installation is failing due to too many errors in Linux Deploy:
Super User access granted to the app when requested? Try going to your root manager app/setting to verify this. Linux Deploy uses a BusyBox plug-in to temporarily turn SELinux Enforcing mode to “Permissive” temporarily while it’s working, which it cannot do without root access.
- Exit the app (press the three-dot button at the bottom right corner and select “Exit”) and reboot your device.
- Linux Deploy crashes while downloading/installing/compiling the desktop environment:
- Try selecting a different desktop environment.
- Exit the app and reboot the device.
- Go to your device’s recovery and clear Cache and Dalvik cache.
- Everything goes fine then this shows up, “E: Couldn’t fine these debs: 0″ followed by the installation ending abruptly:
- This appears to be a common problem with Linux Deploy mostly on Android 5.1.1 ROMs. The solution is simple, exit the app and open Terminal Emulator. In the terminal prompt, enter the following: “su” Tap Enter, grant Super User access if requested; then type (or copy/paste) “chmod 755 /data/data/ru.meefik.linuxdeploy/linux/deploy/debootstrap/pkgdetails”
- Try a different distro of Linux (Debian/Ubuntu/etc.)
- Everything installed okay, but when I try to connect via VNC Viewer, it says “Error: An invalid IP address… …supplied”:
- Recheck the spelling in the “localhost:5900″ part and make sure there aren’t any spaces within or after the text.
- Connecting via VNC Viewer just takes me to a grey/checkered image, or entering any window in the desktop environment leads to a similar situation:
- The Linux installation may have failed at some point, but installation continued nevertheless. Look over the installation logs in Linux Deploy for errors, or reinstall the Linux build after a fresh reboot of your device.
- Try a different desktop environment. Not all distro-environment combinations will work for all devices under all circumstances. For example, I could not get Ubuntu and KDE to work together on my OnePlus One running Exodus 5.1.1.
If you run into any errors apart from the ones mentioned above, leave a comment below or contact AndroidScout via e-mail and we’ll try to help you out in any way we can.
Performance, Profiles and Configuration
On my OnePlus One (running Dirty Unicorns and Exodus), the performance was generally acceptable, but it won’t be the same as running Linux natively on an x86 system. One word of warning though: since Linux runs on an emulation layer on top of Android (at least using this method anyway) which means it is quite demanding on resources and, as such, will require that your phone be up to the task. If the desktop UI runs smoothly enough, your device should be theoretically capable of handling most Linux-compatible apps and games as well. If you face performance issues, try tweaking the settings in the Properties menu in Linux deploy. When you’ve set a configuration you like, simply tap the “Reconfigure” option.
Unless you change the distro/build/desktop environment, you shouldn’t have to re-download and re-install anything. Changing most parameters will just see the app scroll through another couple of lines in the terminal window before proceeding to give you the “go ahead.” If you’ve built a configuration that you’re happy with, click the Linux [<your IP address here>] text to enter the profiles menu; here you can add more profiles and edit the ones you’ve already built.
So you spent the better part of your evening fiddling with these two not-very-easy-to-use apps, troubleshooting problems that reminded you of dealing with Windows ’98, all to run Linux on your Android device – which is only practical if you have a large enough display, a keyboard and a mouse at hand. What gives?
Well for one if you’re using a latest generation “flagship” Android smartphone or tablet you could, in theory, minimize your carry-around to just your portable device, a Chromecast and a portable Bluetooth keyboard with a touchpad, instead of a laptop and all that comes with it. That is, provided you have access to a device with HDMI/MHL and have adjusted to a Linux workflow… Which… Okay, so that doesn’t really work for most people.
But let’s approach this from a different angle: a theoretical standpoint rather than a practical one. It makes more sense to see this as a foreshadowing of the future of portable devices and opensource software. A rather predictable inevitability is the minimization of scale – soon your “desktop” will be a flat piece of glass against the wall, your “laptop” will be a sheet of paper you can fold or roll up and carry in your back pocket. And your smartphone will be the “data monolith” – the one thin, beautiful, iconic slab with all the processing power you’ll ever need, every-which sensor and input method, all the data capturing equipment you need, and of course, your portal of telecommunication. Oh. Wait…
I guess you can see where this is going: with the exponential growth of performance, battery life and the miniaturization of sensors, radios and other components, it’s not an absurd concept that your smartphone could ultimately replace your desktop/laptop. And this personal supercomputer of yours will be built on the same principles that have led to the success of the current generation of smartphones: the human-machine interface.
This is where the “Linux on Android” bit ties in to this little flight of fancy of mine. Let’s face it… With high-quality, high-bandwidth WiDi on the horizon already, a wide array gesture-based input devices in the works, and better battery tech incoming, it’s only a matter of time before the bottlenecks are dealt with. So early adopters of desktop environments on mobile can get a taste of what’s to come, and just maybe innovate for themselves… Linux and Android are, after all, both opensource.