1#!/bin/bash 2# This script builds a Debian root filesystem image for testing libbpf in a 3# virtual machine. Requires debootstrap >= 1.0.95 and zstd. 4 5set -e -u -x -o pipefail 6 7# Check whether we are root now in order to avoid confusing errors later. 8if [ "$(id -u)" != 0 ]; then 9 echo "$0 must run as root" >&2 10 exit 1 11fi 12 13# Create a working directory and schedule its deletion. 14root=$(mktemp -d -p "$PWD") 15trap 'rm -r "$root"' EXIT 16 17# Install packages. 18packages=binutils,busybox,elfutils,iproute2,libcap2,libelf1,strace,zlib1g 19debootstrap --include="$packages" --variant=minbase bullseye "$root" 20 21# Remove the init scripts (tests use their own). Also remove various 22# unnecessary files in order to save space. 23rm -rf \ 24 "$root"/etc/rcS.d \ 25 "$root"/usr/share/{doc,info,locale,man,zoneinfo} \ 26 "$root"/var/cache/apt/archives/* \ 27 "$root"/var/lib/apt/lists/* 28 29# Save some more space by removing coreutils - the tests use busybox. Before 30# doing that, delete the buggy postrm script, which uses the rm command. 31rm -f "$root/var/lib/dpkg/info/coreutils.postrm" 32chroot "$root" dpkg --remove --force-remove-essential coreutils 33 34# Apply common tweaks. 35"$(dirname "$0")"/mkrootfs_tweak.sh "$root" 36 37# Save the result. 38name="libbpf-vmtest-rootfs-$(date +%Y.%m.%d).tar.zst" 39rm -f "$name" 40tar -C "$root" -c . | zstd -T0 -19 -o "$name" 41