30 lines
804 B
Bash
Executable File
30 lines
804 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\n512\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 mkdir -p /mnt/%s && doas mount_msdos /dev/%si /mnt/%s\n" "$_dev" "$_dev" "$_dev"
|