]> git.proxmox.com Git - mirror_zfs-debian.git/blame - scripts/zpool-create.sh
Merge tag 'upstream/0.6.5.10'
[mirror_zfs-debian.git] / scripts / zpool-create.sh
CommitLineData
c9c0d073
BB
1#!/bin/bash
2
3basedir="$(dirname $0)"
4
5SCRIPT_COMMON=common.sh
6if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
7. "${basedir}/${SCRIPT_COMMON}"
8else
9echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
10fi
11
12PROG=zpool-create.sh
13
14usage() {
15cat << EOF
16USAGE:
ea04106b 17$0 [hvfxcp]
c9c0d073
BB
18
19DESCRIPTION:
20 Create one of several predefined zpool configurations.
21
22OPTIONS:
23 -h Show this message
24 -v Verbose
25 -f Force everything
ea04106b 26 -x Disable all zpool features
c9c0d073
BB
27 -c Configuration for zpool
28 -p Name for zpool
29 -d Destroy zpool (default create)
30 -l Additional zpool options
31 -s Additional zfs options
32
33EOF
34}
35
36check_config() {
37
38 if [ ! -f ${ZPOOL_CONFIG} ]; then
39 local NAME=`basename ${ZPOOL_CONFIG} .sh`
40 ERROR="Unknown config '${NAME}', available configs are:\n"
41
42 for CFG in `ls ${ZPOOLDIR}/ | grep ".sh"`; do
43 local NAME=`basename ${CFG} .sh`
44 ERROR="${ERROR}${NAME}\n"
45 done
46
47 return 1
48 fi
49
50 return 0
51}
52
53ZPOOL_CONFIG=unknown
54ZPOOL_NAME=tank
55ZPOOL_DESTROY=
ea04106b 56ZPOOL_FLAGS=${ZPOOL_FLAGS:-""}
c9c0d073
BB
57ZPOOL_OPTIONS=""
58ZFS_OPTIONS=""
59
ea04106b 60while getopts 'hvfxc:p:dl:s:' OPTION; do
c9c0d073
BB
61 case $OPTION in
62 h)
63 usage
64 exit 1
65 ;;
66 v)
67 VERBOSE=1
68 VERBOSE_FLAG="-v"
69 ;;
70 f)
71 FORCE=1
ea04106b
AX
72 ZPOOL_FLAGS="$ZPOOL_FLAGS -f"
73 ;;
74 x)
75 NO_FEATURES=1
76 ZPOOL_FLAGS="$ZPOOL_FLAGS -d"
c9c0d073
BB
77 ;;
78 c)
79 ZPOOL_CONFIG=${ZPOOLDIR}/${OPTARG}.sh
80 ;;
81 p)
82 ZPOOL_NAME=${OPTARG}
83 ;;
84 d)
85 ZPOOL_DESTROY=1
86 ;;
87 l)
88 ZPOOL_OPTIONS=${OPTARG}
89 ;;
90 s)
91 ZFS_OPTIONS=${OPTARG}
92 ;;
93 ?)
94 usage
95 exit 1
96 ;;
97 esac
98done
99
100if [ $(id -u) != 0 ]; then
101 die "Must run as root"
102fi
103
104check_config || die "${ERROR}"
105. ${ZPOOL_CONFIG}
106
107if [ ${ZPOOL_DESTROY} ]; then
108 zpool_destroy
109else
110 zpool_create
111
112 if [ "${ZPOOL_OPTIONS}" ]; then
113 if [ ${VERBOSE} ]; then
114 echo
115 echo "${ZPOOL} ${ZPOOL_OPTIONS} ${ZPOOL_NAME}"
116 fi
117 ${ZPOOL} ${ZPOOL_OPTIONS} ${ZPOOL_NAME} || exit 1
118 fi
119
120 if [ "${ZFS_OPTIONS}" ]; then
121 if [ ${VERBOSE} ]; then
122 echo
123 echo "${ZFS} ${ZFS_OPTIONS} ${ZPOOL_NAME}"
124 fi
125 ${ZFS} ${ZFS_OPTIONS} ${ZPOOL_NAME} || exit 1
126 fi
127
128 if [ ${VERBOSE} ]; then
129 echo
130 echo "zpool list"
131 ${ZPOOL} list || exit 1
132
133 echo
134 echo "zpool status ${ZPOOL_NAME}"
135 ${ZPOOL} status ${ZPOOL_NAME} || exit 1
136 fi
137fi
138
139exit 0