Wiki2
format-usbdisk.sh

#!/bin/sh

# Automates the following process (BE CAREFUL !!!)

# fdisk -i sd0            
# Do you wish to write new MBR and partition table? [n] y
# Writing MBR at offset 0.
# disklabel -E sd0
# Label editor (enter '?' for help at any prompt)
# > z
# > a
# partition: [a] 
# offset: [64] 
# size: [15165296] 
# FS type: [4.2BSD] 
# Rounding size to bsize (32 sectors): 15165280
# > w
# > q
# No label changes.

DISK=$1

[ -z "$1" ] && {
    echo "use: format-usbdisk.sh sd0"
    exit
}

echo "disk $DISK will be formatted ..."

fdisk -i $DISK 2>&1 > /tmp/format-usbdisk.log << __EOT__
y
__EOT__

disklabel -E $DISK 2>&1 >> /tmp/format-usbdisk.log << __EOT__
z
a




w
q
__EOT__