Development environment

Please note that my blog has moved to:


It became clear to me after playing around with Raspbian that I would need to compile my own software and/or Debian packages. Raspbian is new project and is still getting its feet off the ground.

Compiling on the R Pi itself is slow, it takes an hour to compile Quake3 and about 12 hours to compile XBMC, so I decided to compile on my desktop PC. The problem is that my desktop is running Ubuntu 12.04 i386 and my Pi is running Raspbian for armhf.

I’ve never created a Debian chroot before and I’ve never created one that runs on a different architecture to the native PC. So after some googling I found this wiki page.

I used that as a base to create my own chroot that can cross-compile for armhf. Here are instructions for Ubuntu 12.04 i386:

Installing QEMU

In order to compile for a different architecture then we are currently running on we need an emulator. We will use QEMU for this:

apt-get install qemu-user-static

Creating the chroot

Create the chroot (using qemu-debootstrap) and mount some needed filesystems:

sudo apt-get install debootstrap
sudo qemu-debootstrap --arch armhf wheezy chroot-raspbian-armhf
sudo mount -t proc proc chroot-raspbian-armhf/proc
sudo mount -t sysfs sysfs chroot-raspbian-armhf/sys
sudo mount -o bind /dev chroot-raspbian-armhf/dev

Remember that is as minimal as a distro can get, you need to set up everything yourself from here, including adding a user and the applications you need.

Edit: Updated this section to use qemu-debootstrap. This handles the qemu binary and debootstrap –second-stage all for you.

Changing to the chroot

Now that you have everything setup, you can change to your chroot with:

sudo LC_ALL=C chroot chroot-raspbian-armhf

Some setting up

Now that you have the environment, you may need to do some house cleaning to get things running smoothly.

Adding a user

useradd -m -s /bin/bash <username>

Setting up reposatory and adding Raspbian GPG key

In order to install packages from the Raspbian repo, you need to add the repo to sources.list and grab the GPG key:

echo "deb wheezy main" >> /etc/apt/sources.list
wget -O - | apt-key add -
apt-get update

VideCoreIV userspace libs

You may need to fetch the libraries for VideoCoreIV for hf, these live here:


Note that some of these changes won’t survive a reboot. You will need to run the following should you reboot your desktop:

sudo mount -t proc proc chroot-raspbian-armhf/proc
sudo mount -t sysfs sysfs chroot-raspbian-armhf/sys
sudo mount -o bind /dev chroot-raspbian-armhf/dev
This entry was posted in Uncategorized. Bookmark the permalink.

8 Responses to Development environment

  1. sjaak says:

    Thanks for the guide, but I believe you’re missing a step.
    After chrooting for the first time, you should run “./debootstrap/debootstrap –second-stage” to finish configuring the packages.

  2. Andrew says:

    @sjaak: debootstrap doesn’t seem to be in the minimal package list installed by debootstrap so I had to run “apt-get install debootstrap” (in the chroot) first, then, contrary to the man page, it seems to need the suite name with the switch, so the command seems to be “debootstrap wheezy –second-stage”. apt-get moans less if you get the GPG key first too, as described above.

  3. Andrew says:

    Please disregard my last response, I believe it would result in a mixed up system (not least because it seems to pull a bunch of packages from the main Debian ftp mirror). On further research it seems that to get the ./debootstrap/debootstrap file the original debootstrap should be run with the “–foreign” switch, but further investigation seems to be required. Online sources seem a little vague as to whether the second stage is even required if the “–foreign” switch wasn’t supplied to the call to debootstrap.

    • sjaak says:

      I forgot to mention that in my post, you indeed need the ‘–foreign’ option, see the manpage:

      Do the initial unpack phase of bootstrapping only, for example if the target architecture does not match the host architecture. A copy of deboot-
      strap sufficient for completing the bootstrap process will be installed as /debootstrap/debootstrap in the target filesystem. You can run it with
      the –second-stage option to complete the bootstrapping process.

      Then after copying the qemu-arm-static binary you can chroot and run ‘./debootstrap/debootstrap –second-stage’.

  4. adrianmoisey says:

    I had a look at the second-stage and I couldn’t get it to work for some reason.
    What I did discover was qemu-debootstrap, running this will handle the qemu-arm-static and debootstrap –second-stage all for you:
    sudo qemu-debootstrap –arch armhf wheezy chroot-raspbian-armhf

  5. Cyberspice says:

    You don’t need an emulator to cross compile for different architectures. I do it all the time just from my native Linux install. I’m an embedded software engineer by trade.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s