2011-05-06

Running Gentoo Linux (as a chroot) on the Motorola Xoom


Prerequisites

  • a rooted xoom
  • busybox installed
  • a terminal emulator (Better Terminal Pro works perfectly)
  • a large enough & preferably fast  microsd card. I used an 8Gigs class 6.
  • check if you have nothing important to backup on the card before starting
  • optional : a bluetooth keyboard

First step : prepare an sdcard


Plug your card with a reader / adapter on a standard linux.
It should appear like a /dev/mmcblk0

Wipe out the partition table and create one big linux fs:

fdisk /dev/mmcblk0


remove all partitions: d d d
re-add one, primary with the default linux type with the default size (all disk)
n then p then enter enter

Create an ext4 file system:
mkfs.ext4 /dev/mmcblk0p1

Mount the fs somewhere
mkdir -p /mnt/gentoo
mount /dev/mmcblk0p1 /mnt/gentoo
cd /mnt/gentoo

Second step : copy over the stage3 and portage

Browse to http://www.gentoo.org/main/en/mirrors2.xml and find a good mirror for you or if you have already a gentoo machine do :
emerge mirrorselect
mirrorselect -s 1 -o

You need to find a stage3 of armv7 arch with hardfp and undecompress it where you have mounted your sdcard :
cd /mnt/gentoo
wget http://mirror.ovh.net/gentoo-distfiles/releases/arm/autobuilds/current-stage3-armv7a_hardfp/stage3-armv7a_hardfp-20110503.tar.bz2
tar xjvf stage3*.tar.bz2
rm stage3*.tar.bz2

Then you need a portage snapshot and uncompress it in the right directory:
cd /mnt/gentoo/usr
wget http://mirror.ovh.net/gentoo-distfiles/releases/snapshots/current/portage-latest.tar.bz2
tar xjvf portage-latest.tar.bz2
rm portage-latest.tar.bz2


Third step : adjust some settings
in /mnt/gentoo/etc/make.conf adjust your mirrors and, very important disable the userfetch feature:

[...]
SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
GENTOO_MIRRORS="http://mirror.ovh.net/gentoo-distfiles/"
FEATURES="-userfetch" # on android non-priviledged users like portage has no right to open a socket due to CONFIG_ANDROID_PARANOID_NETWORK in the kernel config
Note : you can also add MAKEOPTS="-j2" for parallel building

create /mnt/gentoo/root/.profile like this :

export TERM=xterm
env-update
cd

Unmount your card, put it in your Xoom and restart it.

Chroot in your gentoo
Here is a little script that you can put for example in /sdcard/gg.sh :

mkdir -p /sdcard/gentoo
mountpoint -q /sdcard/gentoo || mount -t ext4 -o noatime /dev/block/mmcblk0p1 /sdcard/gentoo
echo "nameserver `getprop dhcp.wlan0.dns1`" > /sdcard/gentoo/etc/resolv.conf
mountpoint -q /sdcard/gentoo/dev || mount -o bind /dev /sdcard/gentoo/dev
mountpoint -q /sdcard/gentoo/dev/pts || mount -o bind /dev/pts /sdcard/gentoo/dev/pts
mountpoint -q /sdcard/gentoo/sys || mount -o bind /sys /sdcard/gentoo/sys
mountpoint -q /sdcard/gentoo/proc || mount -t proc proc /sdcard/gentoo/proc
export HOME=/root
export TERMINFO=/etc/terminfo
chroot /sdcard/gentoo /bin/bash -l

then do from adb shell or your favorite terminal on the device :
su
source /sdcard/gg.sh

Enjoy your new gentoo environment !

Edit1:
- added a check to avoid remounts when you reexecute the script
- overrided the shell variable better terminal was putting


Edit2 2011-05-28: With the 3.1 update, the sdcard is mounted directly under /sdcard/external:
/dev/block/mmcblk0p1 /mnt/sdcard/external ext4 rw,relatime,barrier=1,data=ordered 0 0

So you can safely reuse it directly, here is the alternative script.

echo "nameserver `getprop dhcp.wlan0.dns1`" > /sdcard/external/etc/resolv.conf
mountpoint -q /sdcard/external/dev || mount -o bind /dev /sdcard/external/dev
mountpoint -q /sdcard/external/dev/pts || mount -o bind /dev/pts /sdcard/external/dev/pts
mountpoint -q /sdcard/external/sys || mount -o bind /sys /sdcard/external/sys
mountpoint -q /sdcard/external/proc || mount -t proc proc /sdcard/external/proc
export HOME=/root
export TERMINFO=/etc/terminfo
chroot /sdcard/external /bin/bash -l