Skip to content

Instantly share code, notes, and snippets.

@maxsu
Created August 24, 2013 06:09
Show Gist options
  • Save maxsu/6326369 to your computer and use it in GitHub Desktop.
Save maxsu/6326369 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -ne 1 ]; then
echo "usage: $0 [raspbian image]"
exit 1
elif [ ! -f $1 ]; then
echo "Error: File $1 not found." >&2
exit 1
fi
DISKIMAGE="$1"
create_start_script() {
cat > raspbian-start << EOF
#!/bin/sh
qemu-system-arm -cpu arm1176 -M versatilepb -m 256 -hda $DISKIMAGE -append 'root=/dev/sda2 panic=1' -no-reboot -kernel kernel-qemu -redir tcp:2222::22
EOF
chmod +x raspbian-start
echo "Raspbian can be booted using ./raspbian-start"
}
guestfish -a $DISKIMAGE << EOF
run
mount /dev/vda2 /
#mount /dev/vda1 /boot
#download /boot/kernel.img kernel-raspberry
download /etc/fstab tmp-fstab
download /usr/bin/raspi-config tmp-raspi-config
#sed -e 's:mmcblk0p2:sda2:g' -e 's:mmcblk0:sda:g'
! sed -i -e 's:mmcblk0p\([0-9]\):sda\1:g' -e 's:mmcblk0:sda:g' tmp-fstab tmp-raspi-config
upload tmp-fstab /etc/fstab
upload tmp-raspi-config /usr/bin/raspi-config
download /etc/ld.so.preload tmp-preload
! sed -i 's/^[^#].*/#&/g' tmp-preload
upload tmp-preload /etc/ld.so.preload
EOF
if [ ! -f kernel-qemu ]; then
if wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu ; then : else
echo "Error downloading qemu kernel" >&2
exit 1
fi
fi
if [ -f raspbian-start ]; then
echo -n "Do you want to overwite 'raspbian-start' (y/n) "
read answer
case $answer in
Y*|y*|T*|t*)
create_start_script ;;
*)
exit 0 ;;
esac
else
create_start_script
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment