1#!/bin/bash 2# Copyright 2016 syzkaller project authors. All rights reserved. 3# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 4 5# create-image.sh creates a minimal Debian-wheezy Linux image suitable for syzkaller. 6 7set -eux 8 9# Create a minimal Debian-wheezy distributive as a directory. 10RELEASE=wheezy 11DIR=wheezy 12sudo rm -rf $DIR 13mkdir -p $DIR 14sudo debootstrap --include=openssh-server,curl,tar,gcc,libc6-dev,time,strace,sudo,less,psmisc,selinux-utils,policycoreutils,checkpolicy,selinux-policy-default $RELEASE $DIR 15 16# Set some defaults and enable promtless ssh to the machine for root. 17sudo sed -i '/^root/ { s/:x:/::/ }' $DIR/etc/passwd 18echo 'T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100' | sudo tee -a $DIR/etc/inittab 19printf '\nauto eth0\niface eth0 inet dhcp\n' | sudo tee -a $DIR/etc/network/interfaces 20echo 'debugfs /sys/kernel/debug debugfs defaults 0 0' | sudo tee -a $DIR/etc/fstab 21echo 'binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0' | sudo tee -a $DIR/etc/fstab 22echo 'SELINUX=disabled' | sudo tee $DIR/etc/selinux/config 23echo "kernel.printk = 7 4 1 3" | sudo tee -a $DIR/etc/sysctl.conf 24echo 'debug.exception-trace = 0' | sudo tee -a $DIR/etc/sysctl.conf 25echo "net.core.bpf_jit_enable = 1" | sudo tee -a $DIR/etc/sysctl.conf 26echo "net.core.bpf_jit_kallsyms = 1" | sudo tee -a $DIR/etc/sysctl.conf 27echo "net.core.bpf_jit_harden = 0" | sudo tee -a $DIR/etc/sysctl.conf 28echo "kernel.softlockup_all_cpu_backtrace = 1" | sudo tee -a $DIR/etc/sysctl.conf 29echo "kernel.kptr_restrict = 0" | sudo tee -a $DIR/etc/sysctl.conf 30echo "kernel.watchdog_thresh = 60" | sudo tee -a $DIR/etc/sysctl.conf 31echo "net.ipv4.ping_group_range = 0 65535" | sudo tee -a $DIR/etc/sysctl.conf 32echo -en "127.0.0.1\tlocalhost\n" | sudo tee $DIR/etc/hosts 33echo "nameserver 8.8.8.8" | sudo tee -a $DIR/etc/resolve.conf 34echo "syzkaller" | sudo tee $DIR/etc/hostname 35ssh-keygen -f $RELEASE.id_rsa -t rsa -N '' 36sudo mkdir -p $DIR/root/.ssh/ 37cat $RELEASE.id_rsa.pub | sudo tee $DIR/root/.ssh/authorized_keys 38 39# Build a disk image 40dd if=/dev/zero of=$RELEASE.img bs=1M seek=2047 count=1 41sudo mkfs.ext4 -F $RELEASE.img 42sudo mkdir -p /mnt/$DIR 43sudo mount -o loop $RELEASE.img /mnt/$DIR 44sudo cp -a $DIR/. /mnt/$DIR/. 45sudo umount /mnt/$DIR 46