Android Phone as Server

Why am I showing you a picture of a cracked-screen phone?

Linux on Android PhoneWell because this particular phone is a bust Oukitel K10000, the phone with the world’s longest-lasting battery and an excellent workhorse. My friend Aidan gave me this (rather than chucking it away) some time ago and it has been sitting doing nothing. All that is wrong with it is a cracked (and exceedingly dangerous on the fingers) screen. I’ll bet I’m not the only one with such a phone lying around wasting space.

Well, as of yesterday, it is a Debian server with all my usual stuff going on quietly in the background – with the screen normally off – running freezing cold and hopefully being super reliable.

This is an experiment only – beware – if your phone or tablet dies it is your problem….  oh and your Android phone/tablet needs to be ROOTED. 

Imagine turning your old, dust-covered phone into a sleek, battery backed-up server with unfeasibly long backup time, immunity to any mains spikes, a silent, fast Debian base for all the stuff in my script – which includes Node-Red, Apache/PHP, SQLITE (+ PHPLiteAdmin), MQTT, MC, Ha-Bridge and more!  If you’ve been following this blog you’ll know about the script.

So this article applies to ROOTED Android phones and we’ve only tested around Android 5.0 onwards.  In my case I rooted the phone with KingRoot (note, NOT the one in the PlayStore which is a con – avoid it – but the one at kingroot.net ) – please note that rooting phones is beyond the scope of this article and if you are not confortable with this you should not do it. There are a lot of links out there on the subject and many of them are fraudulent.

tmpCD52There is an APP in the Play Store called Linux Deploy. It is also on GitHub. Beware that this is essentially undocumented unless you are Russian – so please don’t ask how you can use your phone’s GPS or Sound from Debian – not a clue!

You should have a modern-ish WiFi enabled (or hardwired if you like) Android phone or tablet with at least 16GB of internal FLASH (which should give you 10GB working space).   If you only have 8GB that will leave you only 2GB which – really – isn’t enough.

Getting Debian 8 on the phone:  After ensuring your phone/tablet is rooted, Install the App.

Linux on Android PhoneIn the app, on the top LEFT menu – find  REPOSITORIES and select Debian 8 for ARM.

On the bottom right is a drop down – you should go in there and select INSTALLATION TYPE – directory (OR FILE with a reasonable file size limit – say 5GB – the 2GB default will NOT work). Change the user to “pi” with suitable password in the same menu. TICK for allowing initialisation – and use of SSH server. Also where you see INIT SYSTEM change that to sysv. 

Then TOP RIGHT menu  – INSTALL – that might take some time – top right again CONFIGURE – then bottom menu START – and you should have a working Linux you can get into with for example WINSCP for that “pi” user. The IP address is clearly shown in the App.

I suggest not going further until you are comfortable with the above – took me several attempts because I didn’t follow the above exactly (well, and Antonio and I were learning at the same time).

Running the script: Via WinSCP or similar, put the script into the pi directory – changing permissions as normal – run the script – and ensure PHONE is selected – it isn’t by default. Come back after lunch. The script will no doubt suggest a reboot. Instead, hit the STOP button on the bottom of the phone screen – wait for it complete, hit the START button – wait – and you should now have everything in the script running!

Now – I’m using this to run my script – but I’m thinking you COULD use it to serve files etc. – I’ve not tried this but I’m guessing it would be easy to access an SD card…. and make that a folder…. hmmm.

Anyway, it is now the day after I installed all this – the phone is sitting there “off” and unlike my FriendlyArm board with it’s whirling fan, is sitting silently and freezing cold yet ran the script much faster than any of my SBCs – around 40 minutes.

K10000 running Debian 8No guarantees as there just isn’t enough info about Linux Deploy out there (unless you find/translate some) – but it does seem to work well now that we’ve made sufficient alterations to the script to take this particular setup into account. A fun project, to be sure. Now, I know this is a not a fair comparison and tomorrow we might come back and say … no good (for whatever reason).. but at £107 for that particular phone… compare – how much would it costs for a Raspberry Pi 3, uninterruptable power supply able to keep the phone going for something like a couple of days with no power, a high-def touch screen, a solid case for the whole thing.. indeed ,it might be possible to use a cheap tablet…  I was looking on Ebay – 16GB Android tablet – perfectly working except for missing buttons and cracked digitiser – around £10

One thing to note – I’ve turned rsyslog messages off – it was spitting out all sorts of unwanted helpful messages when you changed brilliance on the phone or disconnected the USB etc –REALLY annoying.. If you feel you need logging on –

sudo service rsyslog start

That will stay on until the next stop-start…

Node-Red running on a K10000 phoneSuch a shame it isn’t clear how to access some of the peripherals like audio. But who knows – someone reading this article may already have solved such challenges.

Please note: the pretty colours on the right do not come as standard. Click images to see larger versions.

This is really starting to look GOOD!!!!

Revelation: I’ve now taken on-board ideas from others and thanks for that – both people in here and on Google+ – most of the other solutions are longwinded and need other packaged  so up to now Linux Deploy – I’m now installing on my old Nexus 7 2012 UTTERLY SUCCESSFULLY (though not the fastest kid on the block) ( after rooting it with the Nexus toolkit ) – using Linux Deploy (which is completely self-contained and offers full root access – is looking the best). The ONLY thing you can’t do is use the Android peripherals – because of lack of UK info but this morning I figured it all out. 

We’ve also tested this one OnePlus One (model BACON) and a Xiaomi Redmi 3 model IDO). The K10000 has now been up for several days.

Ok, bear with me – you have Node-Red on Linux – and MQTT. So, you run Tasker on the phone (in the Android section) with MQTT – and now you have access to and control of all of the Android facilities that TASKER can handle (i.e. just about the lot) from within the Debian environment. Doddle.. now all I need is some time!!

Facebooktwitterpinterestlinkedin

74 thoughts on “Android Phone as Server

  1. just tried to delete completely data of linux deploy on second phone, then redownloaded the jessie arm image with no problems… don’t know what it can be… it’s a problem that you cannot add custom images to it, or even restore easily an export… we need a good backup plan, to restore via ssh…

  2. Thanks to xda forums I got it fully rooted by flashng the chainfire autoroot but still I can’t get Linux deploy to work, Ill keep trying over the next few days but it just doesn’t seem to download anything.

  3. I’m having similar problems, it doesn’t appear to download Jessie, there’s no indication that anything downloads at all and root checker says I have root access but no superuser apps installed, I assume I need superuser ? I ran kingroot.

    1. I’m hoping someone has an answer for this as I can’t verify an issue – on both my Nexus 7 and my K10000 the installation of Jessie went smoothly.

    1. mmm, that’s ok, then… sorry, don’t know what it can be… maybe selinux enforced, but you need an app to “relax” it, and then some other app can refuse to start, as bank ones… try keeping pressed linuxdeploy, drag in INFO (it should pop up on top), then memory, and delete everything about it, not only cache, then restart downloading jessie…

  4. Sorry – all new to me. Root checker app shows. Not sure what else I need to do to grant Linux Deploy any more rights than it has no (i.e. superuser)

  5. When starting the install I see a message that says Linux Deploy has been granted root access – is this what you mean? I got a pop up when I first ran it asking to grant root and I clicked Grant.

  6. Sadly I have tried a couple of times to install using Linux Deploy. I’m using a rooted (confirmed with Root Checker) Samsung galaxy S5 on Android 6.0.1

    I have followed Pete’s instructions but when I click on Install I get ‘>>> deploy’ and then immediately ‘<<< deploy' displayed on the screen. Linux Deploy status looks like the attached.

    Any help/suggestions would be most gratefully received.

    1. Are You starting with Meefik’s busybox instalation – before LinuxDeploy?
      If so – not every type of LinuxDeploy installation works well: try image, partition, etc…

  7. The K1000 is happily running the various servers and (via MQTT) running the doorbell and various speech… been on battery for WELL over 3 days now and still at 70% – I never thought in a million years it might be good for well over a week without power.

  8. LinuxDeploy is some form of chroot – you cannot (simply) use modules (for example i2c-dev, ad-hoc network) which was not compiled and installed in main, Android kernel. One of the big problems of LD is loosing Your linux container/image/configuration when LD version update was made. I am using LD on couple broken Allwinner A23, A33 processor based cheap tablets which have an Android installed native with full of spy/malware. I has also have trouble with KingoRoot. After rooting, KR was installing own, unwanted energy saver and turns off wifi (and connection to guest linux) by default.

    1. No it isn’t a good way – go to those pages and you see link that then threaten you if you don’t pay up. I’m trying to kill anything off from Hackaday – avoid.

        1. I didn’t hang around to find out – I went to the link which WAS in here (I’ve deleted it and replaced with the word HACKADAY) – I noticed the article in here and I remember feeling quite nice about that when all of a sudden another page popped up – and before I knew it another with a warning that the PC is being hacked and you have to pay this amount – etc etc etc… I and of course the pages would not close (I’d re-introduce the death penalty JUST for people who do things like that) and I opened task manager and killed the browser… So I can’t give you a precise definition but for the safety of others in here I thought it prudent to remove the link – there were various attempts at putting trackbacks in here to the same link – I blocked those too.

          1. Yikes. I’m at a loss to explain what happened to you. I visit Hackaday every day and have never had anything like that happen. I guess the Hackaday site could have been temporarily infected with malware. Some times malware infects an ad partner that a site uses. Well, sorry for the alarming crap you endured. I 100% support you removing the link. It’s a shame because the article and most of the comments were quite flattering.

  9. Having a bunch of useless Nexus 7(2012) sitting around, this was a real inspiration. Nexus Root Toolkit and LinuxDeploy worked perfectly. Two things that anybody else doing this may want to watch out for.
    1) When I tried the FILE option for the Debian install even though I set it to 5GB it crashed both times I tried it, seemingly having run out of space. If the script stops working at the point of the Mosquitto install you probably have the same issue. Directory install worked fine.
    2) If you use the MQTT client Tasker plugin be aware that there are two identical looking apps on the play store with very similar logos and from the same author. However one is stand alone and not a Tasker plugin. Install the wrong one and you will be baffled why Tasker will not recognise it.

    1. Absolutely Steve and I think I mentioned about the DIRECTORY option. Also yes sadly there is an old version of of the MQTT client software – you do need the one that says Tasker Plugin.

      Beware – the Nexus 7 (2012) is SLOW – many times slower for example than my K10000 phone which has had the same treatment.

      If you have these machines lying around – great – but if you have the option to use something a little more modern, maybe a relatively new screen-challenged (broken) phone or tablet – then I recommend that. I currently have a doorbell (mp3) and speech running on the phone without issue.

      1. I can’t say that I am stress testing the Nexus 7 but starting with a completely fresh android install, I have to say that I am pleasantly surprised with the speed of the Debian side at least. Runs a range of node-red based monitoring and reporting with no noticeable delay. On the android side it is still painfully slow at times but no worse than before.

    1. Thanks for that Leo – I use TightVNC all the time and have various packages on Android as well as the PC (WinSCP).

      1. Thought so, but tried.
        Btw I am interesting in your doorbell results. It is high on my pointlist as the commercial thing is annoying me with false events and unsolicited refusals to warn.
        Also btw Andreas Spiess did some advertising for you in one his latest videos!

  10. Thinking of just buying a new low end tablet and trying this. USD75 for 8″ no name android tablet. What specs make such tablets appropriate?
    Love your projects!

      1. I could be miles out here – but you need to check if you can root Android 6. Sometimes you see comments about people going backwards to 5.11 and in both my cases the phone and tablet were on 5.1 or thereabouts – so do your homework. 16GB is just fine.

        Put it this way, if it works on a Nexus 7 2012 it should work on more modern tablets as that was a particularly slow tablet.

        1. my OnePlus One is on Lineage OS 7.1.1, root is not a problem of android version but of device itself… so, before buying, go to XDA forums and look if what you’re going to buy has root, and, better, if it’s supported by some version of Lineage OS (ex CyanogenMOD): getting rid of all the crapware the producer put in, is always a good thing…

          1. Thank you for the input. I picked one up last night for Netflix and Hulu in my hotel. Naturally I tried to root it immediately.
            With no experience until last night, I was not surprised I failed.
            I found a video that I followed to get into developer mode etc but ran into trouble deciding what to use once I reached the XDA download page. Did a factory reset when my choice failed.
            Try try again tonight perhaps!

  11. So- right now after discovering a missing quote on the script (now fixed if anyone is struggling with an error right at the start) I’ve now started my Nexus 7 (2012 original WIFI – just rooted with the Nexus root kit – doddle) installing the script having put Linux-Deploy on it – again – a very straightforward install – this one will take longer than the K10000 – I suspect a lot longer – but up to now all is going smoothly. Got guests so it may be a day or so before I can comment further.

    But a challenge – in the event the battery went flat in one of these – what would be the best way to detect this – and make the phone/tablet turn on once charged (they don’t automatically) – once on, Linux-Deploy will sort out starting the setup no problem but the issue is getting the phone to turn back on… I just don’t see this happening in software…. I may be wrong – I hope I am. Thoughts?

  12. Pete, I did a similar thing. I have a cabin in the woods with mains power but no wired internet. I repurposed an old broken-screen phone to link via GSM to the net and act as router/hotspot. Its running Debian. All sonoff units reported to the MQTT server via this old phone. Plus the built-in camera gave me remote visuals. BUT a 3 day power outage drained the battery and the phone doesn’t auto-boot when the power is restored.

    I’m in the process of switching to an orange pi instead.

    Any comments on auto-boot of phone/tablet-as-server?

    1. No Pat and I REALLY would like to hear from anyone (as would you) who has tackled and won this particular challenge. So Linux Deploy will start up from scratch but not if the phone/tablet doesn’t turn on!

      Ok guys – how do we do this – ensure that no matter what, the Android system starts up when power is restored… I don’t ever remember seeing this tackled.. Of course – a transistor across the off switch and a simple circuit (esp8266 which could also measure voltage) would do it – but it would be better not to have to mess with the hardware.

    1. Aside from the need for Root – all of these solutions appear to involve two or more separate packages – you don’t have to go looking for anything – and that’s a big plus. I look forward to seeing the experience of others but I’m now onto my second unit using Linux Deploy… everything is in the one package – download, select operation system, adjust a few simple settings – go and it survives loss of Internet etc…

      My second unit – is the original Nexus 7. I was surprised how easy it was to root using the Nexus root kit and once done, no annoying ads like some other systems. I end up with a Debian system with plenty of Flash and RAM – and up to now (not finished installing) seems to run pretty well for an old and otherwise useless tablet.

      As it is a nice thin model – I could see this sitting on a wall as a server while also displaying useful info and controls, possibly with Chrome on the Android side running in some kind of kiosk mode – displaying Node-Red Dashboard. Too soon to tell how well that will work for now.

    1. But from what I can see GNUroot is not a proper Linux setup – despite the name, the description suggests it is more limited.

      1. On the other hand – nothing to lose by trying it – I have an unrooted original Nexus 7 in really good condition that is sitting doing nothing – if I can get it to boot into Debian with MOST privilages – enough to install my stuff and run root commands for file access etc.. then I might be happy to make use of that. I notice there is a GNURoot Debian…. I wonder if it is up to date…

    2. Ok, so someone please enlighten me… I have a Nexus 7 tablet (the original) – and I grabbed gnuroot – fine – it installed and I’m sitting as root in a nice Debian environment. Looks lovely.

      But it isn’t Debian as I’m used to it. ifconfig isn’t there, sudo isn’t there, sudo can’t be installed…. not a good start… once I install pi user, the very first thing I’ll need is sudo…

      Ideas?

      1. Shame your Nexus 7 isn’t the 2013 WiFi version because there’s an alternative to this android sideload method and perhaps more importantly, it’s a supported linux O/S from Canonical: Ubuntu Touch.

        The Nexus 7 2013 WiFi tablet is one of the devices Canonical build an official image for and it’s one of their supported reference devices:

        https://developer.ubuntu.com/en/phone/devices/devices/

        If this seems like an attractive alternative, the Nexus 4 Phone also looks good because you can pick one of these up in 16gb flavour on ebay for about £60-£80 in working order (on a buy it now) and a lot less than that if you’re lucky or happy with a semi working version 😉

        I’m not saying the android root side load method suggested here isn’t good, in fact quite the opposite because I applaud the effort. But it could be worth considering some other way with the right hardware in hand.

    3. Oh that didn’t work at all well. The root user isn’t allowed to install openssh-server… no ifconfig, no ip (I install ifconfig) – but the openssh is a big one – if root does not have permission to install that – what ELSE does root not have permission for…. I’m thinking – root the Nexus (if that is even possible on the 2012 edition)…

  13. Peter, we swapped a couple of brief mails in the past about using Android as as a server. Appreciate you’re NOT using Android as the host OS really here, but as you say you get a big bang for you buck using that kind of hardware.

    I’m running two Android devices at home that are incredibly stable (rooted with updates disabled, and unused apps removed or disabled). One is a old tablet. The other a phone I got for £20 when one of those ‘end of stock’ types offers came up, as they do.

    The “home automation” one is only running simple scripts that issue HTTP commands to IOT devices I can control that way (like IP cameras). I use SMSs from my phone to send commands to the “home automation” phone completely out of band with no need to use external servers, nor VPN to my router, nor poke holes in it with open ports. Obviously quite limiting, but serves a purpose 🙂

    1. Well of course if this pans out you could use one tablet for both purposes though I think I’d like a little more FLASH in there to do both. I’ve not tried accessing SD yet because for some reason when I put an SD into the K10000 it totally ignored it. The unit does have 2GB of RAM which is nice. A little more knowledge to aid interaction would be nice too – it would be good if Debian could access the bluetooth (for accessing garden sensors for example).

  14. it’s INIT, not INITIALIZATION, in menu

    you need to add pi user to privileged ones in that menu, where are already root and messagebus, if i remember well

    no need of CONFIGURE step, just install then start

    no need to change permissions, i run the script this way (link here is always latest version available on Peter’s git), always done so, it’s equivalent, and no need of winscp:

    wget https://bitbucket.org/api/2.0/snippets/scargill/94yxL/master/files/snippet.txt
    bash snippet.txt

    sd card mount, we’ll see in weekend, together with error checking, which is a MUST…

    for coloured prompt, this is what i use (in first comments the details/format):
    https://gist.github.com/fragolinux/efbe29b9a9a0353cde88ba4f3c7cd01f

    1. No idea is the short answer. I’m guessing as no rooting is required – that Termux will not let you make a proper ROOT user??? I don’t know – just a guess. And can it do a full graphical interface – remotely accessible? I don’t know – maybe someone using Termux could enlighten us.

      Certainly if there is something we can use as a base – that will start up automatically from powering up the phone (as does Linux Deploy) – giving root access to what seems like a standard Debian 8 setup – I’m all ears – and would be even more impressed if it would give that Debian some access to the likes of audio.

      1. Looking at the docs – Termix doesn’t do root user – so you could use SUDO (apparently) but that is no good if you are using, say, WinSCP and you want to edit files from there… at least I can’t see how it could be.

    1. Don’t jump TOO quickly – the RPI works well – recovers perfectly from power loss, has simple backup capability etc etc… this has no-where near proven itself yet – but… it does open up some possibilities. I have an old tablet lying around – all down to whether I can root it or not. However, no rush – I’ll just let this sit on test. This morning I did my usual thing of creating a CLS command which clears the screen, reminds me of the IP address – and also adding a nice coloured prompt. That works after clear screen but when first opening the terminal I get some warnings I’ve not seen on Pi or other devices – so this is not a guaranteed replacement… just a nice experiment for now and would like to hear from anyone who’s done similar or used this blog to do the same.

Comments are closed.