2008-12-05 17:46:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2010-03-09 22:50:15 +00:00
|
|
|
basedir="$(dirname $0)"
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
SCRIPT_COMMON=common.sh
|
2010-03-09 22:50:15 +00:00
|
|
|
if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
|
|
|
|
. "${basedir}/${SCRIPT_COMMON}"
|
2009-08-18 04:35:06 +00:00
|
|
|
elif [ -f /usr/libexec/zfs/${SCRIPT_COMMON} ]; then
|
|
|
|
. /usr/libexec/zfs/${SCRIPT_COMMON}
|
|
|
|
else
|
|
|
|
echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
|
|
|
|
fi
|
|
|
|
|
2009-01-16 21:57:12 +00:00
|
|
|
PROG=zpool-create.sh
|
2008-12-05 17:46:11 +00:00
|
|
|
|
2009-01-16 20:53:12 +00:00
|
|
|
usage() {
|
|
|
|
cat << EOF
|
|
|
|
USAGE:
|
|
|
|
$0 [hvcp]
|
|
|
|
|
|
|
|
DESCRIPTION:
|
|
|
|
Create one of several predefined zpool configurations.
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h Show this message
|
|
|
|
-v Verbose
|
2010-05-18 22:05:44 +00:00
|
|
|
-f Force everything
|
2009-01-20 22:10:30 +00:00
|
|
|
-c Configuration for zpool
|
|
|
|
-p Name for zpool
|
2009-02-06 22:57:37 +00:00
|
|
|
-d Destroy zpool (default create)
|
|
|
|
-l Additional zpool options
|
|
|
|
-s Additional zfs options
|
2009-01-16 20:53:12 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
check_config() {
|
|
|
|
|
|
|
|
if [ ! -f ${ZPOOL_CONFIG} ]; then
|
2009-01-20 22:15:05 +00:00
|
|
|
local NAME=`basename ${ZPOOL_CONFIG} .sh`
|
2009-01-16 20:53:12 +00:00
|
|
|
ERROR="Unknown config '${NAME}', available configs are:\n"
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
for CFG in `ls ${ZPOOLDIR}/ | grep ".sh"`; do
|
2009-01-20 22:15:05 +00:00
|
|
|
local NAME=`basename ${CFG} .sh`
|
2009-01-16 20:53:12 +00:00
|
|
|
ERROR="${ERROR}${NAME}\n"
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
ZPOOL_CONFIG=unknown
|
2009-01-16 20:53:12 +00:00
|
|
|
ZPOOL_NAME=tank
|
2009-01-20 22:10:30 +00:00
|
|
|
ZPOOL_DESTROY=
|
2009-02-06 22:57:37 +00:00
|
|
|
ZPOOL_OPTIONS=""
|
|
|
|
ZFS_OPTIONS=""
|
2009-01-16 20:53:12 +00:00
|
|
|
|
2009-10-21 18:38:51 +00:00
|
|
|
while getopts 'hvfc:p:dl:s:' OPTION; do
|
2009-01-16 20:53:12 +00:00
|
|
|
case $OPTION in
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
v)
|
|
|
|
VERBOSE=1
|
2009-10-21 18:38:51 +00:00
|
|
|
VERBOSE_FLAG="-v"
|
|
|
|
;;
|
|
|
|
f)
|
|
|
|
FORCE=1
|
|
|
|
FORCE_FLAG="-f"
|
2009-01-16 20:53:12 +00:00
|
|
|
;;
|
|
|
|
c)
|
2009-08-18 04:35:06 +00:00
|
|
|
ZPOOL_CONFIG=${ZPOOLDIR}/${OPTARG}.sh
|
2009-01-16 20:53:12 +00:00
|
|
|
;;
|
|
|
|
p)
|
|
|
|
ZPOOL_NAME=${OPTARG}
|
|
|
|
;;
|
2009-01-20 22:10:30 +00:00
|
|
|
d)
|
|
|
|
ZPOOL_DESTROY=1
|
|
|
|
;;
|
2009-02-06 22:57:37 +00:00
|
|
|
l)
|
|
|
|
ZPOOL_OPTIONS=${OPTARG}
|
|
|
|
;;
|
|
|
|
s)
|
|
|
|
ZFS_OPTIONS=${OPTARG}
|
|
|
|
;;
|
2009-01-16 20:53:12 +00:00
|
|
|
?)
|
|
|
|
usage
|
2009-02-06 22:57:37 +00:00
|
|
|
exit 1
|
2009-01-16 20:53:12 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2009-01-16 22:51:52 +00:00
|
|
|
if [ $(id -u) != 0 ]; then
|
|
|
|
die "Must run as root"
|
|
|
|
fi
|
|
|
|
|
2009-01-16 20:53:12 +00:00
|
|
|
check_config || die "${ERROR}"
|
|
|
|
. ${ZPOOL_CONFIG}
|
|
|
|
|
2009-01-20 22:10:30 +00:00
|
|
|
if [ ${ZPOOL_DESTROY} ]; then
|
|
|
|
zpool_destroy
|
|
|
|
else
|
|
|
|
zpool_create
|
|
|
|
|
2009-02-06 22:57:37 +00:00
|
|
|
if [ "${ZPOOL_OPTIONS}" ]; then
|
|
|
|
if [ ${VERBOSE} ]; then
|
|
|
|
echo
|
2009-08-18 04:35:06 +00:00
|
|
|
echo "${ZPOOL} ${ZPOOL_OPTIONS} ${ZPOOL_NAME}"
|
2009-02-06 22:57:37 +00:00
|
|
|
fi
|
2009-08-18 04:35:06 +00:00
|
|
|
${ZPOOL} ${ZPOOL_OPTIONS} ${ZPOOL_NAME} || exit 1
|
2009-02-06 22:57:37 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${ZFS_OPTIONS}" ]; then
|
|
|
|
if [ ${VERBOSE} ]; then
|
|
|
|
echo
|
2009-08-18 04:35:06 +00:00
|
|
|
echo "${ZFS} ${ZFS_OPTIONS} ${ZPOOL_NAME}"
|
2009-02-06 22:57:37 +00:00
|
|
|
fi
|
2009-08-18 04:35:06 +00:00
|
|
|
${ZFS} ${ZFS_OPTIONS} ${ZPOOL_NAME} || exit 1
|
2009-02-06 22:57:37 +00:00
|
|
|
fi
|
|
|
|
|
2009-01-20 23:34:38 +00:00
|
|
|
if [ ${VERBOSE} ]; then
|
|
|
|
echo
|
|
|
|
echo "zpool list"
|
2009-08-18 04:35:06 +00:00
|
|
|
${ZPOOL} list || exit 1
|
2009-01-16 20:53:12 +00:00
|
|
|
|
2009-01-20 23:34:38 +00:00
|
|
|
echo
|
|
|
|
echo "zpool status ${ZPOOL_NAME}"
|
2009-08-18 04:35:06 +00:00
|
|
|
${ZPOOL} status ${ZPOOL_NAME} || exit 1
|
2009-01-20 23:34:38 +00:00
|
|
|
fi
|
2009-01-16 21:57:12 +00:00
|
|
|
fi
|
2009-01-16 20:53:12 +00:00
|
|
|
|
|
|
|
exit 0
|