Created
August 26, 2020 08:44
-
-
Save rgerganov/96c99aff7abdd484f3b0096cddb5d554 to your computer and use it in GitHub Desktop.
Create VMDK disk suitable for syzkaller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VMDK_FILE="syzkaller.vmdk" | |
VMDK_SIZE="3GB" | |
NBD_DEV="/dev/nbd0" | |
NBD_DEVP1="${NBD_DEV}p1" | |
MOUNT_DIR="/tmp/vmdk" | |
ROOTFS="${1:-stretch.img}" | |
echo "Using ROOTFS=$ROOTFS" | |
KERNEL="${2:-bzImage}" | |
echo "Using KERNEL=$KERNEL" | |
[[ -e $ROOTFS ]] || { | |
echo "$ROOTFS: File not found" | |
exit 1 | |
} | |
[[ -e $KERNEL ]] || { | |
echo "$KERNEL: File not found" | |
exit 1 | |
} | |
# Create empty VMDK | |
vmware-vdiskmanager -c -s $VMDK_SIZE -t 0 -a ide "$VMDK_FILE" | |
# Partition the VMDK | |
sudo qemu-nbd -c $NBD_DEV "$VMDK_FILE" | |
( | |
echo n # Add a new partition | |
echo p # Primary partition | |
echo 1 # Partition number | |
echo # First sector (Accept default) | |
echo # Last sector (Accept default) | |
echo w # Write changes | |
) | sudo fdisk $NBD_DEV | |
# Write the root fs | |
sudo dd if="$ROOTFS" of=$NBD_DEVP1 | |
# Mount the root fs | |
mkdir -p "$MOUNT_DIR" | |
sudo mount $NBD_DEVP1 "$MOUNT_DIR" | |
# Install bootloader | |
sudo grub-install --target=i386-pc --boot-directory="$MOUNT_DIR/boot" $NBD_DEV | |
# Install kernel | |
sudo cp "$KERNEL" "$MOUNT_DIR/boot/bzImage" | |
# Configure the bootloader | |
cat << EOF | sudo tee "$MOUNT_DIR/boot/grub/grub.cfg" | |
insmod ext2 | |
set timeout=5 | |
menuentry 'Syzkaller' { | |
insmod ext2 | |
linux /boot/bzImage root=/dev/sda1 | |
} | |
EOF | |
# Cleanup | |
sudo umount $MOUNT_DIR | |
sudo qemu-nbd -d $NBD_DEV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment