[LINUX] Gentoo on your Desire (tutorial)

Search This thread

Deathisfatal

Member
Jul 30, 2010
49
36
Melbourne
Gentoo on HTC Desire

Prerequisites:
  • Rooted Desire
  • Any flavour of Linux (Live or installed)
    Code:
  • A decent sized MicroSD card (>2Gb recommended)
  • MicroSD USB adapter (or SD card reader and adapter)
  • Some knowledge of Linux command line and Gentoo is recommended
  • Patience...

Things you should know first:
  • This is NOT a fully independent Linux - it runs parallel to Android inside a chroot environment
  • Some applications can be very slow until they are compiled properly for the Desire hardware
  • Compilation with a 1GHz single core CPU is slow
  • You can run just about any Linux program; X programs and desktop environments can be used via VNC
  • Many custom ROMs and kernels do not include swap support for performance reasons, and so if you require swap you may need to compile your own kernel (I will upload my custom kernel at a later date)
  • Due to Android security settings, only root can use the network. This causes some problems as anything that requires network access must run as root (again, if anyone has any insight for a way around this, please contact me)
  • Some ROMs underclock the CPU when the screen is off - this will lead to VERY long compilation times if you leave your phone like that

Step one - Prepare MicroSD

To install Gentoo you will need an ext2, 3, or 4 filesystem on your MicroSD card. This can be done two ways: partitioning your card (recommended), or by creating a file and creating the filesystem within that (not covered here).
Start up GParted (or something similar) on your computer and insert your MicroSD card; if your card is fully allocated, you will need to shrink the existing partition(s) first (back up your data! This can go wrong...) and leave a space at the end of the card for your new partition. The absolute minimum I would recommend to dedicate to Gentoo would be 1GB, but that doesn’t give you much wiggle room and you will have a very hard time compiling anything big (like GCC); I would recommend making the partition >2GB. Make sure you create the Gentoo partition at the end of the card.

Note:
APP2SD+ requires its own partition - if you have it enabled, you must have at least three partitions, with the second partition on the card dedicated to it and the third for Gentoo.

Due to the large number of files in the Portage tree, small partitions can sometimes run out of inodes. You can get around this by decreasing the size of the inodes and blocks, and therefore creating more:

Code:
~ $ sudo mkfs.ext3 /dev/(partition) -i 2048 -b 2048

Step two - install base system:

Download the latest stage 3 tarball for armv7a-unknown-linux-gnueabi from the Gentoo mirror closest to you (Google "Gentoo Mirrors", I can't post links yet..), mount the Gentoo partition and extract the contents of the tarball to it.

Example:
Code:
~ $ wget (your selected mirror)/linux/gentoo/releases/arm/autobuilds/current-stage3/armv7a-unknown-linux-gnueabi/stage3-armv7a-20100917.tar.bz2
~ $ sudo mkdir /mnt/sd
~ $ sudo mount /dev/(partition) /mnt/sd
~ $ sudo tar xjvfp stage3-armv7a-20100917.tar.bz2 -C /mnt/sd/

Download the latest portage snapshot (from the Gentoo mirror) and extract:

Code:
~ $ wget (your selected mirror)/linux/gentoo/snapshots/portage-latest.tar.bz2
~ $ sudo tar xjvf portage-latest.tar.bz2 -C /mnt/sd/usr/

Now modify the make.conf file using your favourite text editor:

Code:
~ $ sudo nano /mnt/sd/etc/make.conf

Sample make.conf:

Code:
CFLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=vfpv3 -O2" # if anyone has any suggestions to improving these, please let me know
CXXFLAGS=${CFLAGS}
CHOST="armv7a-unknown-linux-gnueabi"
USE="unicode X -gnome -kde -firefox wifi syslog -udev -mdev -wifi -gpm threads nptl networking wxwidgets -ipv6 sqlite jpeg png dbus" # Have a look at the Gentoo USE flag description page on the web for others you may want/don't want
VIDEO_CARDS="none"
ALSA_CARDS="none"
INPUT_DEVICES="none"
SYNC="rsync://(your selected mirror)"
GENTOO_MIRRORS="(your selected mirror)"
ACCEPT_LICENSE="*"
MAKEOPTS="-j1"
PORTAGE_NICENESS="19"
AUTOCLEAN="yes"
FEATURES="noman nodoc noinfo -userfetch" # Getting rid of the man, doc and info pages saves a lot of space. Userfetch is disabled due to the issue described above
PORTAGE_RSYNC_EXTRA_OPTS="--exclude ChangeLog" # Again, this saves some space

Edit locale.gen with the locale values you require, e.g.:

Code:
en_US.UTF-8 UTF-8

Unmount your MicroSD card and insert it back into your phone.

Step three - configuring the base system

Using ConnectBot, another terminal emulator app, or adb, connect to the local console and setup the mounts, then enter Gentoo (using busybox as your shell (type "busybox sh") is recommended as the tab completion (trackball + i in connectbot) helps a lot):

Code:
# mkdir /data/gentoo
# mount -t ext3 (or whatever fs you set it to) /dev/block/mmcblk0p3 (change the 3 to whatever partition you need) /data/gentoo
# mount -t proc none /data/gentoo/proc
# mount -o bind /dev /data/gentoo/dev
# mount -t devpts none /dev/pts
# chroot /data/gentoo /bin/bash
# source /etc/profile

Congratulations! You are now inside your own Gentoo environment. If you don't need your phone for a while you can now recompile and update the system (this will take quite a long time and will use a lot of data). This doesn't have to be done now, or at all, but it is highly recommended to do so at some point:

Code:
# emerge -DuNav world

Once that's done (or you don't want to do it), install some base programs:

Code:
# emerge -av screen sudo

If you want VNC, tightvnc is recommended:

Code:
# emege -av tightvnc

Web server:

Code:
#emerge -av nginx

Set a root password:

Code:
# passwd

For some reason running SSHD with IPv6 enabled causes the phone to restart. To fix this, make the following changes to /etc/ssh/sshd_config:

Change:
Code:
#AddressFamily any
To:
Code:
AddressFamily inet

To start SSHD:

Code:
# ssh-keygen -t rsa (save to /etc/ssh/ssh_host_rsa_key with no passkey)
# ssh-keygen -t dsa (save to /etc/ssh/ssh_host_dsa_key with no passkey)
# /usr/sbin/sshd

If your kernel supports swap, it is recommended to create and enable it:

Code:
# dd if=/dev/zero of=/swap bs=10M count=20 (change this to alter the size of the swap file)
# mkswap /swap
# swapon /swap (you will need to run this command with the other mount commands each time you boot)

Boot script:
Start your phone in recovery mode and mount /system using the partitions menu in your recovery ROM, then create a file on your computer with the following contents:

Code:
#!/system/bin/sh
#
#		Linux startup script for rooted Android systems 
#		© Deathisfatal @ forum.xda-developers.com
#
#		TODO:
#			-	Error handling
#

# Edit the following variables as required

HOSTNAME="Android"
LINUX="/data/gentoo/"
BB="/system/xbin/busybox"
CHROOT="${BB} chroot ${LINUX}"
ROOT="/dev/block/mmcblk0p3"
SWAP="/swap" 

${BB} mount -o noatime -t ext3 ${ROOT} ${LINUX} # Edit -t as required by your filesystem
${BB} mount -o bind /dev ${LINUX}dev
${CHROOT} /bin/mkdir /dev/shm
${CHROOT} /bin/mount -t tmpfs -o size=32m none /dev/shm
${CHROOT} /bin/mkdir /dev/fd
${BB} /bin/mount -o bind /proc/self/fd /dev/fd
${CHROOT} /bin/mount -t devpts none /dev/pts 
${BB} mount -t proc none ${LINUX}proc
${CHROOT} /sbin/swapon ${SWAP}
${CHROOT} /bin/mount -t tmpfs -o size=32m none /tmp
${CHROOT} /bin/mkdir /tmp/run
${CHROOT} /bin/mkdir /tmp/run/portage
${CHROOT} /bin/touch /tmp/run/utmp
${CHROOT} /bin/chmod 777 -R /tmp
${BB} mount -o bind /data ${LINUX}mnt/data
${BB} mount -o bind /sdcard ${LINUX}mnt/sd
${CHROOT} /bin/hostname ${HOSTNAME}

# Uncomment the following line to enable sshd on boot
#${CHROOT} /usr/sbin/sshd
Connect your phone and computer with the USB cable, then use the following command on your computer:

Code:
~ $ adb push (File you created earlier) /system/etc/init.d/05linux
~ $ adb shell chmod 755 /system/etc/init.d/05linux

Now reboot your phone and your Gentoo partition should automatically mount.

Notes:
  • If you restart your phone, you will need to issue the necessary mount commands as you did earlier until I (or someone else) get around to making a proper script that runs at boot time
  • For information on how to set up programs and servers on Gentoo visit the Gentoo wiki
  • Please contact me or post here with any questions you may have regarding this

Changelog:
  • Updated CFLAGS and bootscript

Thanks to sfjuocekr for his/her contributions.
 
Last edited:
  • Like
Reactions: fagotto

koider

Member
Jun 29, 2010
32
0
Thanks for this tutorial, Gentoo is my favourite Linux distro and it's great to know someone's got it running on the Desire :)

I don't think I've got the patience to try it on my phone though, all the compiling must take ages. I wonder whether it's possible to cross-compile...
 

mathrock

Member
Feb 4, 2010
7
0
I have the same issue with openssh-server crashing my Nexus One (running Ubuntu 10.04 on CM6) too. I would love to figure out how to fix it.
 

Deathisfatal

Member
Jul 30, 2010
49
36
Melbourne
Restored OP to state before server crashes - changed CFLAGS and added a boot script.

EDIT: I have solved the mystery of the SSHD crash!! It's to do with IPv6 - OP updated.
 
Last edited:

sfjuocekr

Senior Member
Jun 14, 2008
650
85
You should do a emerge -e world to recompile the whole tree after first boot.

This will make sure all your packages are compiled with correct CFLAGS etc.
 

sfjuocekr

Senior Member
Jun 14, 2008
650
85
Code:
CFLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=vfpv3 -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"
CHOST="armv7a-unknown-linux-gnueabi"

USE="minimal unicode -X -gnome -kde -firefox -wifi syslog -udev -mdev threads nptl -ipv6 sqlite jpeg png dbus -gpm ssh"

VIDEO_CARDS="none"
ALSA_CARDS="none"
INPUT_DEVICES="none"
ACCEPT_LICENSE="*"
MAKEOPTS="-j1"
FEATURES="noman nodoc noinfo -userfetch"
PORTAGE_RSYNC_EXTRA_OPTS="--exclude ChangeLog"
AUTOCLEAN="yes"
LINGUAS="en"
PORTAGE_NICENESS="19"

I use this make.conf for Gentoo on my Desire.

Firstly NEVER globally allow keywords, this is bad. Do this for the specific programs you need, you can use /etc/portage and mask/unmask packages you actually need unmasked.

Set MAKEOPTS to -j1 instead of 2, helps keeping the system usable while emerging together with PORTAGE_NICENESS at 19.

I have left X etc all out of the global USE flags to save space, again use /etc/portage to set specific USE flags for packages that need them. This will save alot of space, because there are lots of packages with X support you will never need usualy.

I'm not entirely sure about leaving wifi and mdev away, but wifi is handled by Android itself and mdev should be too.

Then in the startup-script there was a minor mistake bind mounting /dev/fd, this is the modified script:

Code:
#!/system/bin/sh
#
#        Linux startup script for rooted Android systems 
#        © Deathisfatal @ forum.xda-developers.com
#
#        TODO:
#            -    Error handling
#

# Edit the following variables as required

HOSTNAME="UGH-GSM"
LINUX="/data/gentoo/"
BB="/system/xbin/busybox"
CHROOT="${BB} chroot ${LINUX}"
ROOT="/dev/block/mmcblk0p2"
#SWAP="/swap" 

${BB} mount -o noatime -t ext3 ${ROOT} ${LINUX}
${BB} mount -o bind /dev ${LINUX}dev
${CHROOT} /bin/mkdir /dev/shm
${CHROOT} /bin/mount -t tmpfs -o size=32m none /dev/shm
${CHROOT} /bin/mkdir /dev/fd
${BB} mount -o bind /proc/self/fd /dev/fd
${CHROOT} /bin/mount -t devpts none /dev/pts 
${BB} mount -t proc none ${LINUX}proc
#${CHROOT} /sbin/swapon ${SWAP}
${CHROOT} /bin/mount -t tmpfs -o size=32m none /tmp
${CHROOT} /bin/mkdir /tmp/run
${CHROOT} /bin/mkdir /tmp/run/portage
${CHROOT} /bin/touch /tmp/run/utmp
${CHROOT} /bin/chmod 777 -R /tmp
${CHROOT} /bin/mkdir /mnt/data
${CHROOT} /bin/mkdir /mnt/sdcard
${BB} mount -o bind /data ${LINUX}mnt/data
${BB} mount -o bind /sdcard ${LINUX}mnt/sdcard
${CHROOT} /bin/hostname ${HOSTNAME}

# Uncomment the following line to enable sshd on boot
#${CHROOT} /usr/sbin/sshd

And yea some error handling should be added to check if a directory exists yes or no, but not really important.

If I make more changes, I'll make notice here in the forums. If you have other general Gentoo questions, please ask I have been working with Gentoo since 2001 :) But it is a really trial and error distribution, you HAVE to be self capable to fix problems that will arise ... they WILL arise ;)

And again, leave

ACCEPT_KEYWORDS="~arm ~*" # Many useful packages are masked for arm with ~*

out of your makefile. Do it in /etc/portage when needed.

Don't use -O3 and -Os together, this actually GROWS ... same with using mcpu with march doesn't work just use march and mtune. -O2 is recommended.

http://www.gentoo.org/doc/en/gcc-optimization.xml
 
Last edited:

sfjuocekr

Senior Member
Jun 14, 2008
650
85
Also make sure you emerge linux-headers first so it ends up in world.

Usualy emerging a kernel makes sure headers are in place, but in this chrooted enviroment it isn't and might be cleaned with depclean or revdep-rebuild. Not sure why tho, because it should be in system already :s
 

[deXter]

Senior Member
Aug 23, 2008
507
171
This is a very interesting development! Thanks to everyone who made it possible.

Has anyone so far been able to run an Xserver / WM / DE yet?
Would love to see some screenshots of this in action..
 

Deathisfatal

Member
Jul 30, 2010
49
36
Melbourne
Code:
CFLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=vfpv3 -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"
CHOST="armv7a-unknown-linux-gnueabi"

USE="minimal unicode -X -gnome -kde -firefox -wifi syslog -udev -mdev threads nptl -ipv6 sqlite jpeg png dbus -gpm ssh"

VIDEO_CARDS="none"
ALSA_CARDS="none"
INPUT_DEVICES="none"
ACCEPT_LICENSE="*"
MAKEOPTS="-j1"
FEATURES="noman nodoc noinfo -userfetch"
PORTAGE_RSYNC_EXTRA_OPTS="--exclude ChangeLog"
AUTOCLEAN="yes"
LINGUAS="en"
PORTAGE_NICENESS="19"

I use this make.conf for Gentoo on my Desire.

Firstly NEVER globally allow keywords, this is bad. Do this for the specific programs you need, you can use /etc/portage and mask/unmask packages you actually need unmasked.

Set MAKEOPTS to -j1 instead of 2, helps keeping the system usable while emerging together with PORTAGE_NICENESS at 19.

I have left X etc all out of the global USE flags to save space, again use /etc/portage to set specific USE flags for packages that need them. This will save alot of space, because there are lots of packages with X support you will never need usualy.

I'm not entirely sure about leaving wifi and mdev away, but wifi is handled by Android itself and mdev should be too.

Then in the startup-script there was a minor mistake bind mounting /dev/fd, this is the modified script:

Code:
#!/system/bin/sh
#
#        Linux startup script for rooted Android systems 
#        © Deathisfatal @ forum.xda-developers.com
#
#        TODO:
#            -    Error handling
#

# Edit the following variables as required

HOSTNAME="UGH-GSM"
LINUX="/data/gentoo/"
BB="/system/xbin/busybox"
CHROOT="${BB} chroot ${LINUX}"
ROOT="/dev/block/mmcblk0p2"
#SWAP="/swap" 

${BB} mount -o noatime -t ext3 ${ROOT} ${LINUX}
${BB} mount -o bind /dev ${LINUX}dev
${CHROOT} /bin/mkdir /dev/shm
${CHROOT} /bin/mount -t tmpfs -o size=32m none /dev/shm
${CHROOT} /bin/mkdir /dev/fd
${BB} mount -o bind /proc/self/fd /dev/fd
${CHROOT} /bin/mount -t devpts none /dev/pts 
${BB} mount -t proc none ${LINUX}proc
#${CHROOT} /sbin/swapon ${SWAP}
${CHROOT} /bin/mount -t tmpfs -o size=32m none /tmp
${CHROOT} /bin/mkdir /tmp/run
${CHROOT} /bin/mkdir /tmp/run/portage
${CHROOT} /bin/touch /tmp/run/utmp
${CHROOT} /bin/chmod 777 -R /tmp
${CHROOT} /bin/mkdir /mnt/data
${CHROOT} /bin/mkdir /mnt/sdcard
${BB} mount -o bind /data ${LINUX}mnt/data
${BB} mount -o bind /sdcard ${LINUX}mnt/sdcard
${CHROOT} /bin/hostname ${HOSTNAME}

# Uncomment the following line to enable sshd on boot
#${CHROOT} /usr/sbin/sshd

And yea some error handling should be added to check if a directory exists yes or no, but not really important.

If I make more changes, I'll make notice here in the forums. If you have other general Gentoo questions, please ask I have been working with Gentoo since 2001 :) But it is a really trial and error distribution, you HAVE to be self capable to fix problems that will arise ... they WILL arise ;)

And again, leave

ACCEPT_KEYWORDS="~arm ~*" # Many useful packages are masked for arm with ~*

out of your makefile. Do it in /etc/portage when needed.

Don't use -O3 and -Os together, this actually GROWS ... same with using mcpu with march doesn't work just use march and mtune. -O2 is recommended.

http://www.gentoo.org/doc/en/gcc-optimization.xml

Thanks very much for your insight! I'll change the tutorial with your suggestions when I'm at a computer later on.
I originally just had -Os for optimization but someone suggested using it with -O3, but their post got lost with the server crash. I've only been using Gentoo for a year now so I'll bow to your wisdom!

I have tightvnc setup along with openbox, so I'll post a couple of screenshots later on too.

EDIT: Is there any benefit to having -mfpu=neon? Or is vfpv3 superior?

Sent from my HTC Desire using XDA App
 
Last edited:

Deathisfatal

Member
Jul 30, 2010
49
36
Melbourne
I'm currently working on getting Gentoo running natively with the S-OFF hack. At the moment I have it booting up, connecting to wifi and starting sshd, but X is a hassle. If anyone wants to collaborate on the project send me a message or post here; any help would be greatly appreciated!
 

Enhdojo

Senior Member
Sep 2, 2010
78
2
Cork, Ireland
Respect!

I'm currently working on getting Gentoo running natively with the S-OFF hack. At the moment I have it booting up, connecting to wifi and starting sshd, but X is a hassle. If anyone wants to collaborate on the project send me a message or post here; any help would be greatly appreciated!



Massive project! I'm impressed.
I wish I had any skill to be able to support you.
 

sfjuocekr

Senior Member
Jun 14, 2008
650
85
Thanks very much for your insight! I'll change the tutorial with your suggestions when I'm at a computer later on.
I originally just had -Os for optimization but someone suggested using it with -O3, but their post got lost with the server crash. I've only been using Gentoo for a year now so I'll bow to your wisdom!

I have tightvnc setup along with openbox, so I'll post a couple of screenshots later on too.

EDIT: Is there any benefit to having -mfpu=neon? Or is vfpv3 superior?

Sent from my HTC Desire using XDA App


Don't know for sure. I could try compile against neon to see if there is a speed increase. But to my knowledge neon instructions are already used or might only be use with vfpf3-d32.

Once I get my own box up and running again, I'll try it out. Compiling GCC without DISTCC is a horror!
 

Deathisfatal

Member
Jul 30, 2010
49
36
Melbourne
Sorry about the lack of updates to the thread - I've been pretty busy at uni lately. I'm currently having a lot of issues with X11 segfaulting randomly so I'll post pictures once I have that back up and running. When X decides to work, the whole interface works nicely - touch support via tslib is great, and fbdev seems adequate for 2D graphics.
Has anyone had any success with the tutorial I posted?
If anyone's interested, to get Gentoo running natively you need to compile your own kernel with a few changes:
  • Disable ramdisk support
  • Enable swap (optional)
  • Create a boot script that mounts FS's, proc, etc
  • Disable Android paranoid networking so users other than root can access the net
Then start your phone in fastboot, push your modified kernel to your phone with fastboot with "root=/dev/mmcblk0p3 (or mmcblk0p2) init=(your boot script) rootfs=ext3 rootwait" as the kernel command line.
When I have time I will create a full guide for getting Linux and X running.
Massive project! I'm impressed.
I wish I had any skill to be able to support you.
Thanks!
Once I get my own box up and running again, I'll try it out. Compiling GCC without DISTCC is a horror!
Indeed! I left GCC 4.5 compiling for 6 hours, only for it to run out of space and fail...
 
Last edited:

artemesia

Member
Dec 16, 2010
7
0
ANd on v6 CPU?

Thanks for the tutorial, Deathisfatal. I thought this was a great idea, so decided to try it on my HTC Hero (as opposed to Desire).

On the first try, the

chroot /data/gentoo /bin/bash

command failed with an "illegal instruction" error. I figured my processor must be an earlier one in the ARM family than the one for which the bash in the stage 3 tarball had been compiled (v7-a). Sure enough, when I looked in /proc/cpuinfo, the processor turned out to be a v6 - the first line of cpuinfo says

ARMv6-compatible processor rev2 (v6l)

So, I tried again using stage3-armv6j-20101112.tar.bz2 instead of stage3-armv7a-20101114.tar.bz2. This improved things a bit. I could then run the bash shell in the chrooted environment, and cd and ls around the chrooted filesystem.

Unfortunately, attempting to run emerge still failed with an "illegal instruction" error (so did attempting to run tar or wget). At this point, I'm stuck. I guess I still have a stage 3 for the wrong processor variant (and that at some point I'll also have to fiddle with the -march and -mtune options in CFLAGS), but have no idea how to select the right stage 3.

Advice welcome, thanks.
 

Deathisfatal

Member
Jul 30, 2010
49
36
Melbourne
That's quite strange! Perhaps try the armv5tel stage3 tarball. It could be that the armv6 stage3 is compiled for a different FPU than what the Hero has. What does the features line say in /proc/cpuinfo?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Gentoo on HTC Desire

    Prerequisites:
    • Rooted Desire
    • Any flavour of Linux (Live or installed)
      Code:
    • A decent sized MicroSD card (>2Gb recommended)
    • MicroSD USB adapter (or SD card reader and adapter)
    • Some knowledge of Linux command line and Gentoo is recommended
    • Patience...

    Things you should know first:
    • This is NOT a fully independent Linux - it runs parallel to Android inside a chroot environment
    • Some applications can be very slow until they are compiled properly for the Desire hardware
    • Compilation with a 1GHz single core CPU is slow
    • You can run just about any Linux program; X programs and desktop environments can be used via VNC
    • Many custom ROMs and kernels do not include swap support for performance reasons, and so if you require swap you may need to compile your own kernel (I will upload my custom kernel at a later date)
    • Due to Android security settings, only root can use the network. This causes some problems as anything that requires network access must run as root (again, if anyone has any insight for a way around this, please contact me)
    • Some ROMs underclock the CPU when the screen is off - this will lead to VERY long compilation times if you leave your phone like that

    Step one - Prepare MicroSD

    To install Gentoo you will need an ext2, 3, or 4 filesystem on your MicroSD card. This can be done two ways: partitioning your card (recommended), or by creating a file and creating the filesystem within that (not covered here).
    Start up GParted (or something similar) on your computer and insert your MicroSD card; if your card is fully allocated, you will need to shrink the existing partition(s) first (back up your data! This can go wrong...) and leave a space at the end of the card for your new partition. The absolute minimum I would recommend to dedicate to Gentoo would be 1GB, but that doesn’t give you much wiggle room and you will have a very hard time compiling anything big (like GCC); I would recommend making the partition >2GB. Make sure you create the Gentoo partition at the end of the card.

    Note:
    APP2SD+ requires its own partition - if you have it enabled, you must have at least three partitions, with the second partition on the card dedicated to it and the third for Gentoo.

    Due to the large number of files in the Portage tree, small partitions can sometimes run out of inodes. You can get around this by decreasing the size of the inodes and blocks, and therefore creating more:

    Code:
    ~ $ sudo mkfs.ext3 /dev/(partition) -i 2048 -b 2048

    Step two - install base system:

    Download the latest stage 3 tarball for armv7a-unknown-linux-gnueabi from the Gentoo mirror closest to you (Google "Gentoo Mirrors", I can't post links yet..), mount the Gentoo partition and extract the contents of the tarball to it.

    Example:
    Code:
    ~ $ wget (your selected mirror)/linux/gentoo/releases/arm/autobuilds/current-stage3/armv7a-unknown-linux-gnueabi/stage3-armv7a-20100917.tar.bz2
    ~ $ sudo mkdir /mnt/sd
    ~ $ sudo mount /dev/(partition) /mnt/sd
    ~ $ sudo tar xjvfp stage3-armv7a-20100917.tar.bz2 -C /mnt/sd/

    Download the latest portage snapshot (from the Gentoo mirror) and extract:

    Code:
    ~ $ wget (your selected mirror)/linux/gentoo/snapshots/portage-latest.tar.bz2
    ~ $ sudo tar xjvf portage-latest.tar.bz2 -C /mnt/sd/usr/

    Now modify the make.conf file using your favourite text editor:

    Code:
    ~ $ sudo nano /mnt/sd/etc/make.conf

    Sample make.conf:

    Code:
    CFLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=vfpv3 -O2" # if anyone has any suggestions to improving these, please let me know
    CXXFLAGS=${CFLAGS}
    CHOST="armv7a-unknown-linux-gnueabi"
    USE="unicode X -gnome -kde -firefox wifi syslog -udev -mdev -wifi -gpm threads nptl networking wxwidgets -ipv6 sqlite jpeg png dbus" # Have a look at the Gentoo USE flag description page on the web for others you may want/don't want
    VIDEO_CARDS="none"
    ALSA_CARDS="none"
    INPUT_DEVICES="none"
    SYNC="rsync://(your selected mirror)"
    GENTOO_MIRRORS="(your selected mirror)"
    ACCEPT_LICENSE="*"
    MAKEOPTS="-j1"
    PORTAGE_NICENESS="19"
    AUTOCLEAN="yes"
    FEATURES="noman nodoc noinfo -userfetch" # Getting rid of the man, doc and info pages saves a lot of space. Userfetch is disabled due to the issue described above
    PORTAGE_RSYNC_EXTRA_OPTS="--exclude ChangeLog" # Again, this saves some space

    Edit locale.gen with the locale values you require, e.g.:

    Code:
    en_US.UTF-8 UTF-8

    Unmount your MicroSD card and insert it back into your phone.

    Step three - configuring the base system

    Using ConnectBot, another terminal emulator app, or adb, connect to the local console and setup the mounts, then enter Gentoo (using busybox as your shell (type "busybox sh") is recommended as the tab completion (trackball + i in connectbot) helps a lot):

    Code:
    # mkdir /data/gentoo
    # mount -t ext3 (or whatever fs you set it to) /dev/block/mmcblk0p3 (change the 3 to whatever partition you need) /data/gentoo
    # mount -t proc none /data/gentoo/proc
    # mount -o bind /dev /data/gentoo/dev
    # mount -t devpts none /dev/pts
    # chroot /data/gentoo /bin/bash
    # source /etc/profile

    Congratulations! You are now inside your own Gentoo environment. If you don't need your phone for a while you can now recompile and update the system (this will take quite a long time and will use a lot of data). This doesn't have to be done now, or at all, but it is highly recommended to do so at some point:

    Code:
    # emerge -DuNav world

    Once that's done (or you don't want to do it), install some base programs:

    Code:
    # emerge -av screen sudo

    If you want VNC, tightvnc is recommended:

    Code:
    # emege -av tightvnc

    Web server:

    Code:
    #emerge -av nginx

    Set a root password:

    Code:
    # passwd

    For some reason running SSHD with IPv6 enabled causes the phone to restart. To fix this, make the following changes to /etc/ssh/sshd_config:

    Change:
    Code:
    #AddressFamily any
    To:
    Code:
    AddressFamily inet

    To start SSHD:

    Code:
    # ssh-keygen -t rsa (save to /etc/ssh/ssh_host_rsa_key with no passkey)
    # ssh-keygen -t dsa (save to /etc/ssh/ssh_host_dsa_key with no passkey)
    # /usr/sbin/sshd

    If your kernel supports swap, it is recommended to create and enable it:

    Code:
    # dd if=/dev/zero of=/swap bs=10M count=20 (change this to alter the size of the swap file)
    # mkswap /swap
    # swapon /swap (you will need to run this command with the other mount commands each time you boot)

    Boot script:
    Start your phone in recovery mode and mount /system using the partitions menu in your recovery ROM, then create a file on your computer with the following contents:

    Code:
    #!/system/bin/sh
    #
    #		Linux startup script for rooted Android systems 
    #		© Deathisfatal @ forum.xda-developers.com
    #
    #		TODO:
    #			-	Error handling
    #
    
    # Edit the following variables as required
    
    HOSTNAME="Android"
    LINUX="/data/gentoo/"
    BB="/system/xbin/busybox"
    CHROOT="${BB} chroot ${LINUX}"
    ROOT="/dev/block/mmcblk0p3"
    SWAP="/swap" 
    
    ${BB} mount -o noatime -t ext3 ${ROOT} ${LINUX} # Edit -t as required by your filesystem
    ${BB} mount -o bind /dev ${LINUX}dev
    ${CHROOT} /bin/mkdir /dev/shm
    ${CHROOT} /bin/mount -t tmpfs -o size=32m none /dev/shm
    ${CHROOT} /bin/mkdir /dev/fd
    ${BB} /bin/mount -o bind /proc/self/fd /dev/fd
    ${CHROOT} /bin/mount -t devpts none /dev/pts 
    ${BB} mount -t proc none ${LINUX}proc
    ${CHROOT} /sbin/swapon ${SWAP}
    ${CHROOT} /bin/mount -t tmpfs -o size=32m none /tmp
    ${CHROOT} /bin/mkdir /tmp/run
    ${CHROOT} /bin/mkdir /tmp/run/portage
    ${CHROOT} /bin/touch /tmp/run/utmp
    ${CHROOT} /bin/chmod 777 -R /tmp
    ${BB} mount -o bind /data ${LINUX}mnt/data
    ${BB} mount -o bind /sdcard ${LINUX}mnt/sd
    ${CHROOT} /bin/hostname ${HOSTNAME}
    
    # Uncomment the following line to enable sshd on boot
    #${CHROOT} /usr/sbin/sshd
    Connect your phone and computer with the USB cable, then use the following command on your computer:

    Code:
    ~ $ adb push (File you created earlier) /system/etc/init.d/05linux
    ~ $ adb shell chmod 755 /system/etc/init.d/05linux

    Now reboot your phone and your Gentoo partition should automatically mount.

    Notes:
    • If you restart your phone, you will need to issue the necessary mount commands as you did earlier until I (or someone else) get around to making a proper script that runs at boot time
    • For information on how to set up programs and servers on Gentoo visit the Gentoo wiki
    • Please contact me or post here with any questions you may have regarding this

    Changelog:
    • Updated CFLAGS and bootscript

    Thanks to sfjuocekr for his/her contributions.