To realize the full benefits of gokrazy, you need to use only
software written in Go. If there is no Go software for what you want
to do, creating that piece of software can pose a seemingly
unsurmountable hurdle. To make some quick progress and figure out if
your idea can be implemented, it might make sense to temporarily use
existing software before starting your own implementation.
This article shows a couple of techniques for getting non-Go
software to work on gokrazy, in increasing order of complexity.
Note that software which is manually installed like shown
here will not be automatically updated by gokrazy
and hence poses a security risk. Use these techniques only for
prototyping.
Go software not written for gokrazy: Grafana
It would not suffice to add Grafana to your gokr-packer
command, as the resulting Grafana binary requires assets, supports
plugins, keeps state, etc.
Hence, you need to manually install Grafana into a directory
underneath /perm. A convenient way to do that is to
use breakglass
to download the “Standalone Linux Binaries” release from
https://grafana.com/grafana/download?platform=arm. Note
that I am serving the file from my computer because my busybox
version supports neither HTTPS nor DNS.
/tmp/breakglass531810560 # wget http://10.0.0.76:4080/grafana-5.3.2.linux-arm64.tar.gz
/tmp/breakglass531810560 # tar xf grafana-5.3.2.linux-arm64.tar.gz
We cannot start Grafana yet, as its binary is dynamically
linked. One way to fix this is to place the sources which correspond
to the release you just unpacked (e.g. from
https://github.com/grafana/grafana/tree/v5.3.2)
in your $GOPATH and recompile the binaries:
Note that it is usually easier to set the environment
variable CGO_ENABLED=0 to get a statically linked
binary, but Grafana uses sqlite3, which is written in C, so we
resort to the -ldflags variant.
At this point, we can start Grafana from breakglass:
WireGuard is a modern VPN tunnel, which consists of a Linux kernel
module and a configuration
tool. See rtr7/kernel@c7afbc1f
for how the kernel module was added to the router7 kernel.
The configuration tool can be statically cross-compiled. We can run
Debian in a Docker container to not mess with our host system:
% mkdir /tmp/wg
% cd /tmp/wg
% docker run -t -i debian
root@d1728eaaa6e1:/# dpkg --add-architecture arm64
root@d1728eaaa6e1:/# apt update
root@d1728eaaa6e1:/# apt install libmnl-dev:arm64 libelf-dev:arm64 linux-headers-amd64 crossbuild-essential-arm64 pkg-config wget
root@d1728eaaa6e1:/# wget https://git.zx2c4.com/WireGuard/snapshot/WireGuard-0.0.20181018.tar.xz
root@d1728eaaa6e1:/# tar xf WireGuard-0.0.20181018.tar.xz
root@d1728eaaa6e1:/# cd WireGuard-0.0.20181018/src/tools
root@d1728eaaa6e1:/# make CC=aarch64-linux-gnu-gcc LDFLAGS=-static
root@d1728eaaa6e1:/# exit
% docker cp -L d1728eaaa6e1:/WireGuard-0.0.20181018/src/tools/wg .
Now we can copy and run the wg binary via breakglass:
Linux’s Traffic Control system (used e.g. for traffic shaping) is
configured with the tc tool.
tc is a special case in that it requires to be
dynamically linked. The different queueing disciplines are
implemented as plugins, and statically linking tc
results in a binary which starts but won’t be able to display or
change queueing disciplines.
Because gokrazy doesn’t include a C runtime environment, we’ll need to copy not
only the tc binary, but also the dynamic loader and all required
shared libraries. We can run Debian in a Docker container to not mess with our
host system, and use the freeze tool to
automate the tedious parts of the process: