Skip to content

Instantly share code, notes, and snippets.

@bradfa
Created December 19, 2011 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradfa/1497952 to your computer and use it in GitHub Desktop.
Save bradfa/1497952 to your computer and use it in GitHub Desktop.
Format SD card with /dev/sdX style card reader
#!/bin/sh
if [ ! "$1" = "/dev/sda" ] ; then
DRIVE=$1
if [ -b "$DRIVE" ] ; then
dd if=/dev/zero of=$DRIVE bs=1024 count=1024
SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`
echo DISK SIZE - $SIZE bytes
CYLINDERS=`echo $SIZE/128/32/512 | bc`
echo CYLINDERS - $CYLINDERS
{
echo 4,32,0x0C,*
echo 36,,,-
} | sfdisk -D -H 128 -S 32 -C $CYLINDERS $DRIVE
mkfs.vfat -F 32 -n "boot" ${DRIVE}1
mke2fs -j -L "rootfs" ${DRIVE}2
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment