Statistiques
| Révision :

root / bin / create-volume @ 39

Historique | Voir | Annoter | Télécharger (3,82 ko)

1
#!/bin/bash
2
# $Id: create-volume 39 2013-10-08 12:46:21Z ltaulell $
3

    
4
function usage {
5
echo "Syntax :" 1>&2
6
echo "$0 [options]" 1>&2
7
echo " -n : volume name" 1>&2
8
echo " -p : pool name" 1>&2
9
echo " -b : block size. Permit value : 32K, 64K, 128K (recommanded)" 1>&2
10
echo " -s : volume size. Permit unit : T, G, M"  1>&2
11
echo " -o : options zfs volume. Read the man zfs for more details" 1>&2
12

    
13
}
14

    
15

    
16
function nointeractive {
17

    
18
if [[ -z $VOL_OPTION ]]
19
then
20
/sbin/zfs create -s -b $BLOCK_SIZE -V $SIZE $NAME_POOL/$NAME
21
else
22
/sbin/zfs create -s -b $BLOCK_SIZE -o $VOL_OPTION -V $SIZE $NAME_POOL/$NAME
23
fi
24

    
25
}
26

    
27

    
28
function interactive {
29
zfs list
30
echo "*** Choose a pool for the ZFS volume to create : ***"
31

    
32
while read inputline
33
do
34
   if [ "$inputline" != "" ]
35
   then
36
      zfs list |grep -i $inputline
37
      if [ $? -eq 1 ]
38
      then
39
         echo "*** Choose a pool for the ZFS volume to create : ***"
40
      else
41

    
42
         echo "*** Are you sur : $inputline ? (y/n) ***"
43
         while read inputConfirm
44
         do
45
            if [ "$inputConfirm" = "y" ]||[ "$inputConfirm" = "n" ]
46
            then
47
              break
48
            fi
49
            echo "*** Are you sur : $inputline ? (y/n) ***"
50
          done
51

    
52
          if [ "$inputConfirm" = "y" ]
53
          then
54
             NAME_POOL=$inputline
55
             echo "volume name : "
56
             while read inputVolume
57
             do
58
                if [ "$inputVolume" != "" ]
59
                then
60
                   test -d /dev/zvol
61
                   if [ $? -eq 0 ]
62
                   then
63
                      ls -l /dev/zvol/$NAME_POOL/$inputVolume
64
                      if [ $? -eq 0 ]
65
                      then
66
                         echo "volume name already exists"
67
                         VOL_OK=1   
68
                      else
69
                         VOL_OK=0
70
                      fi
71
                   else
72
                      VOL_OK=0 
73
                   fi
74
                   if [ $VOL_OK -eq 1 ]
75
                   then
76
                      echo "volume name : "
77
                   else
78
                      NAME_VOL=$inputVolume
79
                      echo "volume size (Unit in T|G|M) : "
80
                      while read inputSize
81
                      do
82
                         if [ "$inputSize" != "" ]
83
                         then
84
                           zfs create -s -b 128K -V $inputSize  $NAME_POOL/$inputVolume
85
                           if [ $? -eq 0 ]
86
                           then
87
                              echo "*** ZFS volume creation [OK] ***" 
88
                              zfs list
89
                              break
90
                           else
91
                              echo "/!\\ ZFS volume creation [ERROR] /!\\"
92
                           fi
93
                        else
94
                           echo "volume size (Unit in T|G|M) : "   
95
                        fi
96
                      done
97
                      break
98
                    fi
99
                else
100
                  echo "volume name : "
101
                fi
102
             done
103
             break
104
          fi
105
          break
106
      fi
107
   else
108
      echo "*** Choose a pool for the ZFS volume to create : ***"
109
   fi
110
done
111
}
112

    
113
while getopts "in:p:b:s:o:h" OPTION
114
do
115
     case $OPTION in
116
         h)
117
             usage
118
             exit 1
119
             ;;
120
         i)
121
            interactive
122
            exit 0
123
            ;;
124
         n)
125
           NAME=$OPTARG
126
           ;;
127
         p)
128
           NAME_POOL=$OPTARG
129
           ;;
130
         b)
131
           BLOCK_SIZE=$OPTARG
132
           ;;
133
         s)
134
           SIZE=$OPTARG
135
           ;;
136
         o)
137
           VOL_OPTION=$OPTARG
138
           VOL_OPTION=$(echo $VOL_OPTION|sed -e 's/,/ -o /g')
139
           echo "$VOL_OPTION"
140
           ;;
141
         *)
142
          usage
143
          exit 1
144
          ;;
145
    esac
146
done
147

    
148

    
149
if [[ -z $NAME ]] || [[ -z $NAME_POOL ]] || [[ -z $BLOCK_SIZE ]] || [[ -z $SIZE ]]
150
then
151
     usage
152
     exit 1
153
fi
154
nointeractive