mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-07 17:19:07 +08:00
vmtest: add mkrootfs.sh to build Arch Linux disk image
Generate a disk image for libbpf testing in compressed *.zst format The mkrootfs.sh has the following stages: - run pacstrap to install libbpf and selftests dependencies. - create /etc/fstab w/ bpffs and debugfs filesystems - create /etc/init.d/rcS to mount in bootime - create /etc/inittab to invoke /etc/init.d/rcS - compress an image In addition ./travis-ci/vmtest/run.sh set up ext4 fs and mounts it as a loop device: mkfs.ext4 -q "$tmp" mount -o loop "$tmp" "$mnt" Signed-off-by: Julia Kartseva (hex@fb.com)
This commit is contained in:
committed by
Andrii Nakryiko
parent
50febacba1
commit
10e4311ad7
146
travis-ci/vmtest/mkrootfs.sh
Executable file
146
travis-ci/vmtest/mkrootfs.sh
Executable file
@@ -0,0 +1,146 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script is based on drgn script for generating Arch Linux bootstrap
|
||||||
|
# images.
|
||||||
|
# https://github.com/osandov/drgn/blob/master/scripts/vmtest/mkrootfs.sh
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
usage () {
|
||||||
|
USAGE_STRING="usage: $0 [NAME]
|
||||||
|
$0 -h
|
||||||
|
|
||||||
|
Build an Arch Linux root filesystem image for testing libbpf in a virtual
|
||||||
|
machine.
|
||||||
|
|
||||||
|
The image is generated as a zstd-compressed tarball.
|
||||||
|
|
||||||
|
This must be run as root, as most of the installation is done in a chroot.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
NAME name of generated image file (default:
|
||||||
|
libbpf-vmtest-rootfs-\$DATE.tar.zst)
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h display this help message and exit"
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
out)
|
||||||
|
echo "$USAGE_STRING"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
err)
|
||||||
|
echo "$USAGE_STRING" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts "h" OPT; do
|
||||||
|
case "$OPT" in
|
||||||
|
h)
|
||||||
|
usage out
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage err
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
if [[ $OPTIND -eq $# ]]; then
|
||||||
|
NAME="${!OPTIND}"
|
||||||
|
elif [[ $OPTIND -gt $# ]]; then
|
||||||
|
NAME="libbpf-vmtest-rootfs-$(date +%Y.%m.%d).tar.zst"
|
||||||
|
else
|
||||||
|
usage err
|
||||||
|
fi
|
||||||
|
|
||||||
|
pacman_conf=
|
||||||
|
root=
|
||||||
|
trap 'rm -rf "$pacman_conf" "$root"' EXIT
|
||||||
|
pacman_conf="$(mktemp -p "$PWD")"
|
||||||
|
cat > "$pacman_conf" << "EOF"
|
||||||
|
[options]
|
||||||
|
Architecture = x86_64
|
||||||
|
CheckSpace
|
||||||
|
SigLevel = Required DatabaseOptional
|
||||||
|
[core]
|
||||||
|
Include = /etc/pacman.d/mirrorlist
|
||||||
|
[extra]
|
||||||
|
Include = /etc/pacman.d/mirrorlist
|
||||||
|
[community]
|
||||||
|
Include = /etc/pacman.d/mirrorlist
|
||||||
|
EOF
|
||||||
|
root="$(mktemp -d -p "$PWD")"
|
||||||
|
|
||||||
|
packages=(
|
||||||
|
busybox
|
||||||
|
# libbpf dependencies.
|
||||||
|
libelf
|
||||||
|
zlib
|
||||||
|
# selftests test_progs dependencies.
|
||||||
|
binutils
|
||||||
|
elfutils
|
||||||
|
glibc
|
||||||
|
# selftests test_verifier dependencies.
|
||||||
|
libcap
|
||||||
|
)
|
||||||
|
|
||||||
|
pacstrap -C "$pacman_conf" -cGM "$root" "${packages[@]}"
|
||||||
|
|
||||||
|
# Remove unnecessary files from the chroot.
|
||||||
|
|
||||||
|
# We don't need the pacman databases anymore.
|
||||||
|
rm -rf "$root/var/lib/pacman/sync/"
|
||||||
|
# We don't need D, Fortran, or Go.
|
||||||
|
rm -f "$root/usr/lib/libgdruntime."* \
|
||||||
|
"$root/usr/lib/libgphobos."* \
|
||||||
|
"$root/usr/lib/libgfortran."* \
|
||||||
|
"$root/usr/lib/libgo."*
|
||||||
|
# We don't need any documentation.
|
||||||
|
rm -rf "$root/usr/share/doc" \
|
||||||
|
"$root/usr/share/help" \
|
||||||
|
"$root/usr/share/man" \
|
||||||
|
"$root/usr/share/texinfo"
|
||||||
|
|
||||||
|
chroot "${root}" /bin/busybox --install
|
||||||
|
|
||||||
|
cat > "$root/etc/fstab" << "EOF"
|
||||||
|
dev /dev devtmpfs rw,nosuid 0 0
|
||||||
|
proc /proc proc rw,nosuid,nodev,noexec 0 0
|
||||||
|
sys /sys sysfs rw,nosuid,nodev,noexec 0 0
|
||||||
|
debugfs /sys/kernel/debug debugfs mode=755,realtime 0 0
|
||||||
|
bpffs /sys/fs/bpf bpf realtime 0 0
|
||||||
|
EOF
|
||||||
|
chmod 644 "$root/etc/fstab"
|
||||||
|
|
||||||
|
cat > "$root/etc/inittab" << "EOF"
|
||||||
|
::sysinit:/etc/init.d/rcS
|
||||||
|
::ctrlaltdel:/sbin/reboot
|
||||||
|
::shutdown:/sbin/swapoff -a
|
||||||
|
::shutdown:/bin/umount -a -r
|
||||||
|
::restart:/sbin/init
|
||||||
|
EOF
|
||||||
|
chmod 644 "$root/etc/inittab"
|
||||||
|
|
||||||
|
mkdir -m 755 "$root/etc/init.d" "$root/etc/rcS.d"
|
||||||
|
cat > "$root/etc/rcS.d/S40network" << "EOF"
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
ip link set lo up
|
||||||
|
EOF
|
||||||
|
chmod 755 "$root/etc/rcS.d/S40network"
|
||||||
|
|
||||||
|
cat > "$root/etc/init.d/rcS" << "EOF"
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
/bin/mount -a
|
||||||
|
|
||||||
|
for path in /etc/rcS.d/S*; do
|
||||||
|
[ -x "$path" ] && "$path"
|
||||||
|
done
|
||||||
|
EOF
|
||||||
|
chmod 755 "$root/etc/init.d/rcS"
|
||||||
|
|
||||||
|
chmod 755 "$root"
|
||||||
|
tar -C "$root" -c . | zstd -T0 -19 -o "$NAME"
|
||||||
|
chmod 644 "$NAME"
|
||||||
Reference in New Issue
Block a user