Created
March 21, 2015 18:15
-
-
Save johncant/0b50ca6d7dc26e50f127 to your computer and use it in GitHub Desktop.
Use rooted Android phone to write Raspberry Pi image to microSSD card
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 | |
# Use a rooted android phone to load a raspberry pi image onto a microSSD card. | |
# | |
# adb push /dev/block/$PHONEBLOCKDEVICE | |
# won't work because you are not root by default | |
# | |
# Commands like | |
# cat $IMAGEFILE | adb su -c dd of=/dev/block/$PHONEBLOCKDEVICE | |
# won't work because adb corrupts the stream | |
# | |
# adb push $IMAGEFILE /path/to/writable/memory/image | |
# won't work unless your phone can fit the im#!/bin/bash | |
# | |
# You need a script to copy the file in many chunks | |
#!/bin/bash | |
IMAGEFILE=$1 | |
PHONEBLOCKDEVICE=$2 | |
BS=1048576 | |
STEP=16 | |
usage () { | |
echo "write_sd_image IMAGEFILE PHONEBLOCKDEVICE" | |
exit | |
} | |
if [[ -z "$IMAGEFILE" ]] | |
then | |
echo "Please supply IMAGEFILE" | |
usage | |
fi | |
if [[ -z "$PHONEBLOCKDEVICE" ]] | |
then | |
echo "Please supply PHONEBLOCKDEVICE" | |
usage | |
fi | |
LOCATION=0 | |
CHUNK_ID=0 | |
while true | |
do | |
CHUNK="$IMAGEFILE.$CHUNK_ID" | |
echo "Writing chunk $CHUNK_ID, location $LOCATION" | |
echo "dd if=$IMAGEFILE of=$CHUNK skip=$(($LOCATION/$BS)) count=$STEP bs=$BS" | |
dd if=$IMAGEFILE of=$CHUNK skip=$(($LOCATION/$BS)) count=$STEP bs=$BS | |
if [[ ! -s "$CHUNK" ]] | |
then | |
echo "complete" | |
exit(0) | |
fi | |
adb push $CHUNK /mnt/sdcard/$CHUNK | |
rm $CHUNK | |
adb shell su -c "busybox dd if=/mnt/sdcard/$CHUNK of=/dev/block/$PHONEBLOCKDEVICE seek=$(($LOCATION/$BS)) count=$STEP bs=$BS" | |
adb shell su -c "busybox rm /mnt/sdcard/$CHUNK" | |
CHUNK_ID=$(($CHUNK_ID+1)) | |
LOCATION=$(($LOCATION+$STEP*$BS)) | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment