Setting Up A Banana Pi

Using the Serial Port Console

The color codes for the serial port dongle. Red is VDD and for the Banana Pi can't supply enough current to power the pi and is usually left disconnected. (For the Raspberry Pi model A it is possible to power the pi completely from the red VDD supply. But not the Banana Pi which draws too much power.)

VDD-red
GND-black
TXD-white
RXD-green

The "picocom" serial port program command line:

picocom -fn -ez -b 115200 /dev/ttyUSB0
C-z C-x exits picocom

Use a standard vt100 size terminal or go insane. The above picocom option -fn turns off flow control. This is required because the serial port only has three wires and no hardware handshaking. Using hardware flow control would hang the terminal. If you are using other terminal and find it hanging then suspect that hardware flow control needs to be disabled.

Default Root Password

Default login root:pi (bananian-config will prompt to change it)

Initial Login

------------------------------------------------------------------------ 
Welcome to Bananian Linux!
For news and updates check: https://www.bananian.org
Any questions? Read the FAQ first: https://www.bananian.org/faq

Run 'bananian-config' to set up Bananian Linux
Run 'bananian-update' to check for distribution updates
------------------------------------------------------------------------

Shipped images Bananian 1604 do not use systemd.

Run bananian-config to walk through the initial setup. Say Yes to each of the questions and provide the setup information for each in turn.

bananian-config
  password
  timezone
  locale
  hostname
  Hardware configuration? BananaPi
  expand root file system

Root Environment Setup

Ships with zsh configured. Change immediately. (Unless you are a zsh fan.) The shipped image has /root zsh cruft left behind. Clean it.

chsh -s /bin/bash
rm -rf .aptitude .zcompdump .zdirs .zsh_history .zshrc
mkdir bin
cp /etc/skel/.profile /etc/skel/.bashrc .
  ...edit .profile .bashrc apply standard fixes...

The shipped image has .gnupg with a pubring already there. This seems to be needed for bananian-update so do not remove it. (This is a crass configuration putting it there instead of /etc/apt where it needs to be.)

Network Setup

Edit /etc/hosts and add an entry for the local fqdn and the short name. Since the banananian default is bananapi this means:

127.0.1.1   bananapi.localdomain bananapi

If you have changed the hostname then use that hostname here. If you have a local domain name and will set it up (later) then use that too.

If you are using a wired network connection then most of this next can be skipped. Just plug in the wire and use dhcp to configure. But if you are using a WiFi connection then this next is needed to set up the local WiFi configuration.

The /etc/udev/rules.d/70-persistent-net.rules file that caches device MAC addresses and associates them with device names wlan0, wlan1, through wlanN. Being as it caches devices it collects entries anytime any device is plugged in. Which means it needs to be edited to remove those entries when they are removed.

Bananian has customized things so the on-board eth0 isn't listed. (Raspbian customizes it so no network devices of any type are cached.) After swapping network devices I often simply remove the file instead of editing it. Removing it resets it to empty and on the next reboot it will start fresh and pristing and start collecting and caching network devices atain.

rm /etc/udev/rules.d/70-persistent-net.rules

This next isn't required everywhere. I list this as optional. But it is useful for setting maximum power output levels.

apt-get install crda
  ...set REGDOMAIN=US in /etc/default/crda...

The /etc/network/interfaces file includes interfaces.d. For this cycle I decided to use that, until I modify /etc/network/interfaces will keep it pristine. But next cycle I might decide to edit that file directly. I am still deciding. In the end it doesn't really matter.

[[FIXME: Need an IPv6 address attempt setup here.]]

Option 1 using wireless-tools:

Officially the wireless-tools method is deprecated. However a lot of people use this method and it doesn't seem to be going away any time soon. It is simple.

Added /etc/network/interfaces.d/wlan0 with:

allow-hotplug wlan0
iface wlan0 inet dhcp
        wpa-ssid "The SSID Here"
        wpa-psk "the passphrase here"

Same thing but setting a static IP address instead of using DHCP.

allow-hotplug wlan0
iface wlan0 inet static
        wpa-ssid "The SSID Here"
        wpa-psk "the passphrase here"
        address 192.168.93.10/24
        gateway 192.168.93.1
        dns-search example.com
        dns-nameservers 192.168.93.1

This depends upon resolvconf for the dns nameserver setup which isn't installed yet. A circular dependency. You will need to manually edit /etc/resolv.conf and set up a nameserver until you can get the network up enough to install resolvconf so that it can do this automatically afterward. This circular dependency is avoided by using DHCP to install and then switching to a static address later.

Option 2 using wpa_supplicant:

Since the wireless-tools method above is deprecated the other method is the officially recommended method. It is a little more completed to understand because there are a zillion possible configurations. However in the simple mode it isn't very complicated. I am leaning toward using this option in the future since it allows automatically connecting to any one of a variety of possible access points.

First create the /etc/wpa_supplicant/wpa_supplicant.conf file. This is most easily done using the wpa_passphrase program.

wpa_passphrase "The SSID Here" "the passphrase here" > /etc/wpa_supplicant/wpa_supplicant.conf

If you want the device to automatically connect to any one of several different access points then add several to the file. Just append the additional access points to the file. When the network is brought online it will connect to any of the configured Access Point SSIDs using the associated configuration.

wpa_passphrase "Another SSID" "another passphrase" >> /etc/wpa_supplicant/wpa_supplicant.conf
wpa_passphrase "Yet Another SSID" "yet another passphrase" >> /etc/wpa_supplicant/wpa_supplicant.conf

With that configuration file in place then add to the /etc/network/interfaces.d/wlan0 file:

allow-hotplug wlan0
iface wlan0 inet dhcp
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Overriding the default DHCP domain name.

If you need or want to override what the DHCP server sends back for a domain name (for example my laptop when connecting at a coffee shop) then that is done in the /etc/dhcp/dhclient.conf file. This is option and probably not needed for anything at a home LAN. It really is only needed for mobile devices connecting to non-home LANs. At the bottom of the file set:

supersede domain-name "example.com";

Bringing up the WiFi network

Regardless of the option selected above, either the wireless-tools method using wpa-ssid and wpa-psk or the wpasupplicant method using the wpasupplicant.conf file, bring the interface up using ifup.

ifup wlan0

If that works it will associate with the WiFi Access Point. If the association works then it will attempt a DHCP. If you see it attempting DHCP then you know the WiFi Access Point information is correct and working. If the DHCP succeeds you will see the IP address it has negotiated. If you miss it you can query the IP address of any network device.

ip addr show

Or just the specific device:

ip addr show wlan0

If you want to scan for WiFi Access Points:

iw dev wlan0 scan

Seems wpa_supplicant writes noisily to the console. If this is annoying and getting in the way of seeing what is happening on the console then reduce the console logging level to avoid it.

dmesg -n4

Where to make that dmesg -n4 persistent? I usually install the Shorewall firewall. Shorewall has an init script for when the firewall is initialized. I tend to put it there. But this could go elsewhere. Certainly it is easy to put it in the /etc/rc.local file.

Updating The OS

Now that the network is up you can update the OS:

Edit /etc/apt/sources.list and change ftp.de.debian.org to US mirrors ftp.us.debian.org.

sed --in-place 's/ftp.de.debian.org/ftp.us.debian.org/' /etc/apt/sources.list

Note that the Bananian /etc/apt/sources.list.d/bananian.list file points to "deb http://dl.bananian.org/packages/ 1604 main".

Upgrade everything. First by calling bananian-update to update the kernel. Reboot afterward if there the kernel was upgraded.

bananian-update

Upgrade everything else:

apt-get update
apt-get upgrade
apt-get upgrade --with-new-pkgs
apt-get dist-upgrade
apt-get autoremove --purge
apt-get clean

Running bananian-update doesn't do anything new for me but immediately afterward I run apt-get ugprade and there is a new kernel and other things needed to be installed.

Installing Everything Else

Install a bunch of stuff that I generally like to have installed. Everyone will have different preferences here.

apt-get install resolvconf
apt-get install bind9 bind9-host
apt-get install ed
apt-get install emacs emacs24-nox emacs24-common-non-dfsg emacs24-el emacs-goodies-el
apt-get install sudo
apt-get install bootlogd
apt-get install file
apt-get install hdparm
apt-get install postfix heirloom-mailx
postconf -e inet_interfaces=loopback-only

These packages are already installed in the stock Bananian image: htop, haveged, ntp, sysvinit.

Installing "etckeeper"

I really like 'etckeeper' which keeps all of /etc in git. But git complains continously about using the default name and email. Therefore I configure /root/.gitconfig first to stop the complaints. While there I turn off that annoying color UI too. YMMV.

root@bananapi:~# cat > .gitconfig <<EOF
[user]
    name = root
    email = root@localhost
[color]
    ui = false
EOF

Then install the packages:

apt-get install git patch
apt-get install etckeeper

Installing a Firewall

On any system that is on the global network I always install fail2ban at the least and then Shorewall for a firewall.

apt-get install fail2ban shorewall shorewall6
  ...Needs various setup not documented here...

For Shorewall specific info see: https://www.proulx.com/~bob/doc/HOWTO-shorewall.html

Stopping the bright green blinking LED

The Banana Pi has a really bright set of red, green and blue LEDs that can be really annoyingly bright and distracting. The green "heartbeat" is particularly bright. This seems to be a specific feature of the original Banana Pi and has been changed on other Banana Pi models. It does not exist on the Banana Pi M2 for example and this configuration is not needed there.

These LEDs can be setup to a variety of other things that are less annoying and some are useful. I find setting it to cpu0 is useful and not bright.

In /etc/rc.local startup file.

# Avoid the bright flashing heartbeat.  Using cpu0 seems okay.
echo cpu0 > /sys/class/leds/green:ph24:led1/trigger

Disabling the OOM Killer

The Out-Of-Memory Killer is problematic enough that I am willing to burn some storage space as swap in order to avoid it.

Check swap. Ships with a static 512M /swapfile1 file configured in /etc/fstab. Can't blame them since the initial imag is only 1.9G total for the distribution image. But I always turn off Linux memory overcommit and the Out-Of-Memory Killer, which then needs the traditional amount of swap.

apt-get install dphys-swapfile

And I turn off Linux memory overcommit and the OOM Killer.

cat > /etc/sysctl.d/vm.conf <<EOF
# Disable Linux kernel memory overcommit.
vm.overcommit_memory = 2
EOF

Reboot

Reboot to have all of the above take effect and verify that it all reboots okay.

And of course there is a lot of additional configuration too. Do all of that too.