Skip to content

Instantly share code, notes, and snippets.

@toreriklinnerud
Last active September 3, 2019 17:23
Show Gist options
  • Save toreriklinnerud/5b1849c096808e94c472d2b17a1e56b2 to your computer and use it in GitHub Desktop.
Save toreriklinnerud/5b1849c096808e94c472d2b17a1e56b2 to your computer and use it in GitHub Desktop.
On linux, for all connected drives under /dev/sd: unmount, wipe, format with exfat, mount
#!/bin/bash
set -e
set -o pipefail
for dev in /dev/sd?
do
if findmnt "${dev}1"
then
umount "${dev}1"
fi
wipefs $dev
printf "g\nn\n1\n\n\nt\n11\np\nw\n" | sudo fdisk "$dev"
sudo mkfs.exfat "${dev}1"
mkdir -p "/mnt${dev}"
mount "${dev}1" "/mnt${dev}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment