# Raspberry Pi Unikernel Setup 1. Download raspi-solo5.img.gz file (1.3 GB) from https://drive.google.com/file/d/1veuzY0L51MSRpceCzdukAdiHu5Gtw4Zc/view?usp=sharing 2. Gunzip and flash the image to the SD card: ``` $ gunzip raspi-solo5.img.gz $ sudo dd bs=4M if=raspi-solo5.img of=<SD card device path> status=progress ``` 3. Connect the raspberry pi to Ethernet and SSH into the device. The default credentials are `user: pi`, `password: raspberry`. 4. Extend the partition to use the full SD card. You can expand the file system using `sudo raspi-config`, then selecting: `6 Advanced Options`, then `A1 Expand filesystem`, and finally reboot. 5. From the Raspberry Pi, you can setup the bridge by running the following script: ``` $ sudo ./bridge.sh ``` 6. You can now launch a unikernel to verify that you are able to boot the Raspberry Pi and run solo5: ``` $ solo5-hvt --net:service=tap0 -- ./input.hvt | ___| __| _ \ | _ \ __ \ \__ \ ( | | ( | ) | ____/\___/ _|\___/____/ Solo5: Bindings version v0.7.3 Solo5: Memory map: 512 MB addressable: ... 2022-11-17 06:26:42 -00:00: INF [tcpip-stack-direct] Dual TCP/IP stack assembled: mac=e2:ec:72:02:3b:f8,ip=10.0.0.2, fe80::e0ec:72ff:fe02:3bf8 2022-11-17 06:26:42 -00:00: INF [application] ready ``` You should see "[application] ready" for a successful execution. ## mirage-www unikernel 1. Clone the mirage-www repository on the Raspberry Pi: ``` $ git clone https://github.com/mirage/mirage-www.git ``` 2. Update opam: ``` $ sudo bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)" $ opam init $ opam update && opam upgrade $ opam switch create 4.14.0 ocaml-base-compiler.4.14.0 ``` 3. Install mirage: ``` $ opam repo add mirage-dev https://github.com/mirage/mirage-dev.git $ opam install "mirage>=4.0.0" ``` 4. Configure the unikernel: ``` $ cd mirage-www $ mirage configure -f mirage/config.ml -t hvt ``` 5. Pin tailwind css: ``` $ opam pin git+https://github.com/tmattio/opam-tailwindcss.git ``` 6. Fetch the dependencies: ``` $ make depends ``` Answer yes to `Opam plugin “monorepo” may require upgrading/reinstalling. Reinstall the plugin on the current switch? [Y/n] y`. 7. Build the unikernel: ``` $ dune build mirage/ ``` 8. Expose port 80 in the iptables firewall: ``` $ sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 10.0.0.2:80 ``` You can also add the above iptables entry to `bridge.sh` script so that everytime you reboot and run bridge.sh script, the firewall is updated. ``` iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 10.0.0.2:80 ``` If running on your computer, create the tap0 interface: ``` $ sudo ip tuntap add tap0 mode tap $ sudo ip addr add 10.0.0.1/24 dev tap0 $ sudo ip link set dev tap0 up ``` 9. Run bridge.sh script ``` $ sudo ~/bridge.sh ``` 10. Run the mirage-www unikernel: ``` $ solo5-hvt --net:service=tap0 -- ./mirage/dist/www.hvt --ipv4-gateway=10.0.0.1 ``` You can open a browser on your system/laptop with IP address of the Raspberry Pi and default port 80, and you should be able to see the mirage-www htdocs. ## Reference 1. MirageOS Unikernel. https://github.com/mirage/mirage-www/#mirageos-unikernel