As some of you know, the server running this website is a PowerMac G5. It’s a great little machine and I love it, but, it’s also a PowerPC machine. As much as that’s really cool, it also means that a lot of newer software doesn’t support it…
So what am I to do? I do have a really nice x86 server, but that’s more of a production machine (plus, I’m heading off to uni soon, I’ll be bringing the G5 with me!).
Plug a Raspberry Pi into it! See, I don’t want to just have a Raspberry Pi running as a separate server entirely, 1. because that’s boring, 2. because it would need to run on WiFi (which looking into the future in university, I don’t think that’ll be the greatest experience).
For those unaware, because the Pi Zero‘s Micro-B port has a direct connection to the SoC (with no hub in between), you can actually have it run as a USB device instead of a host. What that means is using the Linux kernel’s USB Gadget feature, the Pi Zero can make itself a USB Ethernet device (giving us a nice usb0 ethernet device on the G5)!
Adafruit has a nice tutorial on how to set it up, but here’s the gist of it:
- Flash a fresh copy of Raspbian on an SD Card
- Add “
dtoverlay=dwc2” to the bottom of config.txt (on the boot partition)
- Add “
modules-load=dwc2,g_ether” after “rootwait” in cmdline.txt
- (Optionally create a empty file named “ssh” to automatically enable ssh on first boot, just do “touch ssh” in the boot partition).
After that, just plug the Pi Zero’s OTG port into your computer, and it should pop up as a network interface (on Windows you may need additional drivers)! On macOS (and Linux with avahi), your computer and the Pi will automatically get a link-local ip (169.whatever, zeroconf networking is cool), and you can just do “ssh firstname.lastname@example.org”.
Now, you could leave it just like that and use the zeroconf network, but because I wanted the Pi Zero to be a permanent extension of my G5 server, I needed to setup a static IP, aswell as network sharing (so the Pi could access the internet).
First I added the following to “/etc/network/interfaces” on the Pi:
Then, on the G5:
This gives the Pi an IP of “192.168.7.2” and the G5 “192.168.7.1”. This is nice, but we still need to have a NAT between eth0 (the ethernet port of the G5) and usb0 (the Pi Zero). I found a nice article that explains how to do that, here are the steps:
net.ipv4.ip_forward=1in “/etc/sysctl.conf”, the do
sudo sysctl -p /etc/sysctl.conf
- Run the following commands (where eth0 is the WAN port, and usb0 is the Pi’s interface):
Your almost done, on the Pi you’ll want to disable dhcpcd (since we have a static IP), and edit “/etc/resolv.conf” to use some public DNS server (like 220.127.116.11). And that’s it! The Pi Zero should be able to access the internet.
Still one more tweak to go though. You can SSH into the Pi (or access any service) locally on the machine using “192.168.7.2”, but the Pi isn’t exposed outside of the server. If I was running, say, web services, I’d use NGINX as a reverse proxy. But for things like SSH, you need to basically port forward. Most people would add some additional iptables entries, but since I was messing around with Golang a bit while doing this project, I decided I’d write a simple TCP proxy to forward certain ports of the server to the Pi.
You can find that code on my GitHub, and basically it just parses a config file with a list of ports to forward. This way, services on the Pi appear alongside everything on the server, it’s great! Basically “ssh email@example.com” goes to the host OS, and “ssh firstname.lastname@example.org -p 2287” goes to the Pi. ?
And there you go! The SeshanXYZ server now has a little Pi companion! It works great, and I can run stuff that would otherwise not work on the G5 (like modern versions of NodeJS). That being said, a Pi zero isn’t the fastest thing in the world… but it’s the only Pi that can run in Gadget mode… or is it? As it turns out, the Pi 4’s USB-C port can actually do that same thing! Yes that’s right ladies and gentlemen, you can get this same experience but with 64-bit quad-core goodness and up to 8GB of RAM! I might want to get my hands on a Raspberry Pi 4…