DEV Community

Jacopo Valanzano
Jacopo Valanzano

Posted on • Updated on

🍓Raspberrypi - OTG Cluster


In this guide we'll create the simplest slave/master server configuration, using only Raspberrypi devices running Raspberrypi OS.

It is vital that you use quality cables to link each device.
This setup will not work with low quality USB-A Male to Micro B cables.

You can use any suitable device for the master, we'll use a Pi4-B. ne
As slaves, we'll use two Pi Zero W.


  • 1 Pi4-B with Rasperrypi OS preinstalled
  • 2 Pi Zero (W) with Raspberrypi OS preinstalled
  • 2 Power supplies for Pi Zero (W), each Pi Zero needs its own power supply
  • 2 USB-A 2.0 Male to Micro B
  • DHCPCD client installed in each device



For each slave server, edit /boot/cmdline.txt and make sure the dwc2 and g_ether modules are enabled.

Additionally, assign a MAC address for and g_ether.dev_addr.
You can use the MAC provided in the examples below:

$ cat /boot/cmdline.txt

Should output something similar the line below, note the difference between and g_ether.dev_addr MAC:

console=serial0,115200 console=tty1 root=PARTUUID=33a0f260-02 rootfstype=ext4 elevator=deadline rootwait modules-load=dwc2,g_ether g_ether.host_addr=00:22:82:ff:ff:03 g_ether.dev_addr=00:22:82:ff:ff:13

Repeat the process for each slave, note the difference between and g_ether.dev_addr:

console=serial0,115200 console=tty1 root=PARTUUID=7a235f18-02 rootfstype=ext4 elevator=deadline rootwait modules-load=dwc2,g_ether g_ether.host_addr=00:22:82:ff:ff:04 g_ether.dev_addr=00:22:82:ff:ff:14

Note the last two digits of each MAC address listed above.

Slave hostname

Edit each /etc/hostname and give each slave a unique hostname, we'll use pisrv03 and pisrv04 respectively. The hostname file contents should look like the following line:

Slave hosts

Edit each /etc/hosts and map the hostname with localhost, for the slave with hostname pisrv03: localhost pisrv03

for the slave with hostname pisrv04: localhost pisrv04

And so on.

Slave DHCP

Install DHCPCD if not available:
$ apt install dhcpcd

Edit /etc/dhcpcd.conf and give a static IP to the USB interface usb0, you can refer to the following lines:
interface usb0
static ip_address=

interface usb0
static ip_address=

And so on.


Access /boot/cmdline.txt in your master server and make sure the dwc2 and g_ether modules are enabled.
Each module must be separated by a comma and must contain no spaces:

$ cat /boot/cmdline.txt

The output should look similar to the following line, note modules-load:

console=serial0,115200 console=tty1 root=PARTUUID=fb57ee21-02 rootfstype=ext4 elevator=deadline rootwait modules-load=dwc2,g_ether

Userspace /dev

Add a new rule set to udev; create a new file, we'll call it 90-picluster.rules:
$ touch /etc/udev/rules.d/90-picluster.rules

Map each device MAC with an interface.

For the slave pisrv03
SUBSYSTEM=="net", ATTR{address}=="00:22:82:ff:ff:03", NAME="eth3pi"

For the slave pisrv04
SUBSYSTEM=="net", ATTR{address}=="00:22:82:ff:ff:04", NAME="eth4pi"

And so on.

90-picluster.rules should look like this

SUBSYSTEM=="net", ATTR{address}=="00:22:82:ff:ff:03", NAME="eth3pi"
SUBSYSTEM=="net", ATTR{address}=="00:22:82:ff:ff:04", NAME="eth4pi"
Enter fullscreen mode Exit fullscreen mode


Finally, edit the DHCPCD configuration file, usually /etc/dhcpcd.conf, and give each slave a local IP range

interface eth3pi
static ip_address=

interface eth4pi
static ip_address=
Enter fullscreen mode Exit fullscreen mode

Connect to the slave

$ ssh pi@
$ ssh pi@

Top comments (1)

andypiper profile image
Andy Piper

Interesting, this is pretty much the same strategy used by the Pi Zero Cluster in a box, on a ClusterHAT.