Bootstrap Raspi4 + 🐫 OCaml

Sat, 04. Apr 2020

Categories: en Tags: Raspi OCaml Linux

Yesterday a new Raspi4 (1GB) arrived and I’d like to have the OCaml toolchain for static builds running on it. Headless for now, accessible via WIFI and ssh.

Let’s go!

Prepare SD-Card

At first have a look at https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up, next download the OS image:

1$ curl -Lo 2020-02-13-raspbian-buster.txt https://downloads.raspberrypi.org/raspbian/release_notes.txt
2$ curl -Lo 2020-02-13-raspbian-buster.zip.sha256 https://downloads.raspberrypi.org/raspbian/images/raspbian-2020-02-14/2020-02-13-raspbian-buster.zip.sha256
3$ curl -Lo 2020-02-13-raspbian-buster.zip https://downloads.raspberrypi.org/raspbian/images/raspbian-2020-02-14/2020-02-13-raspbian-buster.zip
4$ shasum -c 2020-02-13-raspbian-buster.zip.sha256 
52020-02-13-raspbian-buster.zip: OK

Then insert a SD-Card and flash it (I use https://www.balena.io/etcher/).

Inject ssh + wifi settings

Mount the SD-Card on a Linux-box, follow https://www.raspberrypi.org/documentation/configuration/wireless/headless.md and adjust as needed:

 1cat > /media/$(whoami)/boot/wpa_supplicant.conf <<EOF
 2ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
 3update_config=1
 4country=<Insert country code here>
 5
 6network={
 7 ssid="<Name of your WiFi>"
 8 psk="<Password for your WiFi>"
 9}
10EOF

And enable ssh by default

1$ touch /media/$(whoami)/boot/ssh

Power On! and log in

  1. insert the SD-Card,
  2. connect the USB-Power,
  3. plug it into an outlet.
1$ ssh pi@raspberrypi
2$ sudo apt-get update
3$ sudo apt-get upgrade
4$ sudo apt-get dist-upgrade
5$ sudo reboot
6$ # sudo systemctl disable vncserver-virtuald.service
7$ sudo raspi-config
8$ sudo apt-get install fortunes fortunes-de fortune-anarchism vim fish mosh

🐫 OCaml

Based on https://blog.danny-willems.be/ocaml-raspberry-pi/

 1$ sudo apt-get install git m4 ocaml musl-tools
 2...
 3Setting up musl:armhf (1.1.21-2) ...
 4Setting up musl-dev:armhf (1.1.21-2) ...
 5Setting up musl-tools (1.1.21-2) ...
 6...
 7$ git clone https://github.com/ocaml/opam
 8$ cd opam
 9# today's master 1bab95d0d006ec08db022bc89907986b63f30883 fails, https://github.com/ocaml/opam/issues/4126
10# use a known working version:
11$ git checkout d6e4e4acb2a13e010631d9f27c638072030fd93d
12# $ git checkout 2.0.6
13$ ./configure
14$ make lib-ext
15$ make 
16$ sudo make install
17$ cd
18$ opam init
19$ opam switch --jobs=1 create 4.10.0+musl+static+flambda
20$ eval $(opam env)
21$ opam install dune

Voilà!

P.S.: Be aware that uname -m is armv7l which won’t run on a Raspi Zero or Raspi 1 but vice versa.