Install Debian Wheezy on your Banana Pi

Update: Before wasting a lot of time, you might want to take a look at http://www.bananian.org. The guide is being kept for legacy reasons.

I just got myself a Banana Pi today and was unsatisfied with the selection of prebuilt images, so I dove into some chinese websites with the help of google chrome translate and figured out how to get „quite a vanilla“ debian installation.

Prerequisites

I am assuming you are running Ubuntu or Debian on your desktop (or vitual machine), if not, you might be aware how to use your distribution to get the same result. If you are unsure, you can also try running Ubuntu from the LiveDVD.

You will need the kernel provided by the banana people. You can download the requred files here (http://files.cbwebs.de/banana_pi/fat_content.tar.bz2), since the original mirror in China is horribly slow. The files have been taken from Baidu (original source).

Elevate yourself to root in a terminal session, since we are doing a lot of things that require root:

$ sudo /bin/bash

Install required packages

To install Debian into a directory, we need debootstrap. For chrooting into the arm environment, we also need qemu to be present within that environment. Install the required packages by issuing:

$ apt-get install qemu-user-static binfmt-support debootstrap

Prepare your SD card

Find out where your SD card resides, you can do that by issuing:

$ fdisk -l

In my case, the device is named /dev/mmcblk0 – it could also be /dev/sdx on your system. Please use your device instead of mmcblk0 which is used in this guide.

The chinese guide suggests to overwrite the first MB of the card with zeros and then copying some .bin file to it.

$ dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=1
$ dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

You will now have to create 2 partitions on the SD card, start fdisk

$ fdisk /dev/mmcblk0

and create two primary partitions, one with 20M and one over the rest. Create a vfat filesystem on the first and and an ext4 on the second partition

$ mkfs.vfat /dev/mmcblk0p1
$ mkfs.ext4 /dev/mmcblk0p2

Copy script.bin and uImage file to the FAT partition

$ mount /dev/mmcblk0p1 /mnt
$ cp script.bin /mnt
$ cp uImage /mnt/
$ umount /mnt

Install Debian using debootstrap

Mount the ext4 partition and execute debootstrap

$ mount /dev/mmcblk0p2 /mnt
$ debootstrap --arch=armhf --foreign wheezy /mnt

We are one step ahead of chrooting into your debian environment, but before we can proceed, we need to copy two files from our host system:

$ cp /usr/bin/qemu-arm-static /mnt/usr/bin/
$ cp /etc/resolv.conf /mnt/etc
$ chroot /mnt
$ export LANG=C

We can now proceed the debootstrap process with:

$ /debootstrap/debootstrap --second-stage

Once that’s finished, we can setup apt, the package manager of debian, this copy and paste snippet might come in handy:

cat <<EOT > /etc/apt/sources.list
deb http://ftp.uk.debian.org/debian wheezy main contrib non-free
deb-src http://ftp.uk.debian.org/debian wheezy main contrib non-free
deb http://ftp.uk.debian.org/debian wheezy-updates main contrib non-free
deb-src http://ftp.uk.debian.org/debian wheezy-updates main contrib non-free
deb http://security.debian.org/debian-security wheezy/updates main contrib non-free
deb-src http://security.debian.org/debian-security wheezy/updates main contrib non-free
EOT

cat <<EOT > /etc/apt/apt.conf.d/71-no-recommends
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOT

Update your latest database from the debian servers:

$ apt-get update

And set your locales:

$ apt-get install locales dialog
$ dpkg-reconfigure locales

Install some useful packages inside the chroot

$ apt-get install openssh-server ntp

Set a root password so you can login

$ passwd

Build a basic network interface file so that the board will have a predictable IP address on eth0. DHCP might be an option for you, but it didn’t work out of the box for me.

echo <<EOT >> /etc/network/interfaces
auto eth0
iface eth0 inet static
 address 192.168.1.103
 netmask 255.255.255.0
 gateway 192.168.1.1
EOT

Set the hostname

$ echo localhost > /etc/hostname

We are done inside the chroot, so quit the chroot shell. You might need to stop the sshd deamon

$ /etc/init.d/ssh stop
$ exit # (or press crtl+d)

Tidy up the support files

We are finished setting up your debian and can now tidy up the card.

$ rm /mnt/etc/resolv.conf
$ rm /mnt/usr/bin/qemu-arm-static
$ umount /mnt

You’re done (almost)

You can now remove your SD card, put it into your Banana Pi and boot it. You should reach your login prompt and it should be available via SSH. Unfortunately you are now within a system with a prebuilt kernel without it’s corresponding modules.

Installing your own kernel

For information how to build your own kernel for the Allwinner A20, visit: http://linux-sunxi.org/Linux_Kernel. It explains how to create your own uImage and modules. The networking driver to use is sunxi_gmac – by default it will compile it as a module so you have to load it on startup by putting it into /etc/modules

Have fun!

28 Gedanken zu „Install Debian Wheezy on your Banana Pi“

  1. Hello Christian,
    thanks a lot for your guide!

    Everything words fine in the beginning, including copying qemu-arm-static and resolv.conf to the SdCard.

    But then, unfortunately, i keep on getting a seg fault when i try chrooting the /mnt directory.
    It says:
    qemu: fatal: cp15 insn ee1d7f70
    plus a reg dump

    Do you have any idea how i could fix this?
    Would downloading a newer version of the fat_content fix the problem, and if so, where can i download it?

    Thanks a lot in advance!
    Al

  2. Hi Albert

    that is correct. In order to be able to chroot inside an environment with a different CPU architecture, you need then qemu binary that works „out of the box“.

    From your first comment, it seemed like you installed a non-static qemu (with shared libraries) which are not available within the chrooted environment.

    As you stated in your second comment, using a static binary (from any source that works for you) is the solution to get that working.

      1. Sorry about your BPI, bud nice job with the Debian image. Can you please recommend some way how to use all space on 8G SD card. I tried fdisk delete second partition and create a new one but I failed.

  3. $ dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=1
    $ dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

    my mmcblk0 is sdc and I have replaced, but no partition had been added!

    HOW CAN I DO?

    TNX

    1. Please don’t use ALL CAPS when commenting on a blog. It looks ugly and comes off as rude.

      As for your question. You need to invoke fdisk and create the partitions yourself. Please see

      man fdisk

      if you need any help with that.

  4. Banana Pi with SATA disk, works fantastic.
    Kernel 3.4.90, is this the latest?
    I need the snd-aloop.ko module to get RTL_SDR
    to talk to WSJT. (via loopback)
    As in, I have an RTL2832 USB TV card. The Software
    Defined Radio app (rtl_sdr) works. can output sound.
    I want this sound piped to a ham radio app WSJT.
    And, with x86 linux kernels at 3.15+, why are the ARM kernels
    so far behind?
    – Alan

  5. Hi,

    thank you for the guide!
    One question is left: How can I connect USB-HDDs? They are not recognized by the basic installation …

    Thanks in advance

    Sebastian

  6. Hi Christian,

    thx for your great guide.
    One (two) question though: script.bin is any *.bin or the one that CH manufactures „suggest“ to use? What about this file, is it clean ?

    Thanks,
    Karlo

    1. Since it is binary code, I have no clue about the cleanlieness of the file. However, if Lemaker wanted to inject malicious behaviour into ther boxes, they could also have done it on hardware level – so I wouldn’t worry too much. You can still try to download the file from it’s original source.

  7. Hi,

    can I ask you something ?
    How is the Bananian worser that the full Wheezy version, Waht is the difference. I know, Bananian is a lightweight version of Debian, but when I install all the missed packages, whould I get a full Debian at the end ?

    Thank you and sorry for the rookie question.

    Best regards,
    Nico

    1. Unfortunately, I had to stop providing support for the Banana Pi. Lemaker offered to supply some boards but never did, so I did not keep track between the different versions, nor did I keep track of the development of the board.

      I spoke with the maintainer of bananian for a brief period, and it seems like he has done quite a good job in making the process as easy as possible. You might want to prefer bananian over this guide.

  8. „The chinese guide suggests to overwrite the first MB of the card with zeros and then copying some .bin file to it.“

    what is script.bin ? is it clean ? why chinese want this particular code to be at the first sectors of the partition ?

    just curious …

      1. Hello.

        I loved your guide! Thanks!

        If you don’t mind me asking some questions:
        1. Does the Banana Pi uses the CVBS output (yellow RCA) by standard? I don’t have a HDMI display, want to use it through CVBS.
        2. Since the Banana Pi uses a AllWinner A20, could we use the u-boot-sunxi free bootloader to boot the machine, instead of the closed source file you mentioned?
        3. Do you know if Bananian uses blobs in their build image or not? I am trying to build a system without blobs (non-free software, be it apps codecs drivers or firmware). I am aware that right now there is no free GPU/VPU, but there are open source drivers being developed so I can wait 🙂
        4. Following your guide, would it also work if we choose only „main“ instead of „main contrib non-free“? Same reason as above.

        Thank you again for a great guide and hope you can clarify some of my doubts 🙂
        Keep up the good work.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.