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"

Dion Moult

I've been developing software for well over 10 years, work as an architect (not the computer kind, the regular sort), and am classically trained as a pianist. I try to do the right thing when I get the chance in my field, such as through contributing to open-source communities and promoting sustainable living.

More Posts

Spread the love
Tagged: , , , , ,


  1. 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.

  2. 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.

  3. 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?

  4. 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.

  5. 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?

  6. 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.

  7. 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?

  8. 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 :)

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


    # 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

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

  10. 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

  11. @K3A, thanks very much!

    @Peter, the ARM handbook was taken down, but you can follow an alternate handbook from here: – 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 Reply

Your email address will not be published. Required fields are marked *