Created
March 10, 2023 22:17
-
-
Save themactep/d0b72f4c5d5f246e2551622e95bc9987 to your computer and use it in GitHub Desktop.
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/sh | |
# | |
# Format SD card to two small FAT32 partitions | |
# for guaranteed usage with embedded devices | |
# Paul Philippov <[email protected]> | |
# | |
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