I used the following at my prior employer so it has some base assumptions in it from that enviroment.
Code:
#!/bin/bash
# First parameter should be the device to format <Required>
# second parameter is the Label for the partition <Required>
# third parameter is the mount point <Optional>
#
# Note This is designed to setup an entire "disk/LUN" as 1 partition.
# It is designed to produce "VAULTs" for TapeLabs VTS as used at some prior employer.
#
# !!!! this script needs to be run as ROOT for fdisk and mke2fs to be
# found in $PATH << JHC >>
#
if [ $# -lt 2 ]; then
echo "usage Format_Vault requires a device, fdisk comand file, and Label fields"
echo "Format_Vault.sh device lab [Mount]"
echo "where device is the disk to be formated (sda,sdb,sdc,...)"
echo " Label is the label to put on the first partition"
echo " Mount is the optional mount point relative to /"
exit 1
fi
if [ $# -gt 3 ]; then
echo "warning more than 3 parameters provided extras ignored"
fi
if [ -z $1 ];then
echo " error on device param => ${1}"
exit 1
fi
device="${1}"
#
if $( echo $2 | grep --quiet -P '^VAULT\d\d$' )
then
lab="${2}"
else
echo " Label field is not of form VAULTnn => ${2}"
exit 1
fi
device=${device##/dev/}
part=${device}1
echo " fdisk /dev/${device}"
# call fdisk on device /dev/$1 with input
# New
# Primary
# 1'st partition
# default starting address
# default ending address
# Write
fdisk /dev/"${device}" <<EOF1
n
p
1
w
EOF1
fdisk /dev/"${device}" <<EOF2
p
EOF2
# format the partition just created
echo "mke2fs -j -L /${lab} /dev/${part}"
mke2fs -j -L /"${lab}" /dev/"${part}"
if [ ${#3} -eq '7' ]; then
echo "mkdir /${3}"
mkdir /${3}
fi
You will need to make changes to it if you use it.