dotfiles/.bin/format-fat32.sh
2025-01-08 08:15:25 +01:00

30 lines
761 B
Bash
Executable File

#!/bin/sh -e
_dev="$1"
[ -z $_dev ] && printf "usage: %s <sd2>\n" "$(basename $0)" && exit 2
[ $(id -u) -gt 0 ] && printf "you need superuser rights\n" && exit 2
dmesg | grep "$_dev" | grep -A1 scsibus | tail -n 2
printf "Format ${_dev} [y/N]? "
read
case $REPLY in
[yY]) ;;
*) exit 0; ;;
esac
printf "Overwriting first MBs with zeros:"
dd of=/dev/r${_dev}c if=/dev/zero bs=1M count=1 > /dev/null 2>&1
printf " ✅\n"
printf "Creating FAT32 partition:"
echo "edit 0\n0B\n\n1024\n*\nw\nq\n" | fdisk -e "$_dev" > /dev/null 2>&1
printf " ✅\n"
printf "Creating FAT32 file system (this may take a while)...\n"
newfs_msdos -F32 -b65536 "${_dev}i"
printf "Creating FAT32 file system: ✅\n"
printf "Mount:\ndoas mount_msdos /dev/%si /mnt\n" "$_dev"