Gentoo on an Android Part 1

So I actually moved from the iPhone to the Android. What lured me away was the Optimus 2x, which in the US is running on T-Mobile as the G2x. You can obviously google all the specs, but the dual core gave me hope of doing a little more with it than I could do with the iPhone. One of the first things I really wanted to get running was the Metasploit Framework. As oddly as it is, there is not a Ruby environment that runs on the Android that is capable of this (unlike the iPhone that has been running it since version 1). So instead of messing with Framework and Ruby to get it to work I decided to see if I could just setup Gentoo in a chroot setup.

So here we go. . .First thing we need to do is root the device. Obviously you should know what you are doing here, and warranty issues, blah blah blah. . .
I used SuperOneClick, and I will mention I am on the mac, and it went off without an issue. The link is to the Windows version, with the Linux/Mac version at the bottom.

So that is done, now we are going to install ROM Manager for two reasons. It will backup your ROM, and if you are lazy, it will partition your SD card for you. Here is a video I found, actually walks you through the partitioning. You will want to do the second way, in case you can’t figure that out.

So we have our phone rooted, we have our removable card partitioned. I bold removable because the way the G2x works with storage is a bit odd. The phone has internal storage that is mounted as an SD card too. So we will get into that in a second. Now we have to get access to the shell. You can actually do all this via a terminal app if you want, although that would be a pain. I actually started off using the Android SDK and specifically the adb tool that will start a shell. Then I actually just installed an SSH server from the app store, to make life even easier.

So we get into shell, su to root, and take a loot at the system. It all works pretty much the way you would think that it would, but this is where I noticed the SD card mount was a bit odd.

/dev/block/vold/179:17 /mnt/sdcard/_ExternalSD vfat rw,dirsync, nosuid, nodev, noexec, noatime, uid=1000, gid=1015, fmask=0002, dmask=0002, allow_utime=0020, codepage=cp437, iocharset=iso8859-1, shortname=mixed, utf8, errors=remount-ro 0 0

So you will notice the mount is actually under the sdcard mount, and also it calls it by device number instead of the traditional structure. You can get a bit clearer picture with this:

brw------- root root 179, 19 2011-05-03 01:12 mmcblk1p3
brw------- root root 179, 18 2011-05-03 01:12 mmcblk1p2
brw------- root root 179, 17 2011-05-03 01:12 mmcblk1p1
brw------- root root 179, 16 2011-05-03 01:12 mmcblk1

So we can see the card is currently mounted as a vfat and it is 179:17 which is mmcblk1p1. So what we can do to make sure everything is there is do an fdisk print of the device:

Disk /dev/block/mmcblk1: 15.9 GB, 15931539456 bytes
255 heads, 63 sectors/track, 1936 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/block/mmcblk1p1 1 1432 11496093+ c Win95 FAT32 (LBA)
/dev/block/mmcblk1p2 1432 1930 4000000 83 Linux
/dev/block/mmcblk1p3 1930 1937 62050 82 Linux swap

There is my linux partition, good ol 83. So i did a quick

mke2fs -j /dev/block/mmcblk1p2

Now the root file system is read only, so changed that so I could mount the partition directly.

mount -o rw,remount -t sysfs / /

Then made the mount point that I like

mkdir /mnt/gentoo

Mounted the partition I just made

mount /dev/block/mmcblk1p2 /mnt/gentoo

So if you are familiar with Gentoo that has your storage setup. You can actually pretty much continue on with the standard documentation from. There are some other things that I will show you in part 2 on the install if for some reason you get stuck somewhere.

OH, DO NOT START SSHD IN CHROOT YET
You have to go in and make a change to the /etc/sshd_config and change the AddressFamily value to inet. If set to AddressFamily all or not set at all, it will kill the phone and force a reboot when you try to start up the SSHd service.