diff --git a/Makefile b/Makefile index e42fed2..1dafda5 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,9 @@ help: @echo " Packaging:" @echo "" @echo " pypi Build PyPi packages" - @echo " image Build a Raspberry Pi image" + @echo " image Build all image types" + @echo " raspbian_image Build a Raspbian image suitable for use with most Raspberry Pi models" + @echo " armbian_image Build a Armbian image suitable for use with the NanoPi R2S" @echo "" @echo " Clean:" @echo "" @@ -117,14 +119,34 @@ build/pi-gen: mkdir -p build cd build && git clone --branch 2020-02-13-raspbian-buster https://github.com/RPi-Distro/pi-gen.git -.PHONY: image -image: pypi | build/pi-gen +.PHONY: raspbian_image +raspbian_image: pypi | build/pi-gen mkdir -p dist/image rm -rf build/pi-gen/stage3 build/pi-gen/stage4 build/pi-gen/stage5 - cp -r image/* build/pi-gen/ + cp -r image/raspbian/* build/pi-gen/ cp -r requirements.txt dist/pypi/*.whl build/pi-gen/stage3/01-install-python-packages/files + cp -r image/common/files/* build/pi-gen/stage3/02-install-services/files cd build/pi-gen && ./build-docker.sh mv build/pi-gen/deploy/* dist/image/ +build/armbian: + mkdir -p build + # It would be nice to be able to checkout specific branch or commit here to + # get builds that are reproducible, but this does not seem well supported by + # Armbian. For example, checking out branch v2021.05 yields a broken build + # due to upstream changes. As such, checkout the main branch. + cd build && git clone https://github.com/armbian/build.git armbian + +.PHONY: armbian_image +armbian_image: pypi | build/armbian + mkdir -p dist/image build/armbian/userpatches/overlay + cp -r image/armbian/userpatches/* build/armbian/userpatches + cp -r requirements.txt dist/pypi/*.whl image/common/files/* build/armbian/userpatches/overlay + cd ./build/armbian && ./compile.sh docker znail-nanopi-r2s + mv build/armbian/output/images/* dist/image + +.PHONY: image +image: raspbian_image armbian_image + cleanimage: rm -rf build/image diff --git a/README.md b/README.md index ae7e692..e64ac24 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ ![Znail Logo](/artwork/znail_x10.png) -Znail is a network emulator inteded to run on a Raspberry Pi. -Equipped with two network interfaces, the Raspberry Pi acts as a network bridge. +Znail is a network emulator inteded to run on a computer with two network interfaces. +Equipped with two network interfaces, Znail acts as a network bridge. Znail can then control network traffic passing through the bridge. With a system under test connected to the network through this bridge, @@ -27,11 +27,19 @@ Znail can be managed in one of two ways, using its web interface or its REST API # Getting Started -The easiest way to get started with Znail is to [download](https://github.com/znailnetem/znail/releases/latest) a Rasbian image with Znail pre-installed. +The easiest way to get started with Znail is to [download](https://github.com/znailnetem/znail/releases/latest) an image with Znail pre-installed. -The image can then be [installed](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) on a Raspberry Pi. +The image can then be installed on a suitable target system, for example a [Raspberry Pi](https://www.raspberrypi.org/documentation/installation/installing-images/README.md). -# Generating a Custom Image +## Raspberry Pi + +The default SSH username for the pre-built image is `pi` and the password is `raspberry`. + +## NanoPi R2S + +The default SSH username for the pre-built image is `root` and the password is `1234`. + +# Generating Custom Images To set up the environment on an Ubuntu 20.04 system, run the following commands: @@ -42,8 +50,11 @@ To generate an image: make image -The resulting image can be found in the `dist/image` directory. -Note that due to the way `pi-gen` works, portions of the `make image` target needs to run as root. +The resulting images can be found in the `dist/image` directory. + +Generating the different images can take quite some time. +If you are looking to only build one specific kind of image more narrow `make` targets are available. +See `make help` for more information. # Development diff --git a/image/armbian/userpatches/config-znail-nanopi-r2s.conf b/image/armbian/userpatches/config-znail-nanopi-r2s.conf new file mode 100644 index 0000000..de5d076 --- /dev/null +++ b/image/armbian/userpatches/config-znail-nanopi-r2s.conf @@ -0,0 +1,30 @@ +# Read build script documentation https://docs.armbian.com/Developer-Guide_Build-Options/ +# for detailed explanation of these options and for additional options not listed here + +KERNEL_ONLY="no" # leave empty to select each time, set to "yes" or "no" to skip dialog prompt +KERNEL_CONFIGURE="no" # leave empty to select each time, set to "yes" or "no" to skip dialog prompt +BUILD_MINIMAL="yes" +CLEAN_LEVEL="make,debs,oldcache" # comma-separated list of clean targets: "make" = make clean for selected kernel and u-boot, + # "debs" = delete packages in "./output/debs" for current branch and family, + # "alldebs" = delete all packages in "./output/debs", "images" = delete "./output/images", + # "cache" = delete "./output/cache", "sources" = delete "./sources" + # "oldcache" = remove old cached rootfs except for the newest 8 files + +REPOSITORY_INSTALL="" # comma-separated list of core modules which will be installed from repository + # "u-boot", "kernel", "bsp", "armbian-config", "armbian-firmware" + # leave empty to build from sources or use local cache + +DEST_LANG="C.UTF-8" # sl_SI.UTF-8, en_US.UTF-8 + +# advanced +EXTERNAL_NEW="prebuilt" # compile and install or install prebuilt additional packages +INSTALL_HEADERS="no" # install kernel headers package +LIB_TAG="master" # change to "branchname" to use any branch currently available. +USE_TORRENT="yes" # use torrent network for faster toolchain and cache download +DOWNLOAD_MIRROR="" # set to "china" to use mirrors.tuna.tsinghua.edu.cn +CARD_DEVICE="" # device name /dev/sdx of your SD card to burn directly to the card when done + +BRANCH="current" +RELEASE="buster" +BOARD="nanopi-r2s" +HOST="znail" diff --git a/image/armbian/userpatches/customize-image.sh b/image/armbian/userpatches/customize-image.sh new file mode 100644 index 0000000..cfabf54 --- /dev/null +++ b/image/armbian/userpatches/customize-image.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# arguments: $RELEASE $LINUXFAMILY $BOARD $BUILD_DESKTOP +# +# This is the image customization script + +# NOTE: It is copied to /tmp directory inside the image +# and executed there inside chroot environment +# so don't reference any files that are not already installed + +# NOTE: If you want to transfer files between chroot and host +# userpatches/overlay directory on host is bind-mounted to /tmp/overlay in chroot +# The sd card's root path is accessible via $SDCARD variable. + +RELEASE=$1 +LINUXFAMILY=$2 +BOARD=$3 +BUILD_DESKTOP=$4 +OVERLAY="/tmp/overlay" + +EnableKernelModules() { + echo "sch_netem" >> /etc/modules + echo "br_netfilter" >> /etc/modules +} + +ConfigureNetwork() { + install -v -m 700 "${OVERLAY}/update-network-interfaces" "/usr/local/bin" + install -v -m 644 "${OVERLAY}/update-network-interfaces.service" "/etc/systemd/system/" + rm -f "/etc/systemd/system/multi-user.target.wants/update-network-interfaces.service" + ln -s "/etc/systemd/system/update-network-interfaces.service" "/etc/systemd/system/multi-user.target.wants/update-network-interfaces.service" + # nanopi-r2s board support installs a udev rule to rename eth1 -> lan0. + # We don't need that. + rm -f "/etc/udev/rules.d/70-rename-lan.rules" +} + +FixupHaveged() { + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=866306 + sed -i -e 's/DAEMON_ARGS="\?\([^"]*\)"\?/DAEMON_ARGS="\1 -d 16"/g' "/etc/default/haveged" +} + +InstallZnail() { + install -d "/opt/znail" + install -v -m 600 "${OVERLAY}/requirements.txt" "/opt/znail/requirements.txt" + install -v -m 600 -D -t "/opt/znail" "${OVERLAY}"/*.whl + pushd "/opt/znail" + python3 -m venv venv + source "venv/bin/activate" + pip3 install wheel + pip3 install -r requirements.txt + pip3 install *.whl + popd + install -v -m 644 "${OVERLAY}/znail.service" "/etc/systemd/system/" + rm -f "/etc/systemd/system/multi-user.target.wants/znail.service" + ln -s "/etc/systemd/system/znail.service" "/etc/systemd/system/multi-user.target.wants/znail.service" + # Fake hub-ctrl to make znail start + rm -f "/usr/local/bin/hub-ctrl" + ln -s "/usr/bin/true" "/usr/local/bin/hub-ctrl" +} + +EnableKernelModules "$@" +ConfigureNetwork "$@" +FixupHaveged "$@" +InstallZnail "$@" diff --git a/image/armbian/userpatches/lib.config b/image/armbian/userpatches/lib.config new file mode 100644 index 0000000..c9625fa --- /dev/null +++ b/image/armbian/userpatches/lib.config @@ -0,0 +1,2 @@ +PACKAGE_LIST_ADDITIONAL="$PACKAGE_LIST_ADDITIONAL bridge-utils ebtables iptables dnsmasq python3 python3-pip python3-venv python3-wheel git tcpdump vim" +PACKAGE_LIST_RM="$PACKAGE_LIST_RM smartmontools" diff --git a/image/stage3/02-install-services/files/update-network-interfaces b/image/common/files/update-network-interfaces similarity index 100% rename from image/stage3/02-install-services/files/update-network-interfaces rename to image/common/files/update-network-interfaces diff --git a/image/stage3/02-install-services/files/update-network-interfaces.service b/image/common/files/update-network-interfaces.service similarity index 100% rename from image/stage3/02-install-services/files/update-network-interfaces.service rename to image/common/files/update-network-interfaces.service diff --git a/image/stage3/02-install-services/files/znail.service b/image/common/files/znail.service similarity index 100% rename from image/stage3/02-install-services/files/znail.service rename to image/common/files/znail.service diff --git a/image/config b/image/raspbian/config similarity index 100% rename from image/config rename to image/raspbian/config diff --git a/image/stage3/00-install-packages/00-packages b/image/raspbian/stage3/00-install-packages/00-packages similarity index 100% rename from image/stage3/00-install-packages/00-packages rename to image/raspbian/stage3/00-install-packages/00-packages diff --git a/image/stage3/01-install-python-packages/00-run.sh b/image/raspbian/stage3/01-install-python-packages/00-run.sh similarity index 100% rename from image/stage3/01-install-python-packages/00-run.sh rename to image/raspbian/stage3/01-install-python-packages/00-run.sh diff --git a/image/stage3/01-install-python-packages/files/.keep b/image/raspbian/stage3/01-install-python-packages/files/.keep similarity index 100% rename from image/stage3/01-install-python-packages/files/.keep rename to image/raspbian/stage3/01-install-python-packages/files/.keep diff --git a/image/stage3/02-install-services/00-run.sh b/image/raspbian/stage3/02-install-services/00-run.sh similarity index 100% rename from image/stage3/02-install-services/00-run.sh rename to image/raspbian/stage3/02-install-services/00-run.sh diff --git a/image/stage3/02-install-services/files/locale b/image/raspbian/stage3/02-install-services/files/locale similarity index 100% rename from image/stage3/02-install-services/files/locale rename to image/raspbian/stage3/02-install-services/files/locale diff --git a/image/stage3/02-install-services/files/modules b/image/raspbian/stage3/02-install-services/files/modules similarity index 100% rename from image/stage3/02-install-services/files/modules rename to image/raspbian/stage3/02-install-services/files/modules diff --git a/image/stage3/EXPORT_IMAGE b/image/raspbian/stage3/EXPORT_IMAGE similarity index 100% rename from image/stage3/EXPORT_IMAGE rename to image/raspbian/stage3/EXPORT_IMAGE diff --git a/image/stage3/prerun.sh b/image/raspbian/stage3/prerun.sh similarity index 100% rename from image/stage3/prerun.sh rename to image/raspbian/stage3/prerun.sh