Gentoo chroot on Nokia N900

LMAX Exchange

While I was waiting for my Raspberry Pi to arrive, I decided to put my
Nokia N900 for a better use and create a Gentoo chroot on the SD card to
give the hardened ARM toolchain a go. For the record, I found these two links to be particularly useful when working on the chroot.

N900
is not the fastest arm board out there, but it was the only ARM board I
had at hand…Anyway, creating Gentoo chroot on N900 is quite simple
actually. First you need to create a spare partition, or two if you want
to use swapping space, which is probably a good idea, given my plan to
re-compile the toolchain natively. 🙂

I also decided to leave
some space on the SD for the N900 itself, ( apparently it’s also a good
way of shutting it up as it tries to mount the card anyway ), so I ended
up with three partitions:

Disk /dev/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/mmcblk1p1 1 974 7823623+ 83 Linux
/dev/mmcblk1p2 975 1097 987997+ 83 Linux
/dev/mmcblk1p3 1098 1936 6739267+ 83 Linux

The
first partition is left for the N900 as a FAT filesystem, the second
one will be our Gentoo chroot and the 3rd is swap space. ( I wonder how
quickly the card will die by the way ;)). Now you need to decide where
you are going to put your Gentoo chroot for instance in
/home/user/MyDocs/Gentoo and create that folder so your new partition on
the SD card can be mounted there (but we need to format it first).

mkdir /home/user/MyDocs/Gentoo
mkfs.ext2 /dev/mmcblk1p2
mkswap /dev/mmcblk1p3
mount /dev/mmcblk1p2 /home/user/MyDocs/Gentoo

With
the correct card setup in place, the next thing is to get a Gentoo
stage for the arm achitecture, which you can get from the gentoo.org
site. The N900 is a ARMv7 board and you can use the hardfp stages. Untar
it in your chroot folder:

tar -jxpf stage3-*.tar.bz2

After mounting few additional folders, we can jump in to our new Gentoo environment, so mount first:

mount -o bind /dev /home/user/MyDocs/Gentoo/dev
mount -o bind /dev/pts /home/user/MyDocs/Gentoo/dev/pts
mount -o bind /dev/shm /home/user/MyDocs/Gentoo/dev/shm
mount -o bind /proc /home/user/MyDocs/Gentoo/proc
mount -o bind /sys /home/user/MyDocs/Gentoo/sys
mount -o bind /tmp /home/user/MyDocs/Gentoo/tmp

Note that the mounting of /dev/pts will allow you to run the screen command within the chroot which will come handy later…

Now for the chroot itself:

chroot /home/user/MyDocs/Gentoo/ /bin/bash
env-update
source /etc/profile
export PS1="(chroot) $PS1"

Done!
It’s probably a good idea to put the ‘mount’ commands along with the
‘chroot’ into a shell script somewhere on the N900 so you can run it
again quickly after restarting the phone.

N900 / # eselect profile list
Available profile symlink targets:
[1] default/linux/arm/10.0 *
[2] default/linux/arm/10.0/desktop
[3] default/linux/arm/10.0/desktop/gnome
[4] default/linux/arm/10.0/desktop/kde
[5] default/linux/arm/10.0/developer
[6] default/linux/arm/10.0/server
[7] default/linux/arm/10.0/armv4
[8] default/linux/arm/10.0/armv4/desktop
[9] default/linux/arm/10.0/armv4/desktop/gnome
[10] default/linux/arm/10.0/armv4/desktop/kde
[11] default/linux/arm/10.0/armv4/developer
[12] default/linux/arm/10.0/armv4/server
[13] default/linux/arm/10.0/armv4t
[14] default/linux/arm/10.0/armv4t/desktop
[15] default/linux/arm/10.0/armv4t/desktop/gnome
[16] default/linux/arm/10.0/armv4t/desktop/kde
[17] default/linux/arm/10.0/armv4t/developer
[18] default/linux/arm/10.0/armv4t/server
[19] default/linux/arm/10.0/armv5te
[20] default/linux/arm/10.0/armv5te/desktop
[21] default/linux/arm/10.0/armv5te/desktop/gnome
[22] default/linux/arm/10.0/armv5te/desktop/kde
[23] default/linux/arm/10.0/armv5te/developer
[24] default/linux/arm/10.0/armv5te/server
[25] default/linux/arm/10.0/armv6j
[26] default/linux/arm/10.0/armv6j/desktop
[27] default/linux/arm/10.0/armv6j/desktop/gnome
[28] default/linux/arm/10.0/armv6j/desktop/kde
[29] default/linux/arm/10.0/armv6j/developer
[30] default/linux/arm/10.0/armv6j/server
[31] default/linux/arm/10.0/armv7a
[32] default/linux/arm/10.0/armv7a/desktop
[33] default/linux/arm/10.0/armv7a/desktop/gnome
[34] default/linux/arm/10.0/armv7a/desktop/kde
[35] default/linux/arm/10.0/armv7a/developer
[36] default/linux/arm/10.0/armv7a/server
N900 / # uname -a
Linux
N900 2.6.28.10-power50 #1 PREEMPT Sun Mar 18 20:10:56 EET 2012 armv7l
ARMv7 Processor rev 3 (v7l) Nokia RX-51 board GNU/Linux

Next
step – making the chroot environment a Gentoo Hardened environment of
course! ;] We will have to create a hardened toolchain first, but that’s
a story for the next post 🙂

Any opinions, news, research, analyses, prices or other information ("information") contained on this Blog, constitutes marketing communication and it has not been prepared in accordance with legal requirements designed to promote the independence of investment research. Further, the information contained within this Blog does not contain (and should not be construed as containing) investment advice or an investment recommendation, or an offer of, or solicitation for, a transaction in any financial instrument. LMAX Group has not verified the accuracy or basis-in-fact of any claim or statement made by any third parties as comments for every Blog entry.

LMAX Group will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information. No representation or warranty is given as to the accuracy or completeness of the above information. While the produced information was obtained from sources deemed to be reliable, LMAX Group does not provide any guarantees about the reliability of such sources. Consequently any person acting on it does so entirely at his or her own risk. It is not a place to slander, use unacceptable language or to promote LMAX Group or any other FX and CFD provider and any such postings, excessive or unjust comments and attacks will not be allowed and will be removed from the site immediately.