Gentoo chroot on Nokia N900

2012-06-21
3 min read

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 bytes255 heads, 63 sectors/track, 1936 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice 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/Gentoomkfs.ext2 /dev/mmcblk1p2mkswap /dev/mmcblk1p3mount /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/devmount -o bind /dev/pts /home/user/MyDocs/Gentoo/dev/ptsmount -o bind /dev/shm /home/user/MyDocs/Gentoo/dev/shmmount -o bind /proc /home/user/MyDocs/Gentoo/procmount -o bind /sys /home/user/MyDocs/Gentoo/sysmount -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/bashenv-updatesource /etc/profileexport 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 listAvailable 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/serverN900 / # uname -aLinux 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 :)