What is Chroot?

Well it’s not a virtual machine or emulation, it’s an honest to goodness linux install…running inside of another linux install. Inception style.

Chroot in essence is a method of running a linux distribution that is not at the standard “/” location, for example in this guide gentoo will be running in /data/local/mnt/. You then “chroot” to that directory and voila you have jumped into that linux distribution and can proceed as if you were running linux natively.

This guide will provide instructions on how to install gentoo on an android tablet. It is assumed that you are doing this on a unix system (debian, gentoo, fedora ubuntu etc) (syntax for some commands might be slightly different for different distributions

Familiarity with a linux environment is required and i assume that some blanks can be filled in, we are installing gentoo after all ;)

First I’d like to thank the people over at linuxonandroid for providing the bootscripts which I based mine off of.

Requirements

  1. Rooted android tablet with superuser (in this case i’m using a Nexus 10)
  2. A compiled version of busybox-android get it here (Full credit for this goes to Stephen (Stericson) )
  3. Android Terminal Emulator

Creating the Image

All steps in this part will be performed on your linux install. we will copy this image to the device later

Create a linux image using dd

Configure this to the size you want, the filesystem of the sdcard partition on your device might be a limitation.

dd if=/dev/zero of=gentoo.img bs=1M count=0 seek=3072

Run mkfs.ext2 on it

NOTE: depending on the size of your partition you may have to increase the number of inodes availible
mkfs.ext2 -F gentoo.img

Download the gentoo stage3 bz2 from:

http://distfiles.gentoo.org/releases/arm/autobuilds/current-stage3-armv7a/

Download the latest portage tree

http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2

Create a temporary folder and mount the gentoo image

mkdir tmp
mount -o loop gentoo.img tmp/

Extract the stage3 and portage tree archives

extract the stage3 tarball into the mounted image extract the portage tree into the usr directory that was just created

I assume the files were downloaded a directory one level above tmp

cd tmp
tar xvf ../stage3-armv7a-*.tar.bz2
cd usr
tar xvf ../../portage-latest.tar.bz2

Create some folders (check if they exist first)

mkdir tmp/dev/pts
mkdir tmp/sdcard

Copy the img to your android device!

unmount the img first before copying
umount tmp/

Transfer the img to your android device via usb or similar means.

Chroot into the image

Copy the busybox executable to /data/local so that you can execute it

(feel free to use your own version of busybox)

Copy the following script into the same directory

Script Download

####Location of you busybox
export bbox=/data/local/busybox
####Edit image location as needed
export imgfile=/sdcard/gentoo/gentoo.img
export mnt=/data/local/mnt

mkdir -p $mnt

$bbox mknod /dev/block/loop255 b 7 255
$bbox losetup /dev/block/loop255 $imgfile
$bbox mount -t ext2 /dev/block/loop255 $mnt

$bbox mount -t devpts devpts $mnt/dev/pts
$bbox mount -t proc proc $mnt/proc
$bbox mount -t sysfs sysfs $mnt/sys
$bbox mount -o bind /sdcard $mnt/sdcard

$bbox sysctl -w net.ipv4.ip_forward=1

#set environment
$bbox chroot $mnt /usr/bin/env -i HOME=/root USER=root PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin TERM=linux /bin/bash -l

$bbox umount $mnt/sdcard
$bbox umount $mnt/dev/pts
$bbox umount $mnt/proc
$bbox umount $mnt/sys
$bbox umount $mnt
$bbox losetup -d /dev/block/loop255 &> /dev/null

(run this in side android terminal emulator)

Make them executable

chmod 777 busybox
chmod 777 boot.sh

Make sure the boot script points to the correct image file and run it.

./boot.sh

add DNS servers

echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf

echo "127.0.0.1 localhost" > /etc/hosts

Get portage working.

echo "FEATURES=\"-userfetch\"" >> /etc/make.conf

df error: cannot read table of mounted file systems

grep -v rootfs /proc/mounts > /etc/mtab

and that’s it!

Thanks to linuxonandroid for their usefull app and scripts And Andrew Seidl for his help in getting everything figured out.