----------------------------------------------------------------------[ Meta ]--
description Banana Pi M2+EDU Resources
tags kb bananapi arm debian m2p blog bpi
creation 2017/03/31 16:21:44
copyright Copyright (c) 2017 Ma_Sys.ma.
For furhter info send an e-mail to Ma_Sys.firstname.lastname@example.org.
------------------------------[ Introduction: Debian on the Banana Pi M2+EDU ]--
- Github repository for Debian + Armbian Kernel
- Github repository for Debian + Vendor Supplied Legacy Kernel
- Website URL
(!) WARNING (!)
While the scripts presented here have all ben run at some time, their
most recent release was not tested thoroughly yet. Be aware that there
might be simple errors like e.\,g. syntax errors in there, resulting from
too little testing. If you discover such a thing, do not hesitate to
send an e-mail to `Ma_Sys.email@example.com`.
The Banana Pi M2+EDU is a cheap ARM board supporting Gigabit Ethernet.
This article describes means of getting to run Debian (and Docker) on the
Banana Pi M2+EDU.
Debian is the OS used for all Ma_Sys.ma computers and thus it seemed to be
a good idea to attempt to get to run an unmodified Debian on the Banana Pi
M2+EDU as well.
This proved to be difficult and thus, some minor modifications were accepted
in the end. Still, the result is closer to a
stock'' Debian compared to
most other approaches.
The necessity for a recent kernel
The first approach was to use the vendor-supplied tools in addition to
debootstrap-created Debian root directory (cf. section
Debian + Vendor Supplied Legacy Kernel'').
This proved unable to run Docker and was thus
replaced by the approach presented inDebian + Armbian Kernel''.
These solutions to
Debian on the Banana Pi M2+EDU'' currently exist:
- Debian-Images from the official\ website(
http://www.banana-pi.org/m2plus-download.html): These images are
larger than necessary and only available with old kernels.
Also, it is a bit unclear how those images can be created/customized.
These images are of good quality and best if you want an image
optimized for the ARM platform. They are, however, heavily customized and
as of this writing, there is no Debian + recent Kernel.
If one is looking for an easy solution, the armbian-Images can be recommended.
The following sections present an approach which comes closer to an
unmodified Debian and allows maximum control over the packages present in
All of the approaches presented here, as well as the armbian images, work
with microSD cards of any size (tested for 128 GB).
------------------------------------[ Debian + Vendor Supplied Legacy Kernel ]--
This approach produces an image suited for a microSD card which contains
a Debian installation equipped with the officially supplied Banana Pi
M2+ kernel. This supports HDMI and Gigabit Ethernet but is based on a kernel
3.4.39 and thus too old to run Docker.
First, clone the repository as follows:
git clone https://github.com/m7a/bpi-m2p-legacy-kernel
Configuration is similar to the appraoch presented in section
Debian + Armbian Kernel'', but there is nohack'' needed. Also, an
additional variable called
MA_HOOK_PREPARE is available:
Contains code to be executed for preparation (e.g. providing
.tar.xz files). This is set to
true) if not used.
Be aware that unlike
Debian + Armbian Kernel'', this approach creates _four_
containers which exchange intermediate results in form of `.tar.xz`-files.
External resources are downloaded instep 0'' if not already present in
To run the build, use
make as described in section
Debian + Armbian Kernel''. It makes sense to use
make -j10 ... (or a
larger number if you want to use more processes) to parallelize kernel
and u-boot compilation.
Partition the microSD card as follows:
_100 MiB of leading free space 50 MiB of FAT32 storage (label=BPI-BOOT, flags=lba, boot) XX MiB of EXT4 storage (label=BPI-ROOT) 1024 MiB of SWAP storage
Hint: To backup & restore the partition layout, use
sfdisk as follows
sfdisk -d /dev/sdj > file
sfdisk /dev/sdj < file
- This is of course only necessary if you want to re-create partitioning
from a previously partitioned microSD card.
Run these commands (assuming
/dev/sdj is your microSD card device node) to
establsih the partition filesystems and labels. The flags will need to be
set separately (e.\,g. with
mkdosfs -F 32 -n BPI-BOOT /dev/sdj1 mkfs.ext4 -L BPI-ROOT /dev/sdj2 mkswap /dev/sdj3
Once the build has completed successfully, use the resulting files
$(WRKROOT)/out as follows (assuming
/dev/sdj is your microSD
card device node):
unxz < f100mod.img.xz | dd bs=1k seek=8 skip=8 of=device
mount /dev/sdj1 /mnt && tar -C /mnt -xpf fat32.tar.xz && umount /mnt
mount /dev/sdj2 /mnt && tar -C /mnt -xpf ext4.tar.xz && umount /mnt
---------------------------------------------------[ Debian + Armbian Kernel ]--
This approach produces an image suited for a microSD card which contains
a Debian installation equipped with the Armbian Bootloader and a recent
Kernel like 4.10. The resulting system will support the Gigabit Ethernet
port but not display anything via the HDMI output. Also, there will be no
documented/automatic means of upgrading the kernel without re-generating the
The steps used to build the image are formalized in the associated GIT
Repository. It is recommended that you clone the repository as follows:
git clone https://github.com/m7a/bpi-m2p-armbian-and-debian.git
Obtain the files from the sources listed. Other versions might also work but
have not been tested. If you want to use the hack for direct invocation (the
system is also prepared to perform fully-automatic processing), provide the
files downloaded in the
armbian directory in the repository.
Next, the image to be created has to be confgiured. This is done by creating
a file ending with
myconf.mk and a
conf.mk are already supplied with the repository.
You are suggested to add your own separate
which may contain files below
fsroot which will be copied to the root file
system (after the hooks from
postinst.d have been executed) and
which contains scripts/programs to be called from inside the prepared root
Assuming you followed the instructions so far, you might put the following
# Changed Sample Settings MA_DEBIAN_MIRROR = http://ftp.de.debian.org/debian MA_USE_HACK = 1 MA_HOSTCONFIG = hostconfig myhostconfig MA_IMAGEBUILD = 1 MA_IMAGEPREFIX = masysmalocal WRKROOT = /var/tmp
The settings can be described as follows:
Configures the debian mirror to be consulted for image generation.
If this is 1, a hack to build
.tar.xz files from
directories is enabled. This makes it easier to amend the configuration
hostconfig directories but makes pipeline-automation more
difficult. If you want to provide the
.tar.xz archives, you can set this to 0 and provide said archives in
/var/tmp/in. Also, there is no need to specify
$(MA_HOSTCONFIG) if the hack is not used and the directories
hostconfig need not be present separately.
Contains a space-separated list of directories to compose a single
hostconfig (files are added in order which means you can override
files from a pervious hostconfig by creating a file in
the same name as in
Set this to 1 to build an own docker image to do the processing.
If it is 0, docker will attempt to pull the image
$(MA_IMAGEPREFIX)/bpi-build-armbian-debootstrap from Docker Hub or
other configured repositories.
Declare a prefix for the docker image to use. If you want to use an
existing Ma_Sys.ma image, you can set this to
masysma. For this case set
MA_IMAGEBUILD = 0.
working-root'' directory for intermediate files. Chose a directory large
enough to take about twice the size of your target image.
If you want to build a (boring) image with just SSH, Aptitude and VIM, you
do not need to provide a
myhostconfig and can go with the sample settings
Having prepared as described, call the build as follows:
$ make MA_BS_CONF_PREFIX=my
If you chose not to provide an own
myconf.mk, a simple
make is enough.
Make sure your microSD card is MBR formatted, the first partition has the
file system, starts at sector 2048 and is large enough to take the crated root
filesystem. You can check this with
fdisk -l. If you are using the
supplied with the given
hostconfig, you will also need to have a second
partition containing a swap area. There is no technical need for a swap
partition -- if you do not want it, just copy the prepared
myhostconfig/fsroot/etc/fstab and remove the last line containing
Once the build has completed, you will find two files below
This is the bootsector for your microSD card. Apply it to a given microSD
card as follows:
unxz < u-boot-sunxi-with-spl.bin.xz | dd of=/dev/sdj bs=1024 seek=8
/dev/sdj is your microSD card device node.
This contains the root filesystem to be used. Extract it to a mountpoint
where the first partition of your microSD card is mounted (e.g.
tar -C /mnt -xpf ext4_main.tar.xz.
Umount your microSD card, put it into the Banana Pi M2+EDU, connect
the Banana Pi M2+EDU to the eternet network and then power on the Banana Pi
M2+EDU and be patient for about 30 seconds. You should then see lights
at the ethernet port. If not wait a little longer and if nothing happens,
something is wrong. Such issues are best debugged using the serial console,
search the web for how to do this.
If the startup succeeded and you left that part of the default
intact, you might login at the Banana Pi M2+EDU using
ssh linux-fan@IP with
testwort. The IP address will be taken from DHCP -- you may find
out about it using
nmap -sn NETWORK where NETWORK is your network like e.\,g.
Additional notes and hints
- To delete intermediate results, call
make clean. If you also want to remove
the docker image used, use
- If you intend to change the build process, the main part of it is implemented
in the Makefile
build_inside.mkwhich is called from inside the container
(but outside the target root filesystem).
-----------------------------[ Getting to run Docker on the Banana Pi M2+EDU ]--
In order to run Docker on the Banana Pi M2+EDU, create a directory, e..g.
docker_arm with these contents:
fsroot/usr/bin/docker fsroot/usr/bin/docker-proxy fsroot/usr/bin/docker-containerd fsroot/usr/bin/dockerd fsroot/usr/bin/docker-containerd-ctr fsroot/usr/bin/docker-runc fsroot/usr/bin/docker-containerd-shim fsroot/lib/systemd/system/docker.service fsroot/lib/systemd/system/docker.socket postinst.d/10_setup_docker.sh
10_setup_docker.sh you might want to use this:
#!/bin/sh -e addgroup docker
The files for
docker.socket may be obtained from the
docker sources. The binaries for
/usr/bin may be taken from the official
From the running system, it is then a matter of
systemctl enable docker.service && systemctl start docker.service to
get to run the docker daemon.
-------------------------------------------------------------[ Further Ideas ]--
In the future, the system presented here should be incorporated into an
MDVL build process and customization should not be done using
postinst.d but with Debian packages instead.
Also, tests of all the different variants should be performed and
code to enable newer kernels (which never worked) should be removed from
the legacy build system.
-------------------------------------------------------------------[ License ]--
The Ma_Sys.ma-contributed scripts to build Debian images for a Banana Pi
M2+EDU are licensed under GPLv3.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.