Skip to content

Instantly share code, notes, and snippets.

@dweeber
Created September 9, 2012 18:34
Show Gist options
  • Save dweeber/3686318 to your computer and use it in GitHub Desktop.
Save dweeber/3686318 to your computer and use it in GitHub Desktop.
Sample code of determining the size of the partition.
DISK_SIZE="4" # set this to the card size in nominal GB
# or: DISK_SIZE="$(($(sudo blockdev --getsz /dev/mmcblk0)/2048/925))"
PART_START="$(sudo parted /dev/mmcblk0 -ms unit s p |grep "^2" |cut -f2 -d:)"
[ "$PART_START" ] || exit 1
PART_END="$((DISK_SIZE*925*2048-1))"
[ "$PART_END" -ge 3788799 ] || exit 1
printf "d\n2\nn\np\n2\n$PART_START\n$PART_END\np\nw\n" |sudo fdisk /dev/mmcblk0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment