• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# This script prepares a mounted root filesystem for testing libbpf in a virtual
3# machine.
4set -e -u -x -o pipefail
5root=$1
6shift
7
8chroot "${root}" /bin/busybox --install
9
10cat > "$root/etc/inittab" << "EOF"
11::sysinit:/etc/init.d/rcS
12::ctrlaltdel:/sbin/reboot
13::shutdown:/sbin/swapoff -a
14::shutdown:/bin/umount -a -r
15::restart:/sbin/init
16EOF
17chmod 644 "$root/etc/inittab"
18
19mkdir -m 755 -p "$root/etc/init.d" "$root/etc/rcS.d"
20cat > "$root/etc/rcS.d/S10-mount" << "EOF"
21#!/bin/sh
22
23set -eux
24
25/bin/mount proc /proc -t proc
26
27# Mount devtmpfs if not mounted
28if [[ -z $(/bin/mount -t devtmpfs) ]]; then
29	/bin/mount devtmpfs /dev -t devtmpfs
30fi
31
32/bin/mount sysfs /sys -t sysfs
33/bin/mount bpffs /sys/fs/bpf -t bpf
34/bin/mount debugfs /sys/kernel/debug -t debugfs
35
36echo 'Listing currently mounted file systems'
37/bin/mount
38EOF
39chmod 755 "$root/etc/rcS.d/S10-mount"
40
41cat > "$root/etc/rcS.d/S40-network" << "EOF"
42#!/bin/sh
43
44set -eux
45
46ip link set lo up
47EOF
48chmod 755 "$root/etc/rcS.d/S40-network"
49
50cat > "$root/etc/init.d/rcS" << "EOF"
51#!/bin/sh
52
53set -eux
54
55for path in /etc/rcS.d/S*; do
56	[ -x "$path" ] && "$path"
57done
58EOF
59chmod 755 "$root/etc/init.d/rcS"
60
61chmod 755 "$root"
62