Created
January 23, 2014 23:08
-
-
Save alexclifford/8588689 to your computer and use it in GitHub Desktop.
Reformat an SD card
This file contains 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/sh | |
TARGETDISK="/dev/mmcblk0" | |
TARGETPARTITION="p1" | |
MOUNTPOINT="/media/mmcblk0p1" | |
# Unmount the current SD card | |
echo "Unmounting SD card..." | |
umount $MOUNTPOINT | |
echo "" | |
# Delete the current partition on the disk (there is only 1) | |
echo "Deleting existing partition..." | |
echo "d | |
w" | fdisk $TARGETDISK | |
echo "" | |
# Re-create FAT32 partition | |
echo "Re-creating FAT32 partition..." | |
echo "n | |
p | |
1 | |
t | |
b | |
w" | fdisk $TARGETDISK | |
echo "" | |
echo "Waiting 5 seconds for partition to prepare..." | |
sleep 5 | |
echo "" | |
echo "Unmounting new partition and creating the DOS file system..." | |
umount $MOUNTPOINT | |
mkdosfs -v $TARGETDISK$TARGETPARTITION | |
echo "" | |
echo "Re-mounting the new, fresh file system..." | |
sleep 2 | |
mount $TARGETDISK$TARGETPARTITION $MOUNTPOINT | |
echo "Complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment