2017-06-01 13:54:10 +00:00
|
|
|
// AUTOGENERATED FILE
|
|
|
|
|
|
|
|
package kernel
|
|
|
|
|
|
|
|
const createImageScript = `#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
set -eux
|
|
|
|
|
2017-07-17 12:45:10 +00:00
|
|
|
trap "" SIGINT
|
|
|
|
|
2017-06-01 13:54:10 +00:00
|
|
|
if [ ! -e $1/sbin/init ]; then
|
2017-06-17 15:06:29 +00:00
|
|
|
echo "usage: create-gce-image.sh /dir/with/user/space/system /path/to/bzImage"
|
2017-06-01 13:54:10 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$(basename $2)" != "bzImage" ]; then
|
2017-06-17 15:06:29 +00:00
|
|
|
echo "usage: create-gce-image.sh /dir/with/user/space/system /path/to/bzImage"
|
2017-06-01 13:54:10 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
sudo umount disk.mnt || true
|
|
|
|
sudo qemu-nbd -d /dev/nbd0 || true
|
|
|
|
rm -rf disk.mnt disk.raw tag obj || true
|
|
|
|
|
|
|
|
sudo modprobe nbd
|
|
|
|
fallocate -l 2G disk.raw
|
|
|
|
sudo qemu-nbd -c /dev/nbd0 --format=raw disk.raw
|
|
|
|
mkdir -p disk.mnt
|
|
|
|
echo -en "o\nn\np\n1\n2048\n\na\n1\nw\n" | sudo fdisk /dev/nbd0
|
|
|
|
until [ -e /dev/nbd0p1 ]; do sleep 1; done
|
|
|
|
sudo mkfs.ext4 /dev/nbd0p1
|
|
|
|
sudo mount /dev/nbd0p1 disk.mnt
|
|
|
|
sudo cp -a $1/. disk.mnt/.
|
|
|
|
sudo cp $2 disk.mnt/vmlinuz
|
|
|
|
sudo sed -i "/^root/ { s/:x:/::/ }" disk.mnt/etc/passwd
|
|
|
|
echo "T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100" | sudo tee -a disk.mnt/etc/inittab
|
|
|
|
echo -en "auto lo\niface lo inet loopback\nauto eth0\niface eth0 inet dhcp\n" | sudo tee disk.mnt/etc/network/interfaces
|
|
|
|
echo "debugfs /sys/kernel/debug debugfs defaults 0 0" | sudo tee -a disk.mnt/etc/fstab
|
2017-11-27 14:08:32 +00:00
|
|
|
for i in {0..31}; do
|
|
|
|
echo "KERNEL==\"binder$i\", NAME=\"binder$i\", MODE=\"0666\"" | \
|
|
|
|
tee -a disk.mnt/etc/udev/50-binder.rules
|
|
|
|
done
|
2017-07-17 10:36:05 +00:00
|
|
|
|
2017-06-01 13:54:10 +00:00
|
|
|
echo "kernel.printk = 7 4 1 3" | sudo tee -a disk.mnt/etc/sysctl.conf
|
|
|
|
echo "debug.exception-trace = 0" | sudo tee -a disk.mnt/etc/sysctl.conf
|
2017-07-17 11:55:55 +00:00
|
|
|
SYZ_SYSCTL_FILE="${SYZ_SYSCTL_FILE:-}"
|
|
|
|
if [ "$SYZ_SYSCTL_FILE" != "" ]; then
|
2017-07-17 10:36:05 +00:00
|
|
|
cat $SYZ_SYSCTL_FILE | sudo tee -a disk.mnt/etc/sysctl.conf
|
|
|
|
fi
|
|
|
|
|
2017-06-01 13:54:10 +00:00
|
|
|
echo -en "127.0.0.1\tlocalhost\n" | sudo tee disk.mnt/etc/hosts
|
|
|
|
echo "nameserver 8.8.8.8" | sudo tee -a disk.mnt/etc/resolve.conf
|
|
|
|
echo "ClientAliveInterval 420" | sudo tee -a disk.mnt/etc/ssh/sshd_config
|
|
|
|
echo "syzkaller" | sudo tee disk.mnt/etc/hostname
|
|
|
|
rm -f key key.pub
|
|
|
|
ssh-keygen -f key -t rsa -N ""
|
|
|
|
sudo mkdir -p disk.mnt/root/.ssh
|
|
|
|
sudo cp key.pub disk.mnt/root/.ssh/authorized_keys
|
|
|
|
sudo chown root disk.mnt/root/.ssh/authorized_keys
|
|
|
|
sudo mkdir -p disk.mnt/boot/grub
|
2017-07-17 10:36:05 +00:00
|
|
|
|
|
|
|
CMDLINE=""
|
2017-07-17 11:55:55 +00:00
|
|
|
SYZ_CMDLINE_FILE="${SYZ_CMDLINE_FILE:-}"
|
|
|
|
if [ "$SYZ_CMDLINE_FILE" != "" ]; then
|
2017-07-17 10:36:05 +00:00
|
|
|
CMDLINE=$(awk '{printf("%s ", $0)}' $SYZ_CMDLINE_FILE)
|
|
|
|
fi
|
|
|
|
|
2017-06-01 13:54:10 +00:00
|
|
|
cat << EOF | sudo tee disk.mnt/boot/grub/grub.cfg
|
|
|
|
terminal_input console
|
|
|
|
terminal_output console
|
|
|
|
set timeout=0
|
|
|
|
menuentry 'linux' --class gnu-linux --class gnu --class os {
|
|
|
|
insmod vbe
|
|
|
|
insmod vga
|
|
|
|
insmod video_bochs
|
|
|
|
insmod video_cirrus
|
|
|
|
insmod gzio
|
|
|
|
insmod part_msdos
|
|
|
|
insmod ext2
|
|
|
|
set root='(hd0,1)'
|
2017-07-17 10:36:05 +00:00
|
|
|
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
|
2017-06-01 13:54:10 +00:00
|
|
|
}
|
|
|
|
EOF
|
2017-08-11 18:04:33 +00:00
|
|
|
sudo grub-install --target=i386-pc --boot-directory=disk.mnt/boot --no-floppy /dev/nbd0
|
2017-06-01 13:54:10 +00:00
|
|
|
sudo umount disk.mnt
|
|
|
|
rm -rf disk.mnt
|
|
|
|
sudo qemu-nbd -d /dev/nbd0
|
|
|
|
`
|