-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvps_kvm_lvmcreate.sh
executable file
·37 lines (37 loc) · 1.15 KB
/
vps_kvm_lvmcreate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin"
name=$1
size=$2
IFS="
"
if [ $# -ne 2 ]; then
echo "Create a New LVM (non destructivly)"
echo "Syntax $0 [name] [size]"
echo " ie $0 windows1337 101000"
#check if vps exists
else
echo "Creating LVM ${name}"
if [ "$(lvdisplay |grep 'Allocated pool')" = "" ]; then
thin="no"
else
thin="yes"
fi
if [ "$size" = "all" ]; then
if [ "$(lvdisplay /dev/vz/$name)" = "" ]; then
#lvcreate -y -l +100%FREE -n${name} vz
lvcreate -y -L $(echo "($(pvdisplay -c|grep :vz: | cut -d: -f8,10| tr : "*"))-(1024*1024*4)"|bc)k -n${name} vz
else
echo "already exists, extending to 100%"
#lvextend -f -l +100%FREE /dev/vz/$name
lvextend -f -L +$(echo "($(pvdisplay -c|grep :vz: | cut -d: -f8,10| tr : "*"))-(1024*1024*4)"|bc)k /dev/vz/$name
fi
elif [ "$(lvdisplay /dev/vz/$name | grep "LV Size.*"$(echo "$size / 1024" | bc -l | cut -d\. -f1))" = "" ]; then
if [ "$thin" = "yes" ]; then
lvcreate -y -V${size} -T vz/thin -n${name}
else
lvcreate -y -L${size} -n${name} vz
fi
else
echo "already exists, skipping"
fi
fi