Nobiscuit

Above average nerdiness

Cross-compiling Debian armel using LXC on Ubuntu 12.04

I’ve previously struggled to find a reliable way of building packages on my ubuntu laptop for my ix2-200 running squeeze. I’ve tried scratchbox/scratchbox2 in various configurations, and although it will work for some packages, not all packages work all the time, and I usually end up fiddling with scratchbox 2 settings/scripts/modes to make it work or using a native qemu session.  The problems seem to be related to running scratchbox 2 directly on Ubuntu and thus which native tools that scratchbox 2 tries to use.

Recently my wife got a MacBook Air and so she needs a TimeMachine compatible system to back it up to if she wants to do so over the network. This means I needed to get the netatalk package working on one of my ix2-200s, but because the latest version of MacOS X requires AFP 3.3 support for TimeMachine, I needed 2.2.x rather than the 2.1.x that is currently available in squeeze. At the same time, I was also having a play with LXC that comes with Ubuntu 12.04 and lets you set up lightweight Debian and Ubuntu containers for process isolation etc. so I decided to see if I could get a reliable cross-compile environment going for this. I’m happy with the results and l like how I there is no dependency on packages installed in the underlying OS, although there are probably better ways to do it using tools directories and one of the other scratchbox modes.

The first step is to install LXC and create a Debian Squeeze container:

apt-get install lxc
lxc-create -t debian -n build
lxc-start -n build /sbin/init -d
lxc-console --name build

Once logged into the console (using the root account and password that it tells you in the output to lxc-create), you can then install all the required packages to run scratchbox. I use scratchbox2 and qemu from testing as well as the emdebian toolchain from its own repo, as the stable stuff is just a bit old, so I need to create the right APT preferences.

To enable the testing and emdebian repos, put the following in /etc/apt/preferences.d/10testing. I used cat to do this, because vi wasn’t installed:

Package: *
Pin: release a=stable
Pin-Priority: 900

Package: *
Pin: release o=Debian
Pin-Priority: -10

Put the following in /etc/apt/apt.conf.d/10testing:

APT::Default-Release "stable";

Edit your “/etc/apt/sources.list” and add this

deb http://cdn.debian.net/debian testing main
deb-src http://cdn.debian.net/debian/ testing main

deb http://security.debian.org/ testing/updates main
deb-src http://security.debian.org/ testing/updates main

deb http://www.emdebian.org/debian/ squeeze main

Install the emdebian keychain to avoid unauthorised packages:

apt-get update
apt-get install emdebian-archive-keyring
apt-get update

Then install the packages needed for cross compiling, including scratchbox2 and qemu-user which we will reinstall later:

apt-get install gcc-4.4-arm-linux-gnueabi build-essential cdbs hardening-includes libcrack2
apt-get install scratchbox2 qemu-user libavahi-client-dev gcc-multilib autoconf realpath debootstrap sudo

Install qemu-user and scratchbox2 from testing:

apt-get -t testing install qemu-user scratchbox2

Install the build dependencies for netatalk, otherwise sb2 in simple mode won’t find all the files required to build netatalk:

apt-get build-dep netatalk

At this point you want to create a normal user for youself with access to sudo to continue the rest of the setup:

adduser <username>
adduser <username> sudo

Once you’ve logged in as your new user, initialise the sb2 environment in their home directory.

mkdir debian && cd debian
sb2-init -n -c /usr/bin/qemu-arm debian arm-linux-gnueabi-gcc
fakeroot /usr/sbin/debootstrap --variant=scratchbox --foreign --arch armel squeeze ~/debian http://cdn.debian.net/debian/
sb2 -eR debootstrap/debootstrap --second-stage

Create the new sources.list in ~/debian/etc/apt/sources.list:

deb http://mirror.internode.on.net/pub/debian/ squeeze main
deb-src http://mirror.internode.on.net/pub/debian/ squeeze main

deb http://security.debian.org/ squeeze/updates main
deb-src http://security.debian.org/ squeeze/updates main

Update the apt database and install the dependencies for building netatalk:

sb2 -eR apt-get update
sb2 -eR apt-get install libavahi-client-dev # this is missing from the dependencies in the testing netatalk source package
sb2 -eR apt-get build-dep netatalk

You will get an error because dbus fails to install, but you can just go ahead and remove it:

sb2 -eR apt-get remove dbus

Now retrieve the source for netatalk in another directory:

cd ~
apt-get source -t testing netatalk
cd netatalk-2.2.2
sb2 dpkg-buildpackage -rfakeroot -b -d -uc -us

And that’s it! There are plenty of other sites out there on how to configure netatalk for TimeMachine, so I’ll leave that as an exercise for the reader.

Advertisements

5 responses to “Cross-compiling Debian armel using LXC on Ubuntu 12.04

  1. Alan July 18, 2012 at 8:04 am

    I was just wondering if you could help me with a problem im haveing with my ix2-200 any kernel after the 3.3.7 kernel keeps crashing when i use git or java and possibly other programs but those 2 i have noticed most. ever when connected through serial as soon as i run git clone…(insert whatever here) on the nas it just stops no output just frozen or crashed. would you have any ideas why it would be doing that?

    • nigelr July 18, 2012 at 10:40 pm

      Hi Alan, sorry, no idea – have you tried rolling back to a previous stable kernel?

      • Alan July 19, 2012 at 12:38 am

        thanks and yeah i have to go all the way back to kernel 3.3.7 and everything works fine so it has to be sumthing wrong with the kernels. and the 3.5 rc kernels wont boot they get stuck looking for the root drive. have you tried or had any luck with them?

        just thaught i would ask here as you seem to be the only one doing work on the ix2-200 and not the goflex net’s and stuff. i am also working on cross compileing an arch linux kernel for the ix2-200 aswel just to see how it goes but cant get that to boot yet either.

  2. Andrew Tennenbaum January 17, 2014 at 2:30 am

    Just out of curiosity, what is the advantage of this over using a chroot?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: