From 24dc29dba51a8ae7ae86ebc04521a0b2223c531f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 15 Oct 2021 19:08:56 +0200 Subject: tools: add script for building of buildroot images We used to use Debian-based images, but they have several issues: 1. They boot too slowly (we don't need full systemd power). 2. Systemd mounts cgroup controllers so that we can't use them during fuzzing (can be mounted only once). 3. We have poor control over contents of the image. This script creates lightweight buildroot-based images that boot fast. --- tools/create-buildroot-image.sh | 221 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100755 tools/create-buildroot-image.sh diff --git a/tools/create-buildroot-image.sh b/tools/create-buildroot-image.sh new file mode 100755 index 000000000..7f89caf23 --- /dev/null +++ b/tools/create-buildroot-image.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash +# Copyright 2021 syzkaller project authors. All rights reserved. +# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +# This script builds a buildroot-based Linux image. +# It should be run from a buildroot checkout (git://git.buildroot.net/buildroot) as: +# TARGETARCH={amd64,arm64,arm,riscv64,s390x,mips64le,ppc64le} [NOMAKE=yes] create-buildroot-image.sh +# If no NOMAKE=yes is specified, then it will just prepare the buildroot config, +# but will not run the final make. +# For amd64 it creates a bootable image with root partition +# on /dev/sda1 in output/images/disk.img file. +# For other architectures it creates a non-bootable disk +# suitable qemu injected boot with root partition on /dev/sda +# in output/images/rootfs.ext4 file. +# Note: the image requires at least kernel v4.19 +# (otherwise glibc complains about unsupported kernel version). + +set -eux + +NOMAKE="${NOMAKE:-}" +TARGETARCH="${TARGETARCH:-amd64}" +case "$TARGETARCH" in + amd64) + DEFCONFIG="pc_x86_64_bios_defconfig";; + arm64) + DEFCONFIG="qemu_aarch64_virt_defconfig";; + arm) + DEFCONFIG="qemu_arm_vexpress_defconfig";; + riscv64) + DEFCONFIG="qemu_riscv64_virt_defconfig";; + s390x) + DEFCONFIG="qemu_s390x_defconfig";; + mips64le) + DEFCONFIG="qemu_mips64r6el_malta_defconfig";; + ppc64le) + DEFCONFIG="qemu_ppc64le_pseries_defconfig";; + *) + echo "unsupported TARGETARCH=${TARGETARCH}" + exit 1;; +esac + +git fetch origin +git checkout 2021.08.x + +make "${DEFCONFIG}" + +# Common configs for all architectures. +cat >>.config <>.config <>.config <>.config <>.config <>.config <>.config <>.config <rootfs_script.sh <<'EOFEOF' +set -eux + +# Mount debugfs for KCOV and other filesystems. +cat >>$1/etc/fstab <$1/etc/ssh/sshd_config <>rootfs_script.sh <<'EOFEOF' + +# Write udev rules. +cat >$1/etc/udev/rules.d/50-syzkaller.rules <> $1/etc/udev/rules.d/50-syzkaller.rules +done + +# Override default grub config with timeout 0. +cat >$1/boot/grub/grub.cfg <