Installing Gentoo on Android with chroot

Note: recently edited 8th Nov 2014

Installing Gentoo in a chroot alongside Android is easy, so if you already use Gentoo and have an Android phone, there’s really no reason why you shouldn’t do it. With a ginormous phablet like the Samsung Galaxy Note 2 and a bluetooth keyboard, you can get a super-mobile full Linux workstation everywhere you go.

Before we begin, let’s see the pretty pictures. Here’s Larry saying hello :) (Installing a talking cow should be the top priority once the base system is up and running)

Larry saying hello on Android

… and of course a shot of emerging stuff …

Gentoo on Android compiling stuff

… and finally we’re running Enlightenment 17 with the Webkit-based Midori browser with X, accessed via (Tight)VNC …

E17 on Android with Gentoo Linux

Installing Gentoo on Android

Prerequisites first: you’ll need a rooted device. You’ll also need a terminal with busybox. I recommend Android Terminal Emulator and busybox by stericson. I would also recommend installing Hacker’s Keyboard, which gives you a full keylayout.

Installing is rather straightforward: modern Android phones usually run on ARMv7 so just follow the appropriate handbook. If you are installing it onto your internal storage (not on an external SD), you can skip to chapter 5 :)

You will need to be root to install, so su - in your terminal emulator of choice. Similarly, remount Android into read-write so that you can create the necessary files for Gentoo with mount -o remount,rw /. Finally, remember to install in /data/gentoo instead of /mnt/gentoo so to not conflict with Android’s mounting preferences.

Since we’re only installing a chroot and not booting alongside android, you can safely skip configuring the kernel, configuring fstab, configuring networking, and setting up the bootloader.

When mounting, you will need to do so as root user, and use the busybox implementation for --rbind support, as so:

$ su -
[ ... superuser access granted ... ]
$ cd /
$ mount -t proc proc /data/gentoo/proc
$ busybox mount --rbind /dev /data/gentoo/dev
$ busybox mount --rbind /sys /data/gentoo/sys
$ chroot /data/gentoo /bin/bash
[ ... now in the chroot ... ]
$ source /etc/profile

This is assuming you’ve put Gentoo in /data/gentoo

Android quirks

There doesn’t seem to be a /dev/fd on Android, so let’s fix that:

[ ... in Gentoo chroot ... ]
$ cd /dev
$ ln -s /proc/self/fd`

Portage won’t be able to download files as it doesn’t download as root, but instead as another user by default. No problem:

[ ... in /etc/portage/make.conf ... ]

Sometimes I’ve noticed that on bad reboots the /etc/resolv.conf can get reset. This will cause host resolving issues. Resolving is as easy as:

[ ... in /etc/resolv.conf ... ]

It will be a good idea to set your main user to the same UID as the Android normal user. Also, running id -a in android will show you that your user is part of various reserved Android groups. To fix issues such as your Gentoo user’s (in)ability to go online or use bluetooth, just create these groups in your Gentoo install with matching GIDs, and add your user to these groups. Here’s a list of Android UIDS and GIDS. For example, I needed to add my Gentoo user to groups with GIDs 3003 and 3004 before it could successfully go online.

If you want an X server, VNC will do the trick. I recommend android-vnc-viewer 24-bit colour seems to work, and perhaps change the input method to touchpad rather than touchscreen so it’s relatively usable.

Finally, with no fan and big heatsink on a mobile phone, you might find yourself running hot. So even though monsters like the Galaxy Note 2 have 4 cores, I recommend sticking it to MAKEOPT="-j2"


Syncing Kontact with Android

I recently became the proud new owner of an Android phone, or more specifically the Samsung Galaxy S i9000. Upon purchase it was promptly rooted and had a custom rom flashed onto it. Also recently KDE 4.6 was released and after a night of compiling I was sitting at a sparkling new desktop and customising it.

But this post isn’t about KDE 4.6 and nor is it about roms and galaxys. It’s about Kontact 2, part of KDEPIM 4.6 (which is still considered unstable by upstream) and how to achieve the state of PIM-zen which everybody should achieve once in their lives. The state of PIM-zen, for those too lazy to click, is the state where your PIM data (calendar/todo/contacts/feeds/etc) is accessible through any digital medium, be it your desktop’s PIM applications, a website visited from a remote location, or your mobile phone’s bundled PIM-suite.

Syncing your Calendar and events

I’m not going to talk about syncing email, as that has been covered countless times elsewhere. So let’s start with syncing the calendar, as it is the next most prevalent in use. Google phones unsurprisingly sync well to Google accounts – and given that Google accounts have a web-based frontend too, this kills two birds with one stone in our “access everywhere” requirement of PIM-zen. So our solution is going to be Kontact 2 <–Sync–> Google’s PIM Suite <–Sync–> Android device.

Kontact 2 is completely Akonadi based. In comparison to Kontact 1, where there was a makeshift Akonadi-resource wrapper which you could add to harness Akonadi as a data source, Kontact 2 only uses Akonadi-supported sources for your data. Luckily Akonadi makes it easy to connect to data sources, and so there is a specialised Akonadi-GCal-resource which you can add.

To do this, just right click on the bottom left box in Korganizer which holds the calendar sources, click “Add Calendar”, and select “Akonadi Google Calendar Resource”.

To get the resource, you may need to install the akonadi-googledata package. After clicking OK, all that remains is that you enter in your Google username (your email), and your Google account password. It should then start syncing and working flawlessly. Your Android phone can then sync to your Google account’s calendar.

However GCal is very buggy it seems as it isn’t unlikely that you’ll be having problems such as unable to authenticate or unable to grab calendar data. After scouring the web here are a few potential solutions to problems you might have:

  • Add the resource through the Akonadi configuration, not through Korganizer’s Akonadi wizard.
  • Ensure you have suffixed (even if you have an address) to your username.
  • Make sure you don’t use special characters (non-alphanumeric) in your password.
  • Use the latest version of libgcal (>0.9.3 should be good enough)
  • Remove any older version of libgcal.
  • If you are behind a proxy, set it properly in KDE’s system settings -> Network -> Proxy, if not, ensure it is “Connect to internet directly”. (OpenSuse’s defaults to using env variables)
  • Ensure you have ca-certificates package installed, and the certificate from to the list of accepted certs.
  • Have at least one event in the Google Calendar or it won’t sync (bug).
  • Sign out all other account sessions as detailed here.
  • … and of course, make sure Akonadi is running. (akonadictl start)

If it doesn’t work, you may want to stop akonadiserver, then start it with akonadictl start &> log in order to get a logfile. You can then poke around to see exactly where it failed. #akonadi on freenode may be able to help.

If it still doesn’t work, don’t despair (it didn’t work for me either!), as there is an alternative sync. The alternative uses CalDAV, as opposed to directly using Google’s Data API. To use it, just select “DAV groupware resource” from the wizard from the same screenshot shown above. However when it asks for you to pick the groupware server, click Cancel. This will prompt you to enter the details manually. Now follow the instructions by Google for SunBird for setting up a CalDAV resource, and as shown below in the screenshot, then after pressing OK things should starting syncing fine.

Finally, we should note that there might be some data loss, as Google Calendar doesn’t implement all of the data fields, such as attendees to events. Another thing you might want to note is that exporting your existing KOrganizer calendar into ical/ics and then importing into Google Calendar may not work, as KOrganizer doesn’t follow the ical/ics specs properly. If you are exporting and are manually modifying the ical/ics file such that it works, ensure you define the timezone, otherwise chaos will ensue :D

Syncing your contacts

Android has, just like Calendar, a built-in autosync with your Google account’s contacts. Akonadi also has a Google Contacts resource, which you may use in similar fashion to the Google Calendar resource described above. Unfortunately it doesn’t work with me, and so I’m currently in the process of debugging it with Savago in #akonadi. YMMV, and I don’t know any good alternative to syncing this.

Syncing your todo lists

This is a pain. First off it should be plainly stated that Google’s Android does not have a stock to-do application. Google’s own laughable implementation of a to-do webapp in GMail is – well, I would use the most derogatory adjectives I could think of to describe it, but that would just mislead you into thinking that it is possible to quantify the horribleness of it (which it isn’t) – oh, where was I? Oh yes, Google’s to-do webapp doesn’t allow you to access it via ical or any sane format, is missing a ton of useful meta-tags which some people might want, and so you should probably scratch out trying to sync over Google’s to-do webapp.

The options do you have are limited to what exists on the Android marketplace to read your todo lists. The two major ones are Astrid Tasks and RememberTheMilk, both of which are very good. Let’s cover RTM first.

The biggest downside with RTM is that in order to use the Android application for it (which is very good), you have to be a RTM Pro user, which costs 25$ a year, which is actually worth it if you are really dependent on task lists. Alternatively you could use their mobile barebones webapp which looks ugly but gets the job done. Their main webinterface is probably the only webinterface I actually really enjoy using, but the downside is that you cannot interact with your tasks via KTodo – you get only readonly access via an iCal file (note that you can also use a version where your todo items are converted to events in your iCal file for use through the KOrganizer interface). So the final setup goes somewhat like this RTM Android App <– Push/scheduled syncs –> RTM Website and/or Google Calendar <– Read-only iCal file –> KTodo. It should be noted that RTM supports syncing with your Google Calendar as well, so that’s an added plus if you want to use that interface. Note that there is also a RTM Plasmoid, which just adds icing to the cake.

The alternative is Astrid Tasks. Whilst interfacewise a little more clunky it still does get things done. It can sync with a “space” on the online saas Producteev, which in turn allows you to manage it from there. It also does a two-way sync with Google’s to-do webapp, but is known to be buggy, YMMV. However from there it doesn’t seem to have a way to sync with KTodo. Luckily, in a twisted sort of way, it does allow you to sync to RTM via a now unofficial sync (due to RTM’s policies of not allowing other companies to make added profit from their system), and using RTM you can then do the same sync as above. However if you use Astrid Tasks even with syncing to RTM, you don’t need to be a RTM Pro user and hence everything is free. Your options are therefore Astrid Tasks Android App <–> Producteev/Google, or Astrid Tasks Android App <–> RTM <– Read-only iCal file –> KTodo.

There is a third alternative – GTDAgenda. This webapp closely follows the original principles of Getting Things Done by David Allen. It’s a really powerful tool and comes with both a mobile site and Android application too. The only downside is that they are rather expensive and their free version is rather stripped down. Even when stripped down it does seem a little overkill for my needs, but it might be different for you.

My personal reccomendation is to just go with RTM.

Syncing your RSS feeds

Syncing your RSS feeds are a little tricky now that Akregator’s Google Reader sync is unmaintained and broken. Also Google doesn’t have a stock feeds application (why, oh why, Google, do you leave out the basics!) – update: actually it turns out they have recently published one. This pretty much limits you to running any Android app which syncs with Google Reader (there are a few out there, I personally use Pulse) – or you could just access Google Reader’s mobile application, which is really attractive for a mobile site I must say.

In the meantime, get somebody hacking on Akregator and fix that sync plugin!

… and reach your state of PIM-zen!

I hope that this guide has been helpful to those wanting to achieve that perfect sync across all their devices. Any tips and tricks I missed out please let me know in the comments.


Oh, did I miss something?

Rumour has it that I didn’t put a post on the 10th of November when I promised I would do a post every two days. Whoops. Well, two days ago marked the starting of what I believe would be one of the most interesting set of days I’ll come across. Suffice to say my Twitter page might cover some of the events, and well … I’m quite at a loss as to what I should say.

Perhaps I can justify myself with an interesting techy article about Google’s latest massive slipup.