Thursday, 21 June 2012

Gentoo chroot on Nokia N900

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 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
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 #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 :)

No comments:

Post a Comment

Have your say: