Pi Imaging and Initial Configuration - Pieman130/dtr_open GitHub Wiki
- Use Pi Imager to install Raspbian
- Select Raspberry Pi OS (other) and then Raspberry Pi OS Lite (32-bit).
- Use [command/ctrl+shift+x] to preconfigure hostname, ssh, wifi networking (optional, can be used for configuration, will be overwritten to become a mesh below), localization.
- Write card.
- ssh-copy-id your key to the new pi and log in
- replace
raspberrypi
with your hostname if you changed it in 1.
$ ssh-copy-id pi@raspberrypi
$ ssh pi@raspberrypi
- update to predictable network names and unblock wifi
$ sudo raspi-config
* 4 Localisation Options
* L4 WLAN Country
* US United States
* <Ok>
* <Ok>
* 6 Advanced Options
* A4 Network Interface Names
* <Yes>
* <Ok>
* <Finish>
* <No>
- Install
batctl
, and optionallybatmand
andalfred
$ sudo apt install -y batctl batmand alfred
- set up a network bridge via
systemd-networkd
This section creates the files that are required when using systemd-networkd
to manage network interfaces. These reside in /etc/systemd/network/
and are processed in lexical order (and thus start with numbers to make it obvious).
I'm using STP and Priority just in case the bridge winds up with two connections to the same switch, creating a loop. I've also set the MTU to 1468 because we're going to want to let bat0
add its headers on wlan0
, but the pis support 1500 max. The code below prefers the builtin eth0
device to the enx
dongles when both exist, and if you have a wireless dongle you'll want to make sure to set its priority as well.
We disable dhcpcd
because systemd-networkd
has enough DHCP functionality for us at this point (i.e., it can get an IP for the bridge, which is what we want).
-
10-br0.netdev
creates the bridge -
10-br0.network
requests an IP for the bridge via DHCP -
20-eth-br0.network
adds any builtin ethernet ports to the bridge -
30-enx-br0.network
adds any ethernet dongles to the bridge.
$ sudo tee -a /etc/systemd/network/10-br0.netdev << EOF
[NetDev]
Name=br0
Kind=bridge
[Bridge]
STP=yes
EOF
$ sudo tee -a /etc/systemd/network/10-br0.network << EOF
[Match]
Name=br0
[Network]
DHCP=yes
EOF
$ sudo tee -a /etc/systemd/network/20-eth-br0.network << EOF
[Match]
Name=eth*
[Link]
MTUBytes=1468
[Network]
Bridge=br0
[Bridge]
Priority=32
EOF
$ sudo tee -a /etc/systemd/network/30-enx-br0.network << EOF
[Match]
Name=enx*
[Link]
MTUBytes=1468
[Network]
Bridge=br0
[Bridge]
Priority=33
EOF
$ sudo systemctl enable systemd-networkd
$ sudo systemctl disable dhcpcd
- configure the
wlan0
in IBSS mode to create the mesh network
This section uses wpa_supplicant
to take the pi's builtin wlan0
and convert it to an IBSS mode device that will participate in the underlying mesh network.
You need to pick a mesh network SSID and a mesh network channel. All of the mesh devices have to be on the same channel. If you have pi zero Ws then you need to use a 2.4MHz channel, otherwise you could configure a 5MHz option. You can see a list of channel frequencies using iw list | grep MHz
, however if you have other wireless dongles connected then you might need to manually look through the output of iw list
to make sure you're seeing the builtin NIC info.
$ sudo tee -a /etc/wpa_supplicant/wpa_supplicant-wlan0.conf << EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
p2p_disabled=1
country=US
network={
ssid="MESH_NETWORK_SSID"
frequency=XXXX
mode=1
key_mgmt=NONE
}
EOF
$ sudo sed -i 's/MESH_NETWORK_SSID/YOUR_ID_HERE/' /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
$ sudo sed -i 's/XXXX/2412/' /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
$ sudo systemctl enable wpa_supplicant@wlan0
- create the
bat0
interface, addwlan0
to it, and add it tobr0
This uses the older-style network interface infrastructure to manage the batman-adv
interface, because raspbian's systemd
hasn't yet been updated to version 249. The basic idea is to create the interface, use batctl
to attach wlan0
to it, and then attach bat0
as a port on the bridge. This will allow non-mesh clients to connect to any ethernet devices (or other wireless devices) that are also attached to the bridge.
$ sudo tee -a /etc/network/interfaces.d/bat0 << EOF
auto bat0
iface bat0 inet6 manual
pre-up /usr/sbin/batctl if add wlan0
pre-up /usr/sbin/ip link set dev \$IFACE master br0
pre-up /usr/sbin/ifconfig \$IFACE mtu 1468 up
pre-down /usr/sbin/ifconfig \$IFACE down
EOF
- update system to bullseye with
apt
$ sudo sed -i 's/buster/bullseye/g' /etc/apt/sources.list
$ sudo apt update
$ DEBIAN_FRONTEND=noninteractive sudo apt full-upgrade -y
$ sudo apt autoremove -y
$ sudo reboot
At this point you should be able to access your pi over the mesh.
I. Install batctl
from source (required for buster
, optional if you upgraded to bullseye
)
$ sudo apt install libnl-3-dev libnl-genl-3-dev
$ wget https://downloads.open-mesh.org/batman/stable/sources/batctl/batctl-2021.3.tar.gz
$ tar xf batctl-2021.3.tar.gz
$ cd batctl-2021.3/
$ make -j
$ sudo make install
$ cd ..
II. Install wpa_supplicant
with mesh support from source (derived from LFS).
$ sudo apt install libnl-3-dev libnl-genl-3-dev libdbus-1-dev libssl-dev
$ sudo wget https://w1.fi/releases/wpa_supplicant-2.9.tar.gz
$ echo "2d2958c782576dc9901092fbfecb4190 wpa_supplicant-2.9.tar.gz" > wpa_supplicant-2.9.tar.gz.md5
$ md5sum -c wpa_supplicant-2.9.tar.gz.md5
$ tar xf wpa_supplicant-2.9.tar.gz
$ cd wpa_supplicant-2.9/wpa_supplicant
$ cp defconfig .config
$ sed -i 's/#CONFIG_MESH=y/CONFIG_MESH=y/' .config
$ make BINDIR=/usr/sbin LIBDIR=/usr/lib
$ sudo install -v -m755 wpa_{cli,passphrase,supplicant} /usr/sbin/
$ sudo install -v -m644 doc/docbook/wpa_supplicant.conf.5 /usr/share/man/man5/
$ sudo install -v -m644 doc/docbook/wpa_{cli,passphrase,supplicant}.8 /usr/share/man/man8/
$ sudo install -v -m644 dbus/fi.w1.wpa_supplicant1.service /usr/share/dbus-1/system-services
$ sudo install -v -d -m755 /etc/dbus-1/system.d
$ sudo install -v -m644 dbus/dbus-wpa_supplicant.conf /etc/dbus-1/system.d/wpa_supplicant.conf
$ sudo reboot
III. configure the wlx*
in mesh mode to create the mesh network
This requires that you first follow the instructions in II to build wpa_supplicant
from source, because the raspbian version is not built with 802.11s mesh support.
This section uses wpa_supplicant
to take an 802.11s capable dongle wlx*
and convert it to an mesh mode device that will participate in the underlying mesh network.
You need to pick a mesh network SSID and a mesh network channel. All of the mesh devices have to be on the same channel. You can see a list of channel frequencies using iw list | grep MHz
, however if you have other wireless dongles connected then you might need to manually look through the output of iw list
to make sure you're seeing the USB dongle info.
Start by running $ networkctl
to figure out what the device id will be (it will be of the form wlx????????????
where the question marks are replaced by the devices MAC address). In the
$ export WLX=$(networkctl | grep wlx | awk '{print $2}')
$ sudo tee -a /etc/wpa_supplicant/wpa_supplicant-$WLX.conf << EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
user_mpm=1
# secure mesh network
network={
ssid="MESH_NETWORK_SSID"
mode=5
frequency=XXXX
key_mgmt=SAE
psk="PLAINTEXT"
}
EOF
$ sudo sed -i 's/MESH_NETWORK_SSID/YOUR_ID_HERE/' /etc/wpa_supplicant/wpa_supplicant-$WLX.conf
$ sudo sed -i 's/PLAINTEXT/YOUR_PASSPHRASE_HERE/' /etc/wpa_supplicant/wpa_supplicant-$WLX.conf
$ sudo sed -i 's/XXXX/YOUR_FREQUENCY_HERE/' /etc/wpa_supplicant/wpa_supplicant-$WLX.conf
$ sudo systemctl enable wpa_supplicant@$WLX
IV. Set up a bridged (br0
) access point with wlan0
using hostapd.
$ sudo apt install hostapd
$ sudo systemctl stop hostapd
$ sudo systemctl unmask hostapd
$ sudo systemctl disable hostapd
$ sudo tee -a /etc/hostapd/wlan0.conf << EOF
interface=wlan0
bridge=br0
ssid=YOUR_NETWORD_SSID
macaddr_acl=0
ignore_broadcast_ssid=0
country_code=US
## 2.4G
hw_mode=g
channel=7
ieee80211d=1
ieee80211n=1
ieee80211ac=1
## 5G
#hw_mode=a
#channel=36
#wmm_enabled=1
## wpa auth
auth_algs=1
wpa=2
wpa_passphrase=YOUR_NETWORK_PASSPHRASE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
EOF
$ sudo systemctl enable hostapd@wlan0