• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// AUTOGENERATED FILE
2
3package build
4
5const createImageScript = `#!/bin/bash
6
7
8set -eux
9
10CLEANUP=""
11trap 'eval " $CLEANUP"' EXIT
12
13if [ ! -e $1/sbin/init ]; then
14	echo "usage: create-gce-image.sh /dir/with/user/space/system /path/to/bzImage"
15	exit 1
16fi
17
18if [ "$(basename $2)" != "bzImage" ]; then
19	echo "usage: create-gce-image.sh /dir/with/user/space/system /path/to/bzImage"
20	exit 1
21fi
22
23SYZ_VM_TYPE="${SYZ_VM_TYPE:-qemu}"
24if [ "$SYZ_VM_TYPE" == "qemu" ]; then
25	:
26elif [ "$SYZ_VM_TYPE" == "gce" ]; then
27	:
28else
29	echo "SYZ_VM_TYPE has unsupported value $SYZ_VM_TYPE"
30	exit 1
31fi
32
33sudo umount disk.mnt || true
34if [ "$SYZ_VM_TYPE" == "qemu" ]; then
35	:
36elif [ "$SYZ_VM_TYPE" == "gce" ]; then
37	sudo modprobe nbd
38	sudo qemu-nbd -d /dev/nbd0 || true
39fi
40rm -rf disk.mnt disk.raw || true
41
42fallocate -l 2G disk.raw
43if [ "$SYZ_VM_TYPE" == "qemu" ]; then
44	DISKDEV="$(sudo losetup -f --show -P disk.raw)"
45	CLEANUP="sudo losetup -d $DISKDEV; $CLEANUP"
46elif [ "$SYZ_VM_TYPE" == "gce" ]; then
47	DISKDEV="/dev/nbd0"
48	sudo qemu-nbd -c $DISKDEV --format=raw disk.raw
49	CLEANUP="sudo qemu-nbd -d $DISKDEV; $CLEANUP"
50fi
51echo -en "o\nn\np\n1\n\n\na\nw\n" | sudo fdisk $DISKDEV
52PARTDEV=$DISKDEV"p1"
53until [ -e $PARTDEV ]; do sleep 1; done
54sudo -E mkfs.ext4 $PARTDEV
55mkdir -p disk.mnt
56CLEANUP="rm -rf disk.mnt; $CLEANUP"
57sudo mount $PARTDEV disk.mnt
58CLEANUP="sudo umount disk.mnt; $CLEANUP"
59sudo cp -a $1/. disk.mnt/.
60sudo cp $2 disk.mnt/vmlinuz
61sudo sed -i "/^root/ { s/:x:/::/ }" disk.mnt/etc/passwd
62echo "T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100" | sudo tee -a disk.mnt/etc/inittab
63echo -en "auto lo\niface lo inet loopback\nauto eth0\niface eth0 inet dhcp\n" | sudo tee disk.mnt/etc/network/interfaces
64echo "debugfs /sys/kernel/debug debugfs defaults 0 0" | sudo tee -a disk.mnt/etc/fstab
65echo 'binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0' | sudo tee -a disk.mnt/etc/fstab
66for i in {0..31}; do
67	echo "KERNEL==\"binder$i\", NAME=\"binder$i\", MODE=\"0666\"" | \
68		sudo tee -a disk.mnt/etc/udev/50-binder.rules
69done
70echo 'SELINUX=disabled' | sudo tee disk.mnt/etc/selinux/config
71
72echo "kernel.printk = 7 4 1 3" | sudo tee -a disk.mnt/etc/sysctl.conf
73echo "debug.exception-trace = 0" | sudo tee -a disk.mnt/etc/sysctl.conf
74SYZ_SYSCTL_FILE="${SYZ_SYSCTL_FILE:-}"
75if [ "$SYZ_SYSCTL_FILE" != "" ]; then
76	cat $SYZ_SYSCTL_FILE | sudo tee -a disk.mnt/etc/sysctl.conf
77fi
78
79echo -en "127.0.0.1\tlocalhost\n" | sudo tee disk.mnt/etc/hosts
80echo "nameserver 8.8.8.8" | sudo tee -a disk.mnt/etc/resolve.conf
81echo "ClientAliveInterval 420" | sudo tee -a disk.mnt/etc/ssh/sshd_config
82echo "syzkaller" | sudo tee disk.mnt/etc/hostname
83rm -f key key.pub
84ssh-keygen -f key -t rsa -N ""
85sudo mkdir -p disk.mnt/root/.ssh
86sudo cp key.pub disk.mnt/root/.ssh/authorized_keys
87sudo chown root disk.mnt/root/.ssh/authorized_keys
88sudo mkdir -p disk.mnt/boot/grub
89
90CMDLINE=""
91SYZ_CMDLINE_FILE="${SYZ_CMDLINE_FILE:-}"
92if [ "$SYZ_CMDLINE_FILE" != "" ]; then
93	CMDLINE=$(awk '{printf("%s ", $0)}' $SYZ_CMDLINE_FILE)
94fi
95
96cat << EOF | sudo tee disk.mnt/boot/grub/grub.cfg
97terminal_input console
98terminal_output console
99set timeout=0
100menuentry 'linux' --class gnu-linux --class gnu --class os {
101	insmod vbe
102	insmod vga
103	insmod video_bochs
104	insmod video_cirrus
105	insmod gzio
106	insmod part_msdos
107	insmod ext2
108	set root='(hd0,1)'
109	linux /vmlinuz root=/dev/sda1 console=ttyS0 earlyprintk=serial vsyscall=native rodata=n ftrace_dump_on_oops=orig_cpu oops=panic panic_on_warn=1 nmi_watchdog=panic panic=86400 $CMDLINE
110}
111EOF
112sudo grub-install --target=i386-pc --boot-directory=disk.mnt/boot --no-floppy $DISKDEV
113`
114