Mikko Kortelainen

Scratchbox installation under 32-bit chroot on 64-bit Ubuntu

I wanted to try out the Maemo SDK for Nokia 770, N800 and N810 devices (for some reason I happen to own one of every generation), but found out that there are no prebuilt packages for the 64-bit environment. The quick (?) remedy for this is the chroot jail, because a guest i386 environment can pretty easily be bootstrapped inside a 64-bit one. Here are the step-by-step instructions for doing it.


Setting up the chroot jail for Scratchbox

The first thing to do is setting up a chroot environment with 32-bit binaries. This can be achieved nicely with schroot and debootstrap, which can be found in the Debian Universe. Debootstrap will download and install a basic Debian system into a directory. In this case, we will install Ubuntu Gutsy i386 under /ubuntu32:

root@T60:/# apt-get install schroot debootstrap
root@T60:/# mkdir /ubuntu32
root@T60:/# debootstrap --arch i386 gutsy /ubuntu32
I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
.
.
.
root@T60:/# chroot /ubuntu32

That last command will actually chroot you into the directory /ubuntu32. What that means in practise is that your new root directory will be in fact /ubuntu32, and your new shell will be restricted under that directory. In effect, what you see as the root directory / will in reality reside under /ubuntu32. There is no easy way to see whether you're inside a jail or not, and the purpose of this is of course to trick programs into thinking they are running on another system. To escape the chroot jail, just say exit.

The newly bootstrapped system is very bare. Indeed there is no locale support until you install it. That should probably be the first thing to do. My locale is Finnish, so I will install the language-pack-fi package. After that, let's install the Nano editor, and edit our Apt sources:

root@chroot:/# apt-get install language-pack-fi
root@chroot:/# apt-get install nano
root@chroot:/# nano -w /etc/apt/sources.list

I make the sources.list look like this:

deb http://archive.ubuntu.com/ubuntu gutsy main restricted universe multiverse

A couple more things to do before our chroot is ready. We must set up user accounts and mounts. If you are happy running as the root user, there is no need to do anything, but I wanted to add an account for myself. The easiest way is to copy all necessary information from your existing /etc outside the chroot:

root@T60:/etc# cp passwd shadow group gshadow sudoers hosts resolv.conf /ubuntu32/etc/

That way your password, groups and all other settings are preserved without problems. You can add that command to cron if you want them synchronized automatically.

Next, you need to mount a couple of filesystems to make things go smoothly. Such are /proc, /sys and /dev, and also possibly /home and /tmp. The first three are needed for correct operation of many programs, while the latter two will ease your use of the chroot environment.

The create the mounts, add these lines to the /etc/fstab OUTSIDE the chroot (your normal fstab):

# chroot binds:

/home  /ubuntu32/home   none   bind     0 0
/tmp   /ubuntu32/tmp    none   bind     0 0
/dev   /ubuntu32/dev    none   bind     0 0
proc   /ubuntu32/proc   proc   defaults 0 0
sysfs  /ubuntu32/sys    sysfs  defaults 0 0

I mounted them right away with the mount -a command.

The last thing to do is make the chroot accessible for the general user. This is where schroot comes into play. It's purpose is to make normal users able to chroot themselves into jails predefined by root. Let's add a chroot jail into /etc/schroot/scroot.conf:

[ubuntu32]
description=Gutsy Gibbon i386
location=/ubuntu32
users=mkortela
aliases=scratchbox,default

Now, user mkortela is able to chroot into our new environment:

mkortela@T60:~$ schroot ubuntu32
I: [ubuntu32 chroot] Running login shell: '/bin/bash'
mkortela@T60:~$

Now we are in the chroot jail as ourselves, and able to sudo as we were outside the jail. Also, the user's home directory is right where it is supposed to be. To remember we are inside the chroot, it may be a good idea to change the prompt a little bit:

mkortela@T60:~$ export PS1='${debian_chroot:+($debian_chroot)}u@chroot:w$ '
mkortela@chroot:~$

Scratchbox installation inside the chroot jail

The Scratchbox installation will go pretty much like described in the INSTALL.txt. There are a couple of extra tweaks, though. First, lets fetch the installation scripts, and run them. First the Scratchbox installation, then the SDK installation. The installation scripts will have to be cheated with the linux32 command:

mkortela@chroot:~$ sudo apt-get install wget
mkortela@chroot:~$ wget http://tablets-dev.nokia.com/4.0/maemo-scratchbox-install_4.0.sh
mkortela@chroot:~$ wget http://tablets-dev.nokia.com/4.0/maemo-sdk-install_4.0.sh
mkortela@chroot:~$ chmod a+x maemo-scratchbox-install_4.0.sh
mkortela@chroot:~$ chmod a+x maemo-sdk-install_4.0.sh
mkortela@chroot:~$ linux32 sudo ./maemo-scratchbox-install_4.0.sh
.
.
.
Installation was successful!
----------------------------

You now have Scratchbox 1.0.8 'apophis' release installed.

Scratchbox cannot be run as user root. Instead, use your normal login
user account. Add additional scratchbox users and sandboxes with the
following command (outside scratchbox with root permissions):

        # /scratchbox/sbin/sbox_adduser USER yes

Running this command will create sandbox environment for that user and
add user to the 'sbox' scratchbox user group.
You will need to start a new login terminal after being added to the
'sbox' group for group membership to be effective.

Login to scratchbox session using the following command (as user):

        $ /scratchbox/login

Refer to scratchbox.org documentation for more information re scratchbox:
http://scratchbox.org/documentation/user/scratchbox-1.0/

Let's do what they ask:

mkortela@chroot:~$ sudo /scratchbox/sbin/sbox_adduser mkortela yes
Adding user `mkortela' to group `sbox' ...
Done.
Scratchbox user account for user mkortela added

And let's create the group outside the chroot and add ourselves there as well:

root@T60:/# groupadd -g 1001 sbox
root@T60:/# usermod -a -G sbox mkortela

And now, the SDK installation:

mkortela@chroot:~$ linux32 ./maemo-sdk-install_4.0.sh

I installed with the default options, although I decided to download the non-free Nokia packages as well.

Installing and running Xephyr

Xephyr can be installed directly from the universe. We will install it outside the chroot environment, because that's where all our X libraries and fonts are:

root@T60:/# apt-get install xserver-xephyr

Let's check that it runs as a regular user:

mkortela@T60:~$ Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -extension Composite

You should get a Window with a simple X session (just the default boring wallpaper and nothing else). To start the Maemo default programs in it, open another shell window, go inside the chroot, and run:

mkortela@chroot:~$ sudo /etc/init.d/scratchbox-core start
mkortela@chroot:~$ sb-conf select CHINOOK_X86
mkortela@chroot:~$ scratchbox
[sbox-CHINOOK_X86: ~] > export DISPLAY=:2
[sbox-CHINOOK_X86: ~] > af-sb-init.sh start

You should be able to see a very basic Maemo session, similar to the one shown in the Maemo 4.0 Tutorial. That document is also a good place to continue from here on.