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.
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
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