Dion Moult Seriously who ever reads this description.

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 ... ]
FEATURES="-userfetch"

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 ... ]
nameserver 8.8.4.4
nameserver 8.8.8.8

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"


13 Comments

hari says: (3 January 2014)

Interesting way to use your mobile phone, Dion! :) As you say, it opens up more possibilities to use your phone/tablet than with pure Android.

What is the advantage of chroot over installing Linux natively on the device (if that is at all possible, which I’m sure I’ve read about before).

I definitely think that compiling desktop software on a phone will be a big processor and battery drain. It would be better to put the phone on its AC adapter while installing such software. And also the size of the internal/external storage required. Maybe a caveat would help.

Dion Moult says: (3 January 2014)

Hari, it’s great: I believe i can safely say that this has practically converted my phone into another laptop: I can do my development on the go now with all my tools required. The bluetooth keyboard seals the deal. I can set up in 5 seconds anywhere, and stop instantly.

Chroots are convenient because you don’t touch the host OS: and although Linux on your Android is great for doing laptoppy stuff, Android still provides a better touch friendly interface. This way I can bootstrap using the Android kernel, not worry about hardware incompatibility, and play to each strength.

Power is consumed, but surprisingly not a huge amount when compiling. I don’t find it an issue. Power and temperature issues are mitigated with limitting the compilation to 2 cores. Hard drive space is not an issue because you can always use an external SD card, and if you were really pressed, Gentoo does allow the ability to strip down the system to a super minimal setup. Finally with RAM, that’s the killer. For example I don’t have enough RAM to compile Firefox (hence running Midori). I guess you could always use external SD card with swap but that’s a hack :)

Definitely recommend doing this :) Let me know if you try it out. No regrets whatsoever.

Erica says: (31 March 2014)

Sorry I sound noobish, but;

Will this work on any Android mobile device? Even the newer ones? Is it possible to use Gentoo on the Nexus 5? Can you install GNU/Linux Gentoo distro onto an Android phone from a Virtual Machine?

Dion Moult says: (2 April 2014)

Short answer: Yes it will work on any Android device, installed from any medium.

Long answer: Gentoo is a meta distribution. As long as there is some way to load any operating system on it, it’s likely that you can install Gentoo on it.

Because in my post above I haven’t needed to use any device or hardware specific features, I can perhaps safely say that it _will_ work with your Android device, newer ones, the Nexus 5, and even the Samsung Toaster.

As for installing Gentoo onto an Android phone from a VM, I don’t see why you’d want to. You can install from the phone, on the phone. There is no need to plug it into another machine, and especially no need to fire up a VM.

Conrad says: (28 December 2014)

Hi Dion,

Thanks for the great tutorial and sharing your expertise freely.
I recently got an Xperia Z2 tablet, and really want to have gentoo running on it so that I can use some applications like Rstudio on the tablet. Besides that, with sufficient processing power and memory, why not?
I have gentoo chrooted in my /storage/sdext2/gentoo folder rather than using an image so that I can make use of the ample space on my sdcard. I have emerged xorg-server, tight-vnc and lxde, but don’t know where to go from here. When I try and access through vnc viewer I am greeted by a grey block with a black x cursor. Typing in commands on the virtual keyboard gives no response. How does one configure the running system so that the display manager is accessible through vnc?

Dion Moult says: (28 December 2014)

Hello Conrad,

First try get X working with a simple interface like twm or fluxbox. Then make sure your vnc is set up properly to launch that interface. Connecting to vnc on localhost on the standard 5900 port is sufficient. As far as I know nothing fancy needs to be done.

Conrad says: (29 December 2014)

Hi Dion,

Thank you for responding!

I will keep working on trying to get a basic X interface configured. Could you post your xorg.conf for me and your make.conf so that I can see if there is anything I am missing. Also, I noticed that one or two of the packages that were emerged to get xorg-server required access to /usr/src/linux. How have you linked to the Android kernel sources so that gentoo has access to them?

Dion Moult says: (8 January 2015)

Hello Conrad, I do not have a xorg.conf, the defaults have been fine for me. I have not had to link the android kernel, usually the ebuilds say “Look, we can’t find the kernel, you’re on your own to ensure these modules are enabled”, so simply disregard the messages and continue along :)

Nazar says: (1 May 2015)

Thank you Dion! Your post inspired me and helped in not obvious things, especially “android quirks”! I brought my old phone a new life – I’ve made web-server from it. Now there is my blog hosted on it and here is the post about how I did it http://nazar.serveblog.net/2015/04/the-very-first-post/
Thank you for valuable info!

How I raised this blog with my ex-android phone | Nazar's Blog says: (9 August 2015)

[…] is a good article about this. Also it is useful to read article from project Gentoo on Android.¬† My¬†Gentoo resides under […]

K3A says: (16 August 2015)

I made a simple script for mounting stuff and migrating DNS settings from android:

#!/system/bin/sh

# transfer dns settings
echo -n > /data/gentoo/etc/resolv.conf
x=`getprop dhcp.wlan0.dns1`
if [ -n “$x” ]; then echo “nameserver $x” >> /data/gentoo/etc/resolv.conf ; fi
x=`getprop dhcp.wlan0.dns2`
if [ -n “$x” ]; then echo “nameserver $x” >> /data/gentoo/etc/resolv.conf ; fi
x=`getprop dhcp.wlan0.dns3`
if [ -n “$x” ]; then echo “nameserver $x” >> /data/gentoo/etc/resolv.conf ; fi
x=`getprop dhcp.wlan0.dns4`
if [ -n “$x” ]; then echo “nameserver $x” >> /data/gentoo/etc/resolv.conf ; fi

if ! mount | grep /data/gentoo/sys > /dev/null; then
mount -t proc proc /data/gentoo/proc
busybox mount –rbind /dev /data/gentoo/dev
busybox mount –rbind /sys /data/gentoo/sys
busybox mount –rbind /mnt/media_rw/extSdCard /data/gentoo/sdcard
ln -s /proc/self/fd /data/gentoo/dev/fd
fi

chroot /data/gentoo/ /bin/bash -l

Peter says: (19 February 2016)

Hi Dion,

pleease please help me!:)

I cant get Linux to work on my Note 2..
The link to the Gentoohandbook doesnt exist anymore.
And on the easy way over Linux Deploy and Linux on Android i havent any internet conection.

What ive is the latest version of BusyBox, root and a CMbased Android System (SlimRom without Gaps) Version 4.4.

I really need linux on my androidsmartphone, *please**

Is there any other tutorial that work for our note 2?
Or is there anything special to look for? Could the missing Gaps be source of the missing parts?

Yours sincerly
Phiter

Dion Moult says: (19 February 2016)

@K3A, thanks very much!

@Peter, the ARM handbook was taken down, but you can follow an alternate handbook from here: https://wiki.gentoo.org/wiki/Handbook:Main_Page – from their page: “ARM and ARM64 are supported by the Gentoo project but do not yet have a full handbook at their disposal. Please refer to the ARM project for more information.”

Just follow another handbook and modify the architecture specific steps for ARM.

Leave a Comment