Skip to content

Instantly share code, notes, and snippets.

@themactep
Created March 10, 2023 22:17
Show Gist options
  • Save themactep/d0b72f4c5d5f246e2551622e95bc9987 to your computer and use it in GitHub Desktop.
Save themactep/d0b72f4c5d5f246e2551622e95bc9987 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Format SD card to two small FAT32 partitions
# for guaranteed usage with embedded devices
# Paul Philippov <paul@themactep.com>
#
show_help() {
echo "Usage: $0 [OPTIONS]>
Where:
-d <device> SD Card device (e.g. /dev/sdc).
-h Show this help.
"
echo "Possible devices:"
sudo fdisk -x | grep -B1 SD | head -1 | awk '{print $2}' | sed 's/://'
exit 1
}
# command line arguments
while getopts d:h flag; do
case ${flag} in
d) card_device=${OPTARG} ;;
h) show_help ;;
esac
done
if [ -z "$card_device" ]; then
show_help
exit 1
fi
# create
sudo parted ${card_device} mklabel msdos
# create first partition
sudo parted ${card_device} mkpart primary fat32 1MB 64MB
sudo mkfs.vfat -F32 ${card_device}1
# create second partition
sudo parted ${card_device} mkpart primary fat32 64MB 128MB
sudo mkfs.vfat -F32 ${card_device}2
# show partitions
sudo parted ${card_device} print
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment