forked from extremeshok/xshok-proxmox
-
Notifications
You must be signed in to change notification settings - Fork 5
/
xshok_slog_cache-2-zfs.sh
165 lines (147 loc) · 5.25 KB
/
xshok_slog_cache-2-zfs.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
################################################################################
# This is property of eXtremeSHOK.com
# You are free to use, modify and distribute, however you may not remove this notice.
# Copyright (c) Adrian Jon Kriel :: [email protected]
################################################################################
#
# Script updates can be found at: https://github.com/extremeshok/xshok-proxmox
#
# post-installation script for Proxmox
#
# License: BSD (Berkeley Software Distribution)
#
################################################################################
#
# Assumptions: /xshok/zfs-cache and/or /xshok/zfs-slog are mounted.
#
# Assumes mounted MD raid partitions (linux software raid)
#
# Usage:
# curl -O https://raw.githubusercontent.com/extremeshok/xshok-proxmox/master/xshok_slog_cache-2-zfs.sh && chmod +x xshok_slog_cache-2-zfs.sh
# ./xshok_slog_cache-2-zfs.sh MY_ZFS_POOL
#
# NOTES: remove slog with
# zpool remove MYPOOL mirror-1
# NOTES: remove cache with
# zpool remove DEVICE
#
################################################################################
#
# THERE ARE NO USER CONFIGURABLE OPTIONS IN THIS SCRIPT
#
################################################################################
# Set the local
export LANG="en_US.UTF-8"
export LC_ALL="C"
MY_ZFS_POOL="$1"
if [ "$MY_ZFS_POOL" == "" ]; then
#DEFAULT ZFS POOL
MY_ZFS_POOL="hddpool"
fi
declare -a XSHOK_MOUNTS=('/xshok/zfs-cache' '/xshok/zfs-slog');
echo "+++++++++++++++++++++++++"
echo "WILL DESTROY ALL DATA ON"
echo "${XSHOK_MOUNTS[@]}"
echo "+++++++++++++++++++++++++"
echo "[CTRL]+[C] to exit"
echo "+++++++++++++++++++++++++"
sleep 1
echo "5.." ; sleep 1
echo "4.." ; sleep 1
echo "3.." ; sleep 1
echo "2.." ; sleep 1
echo "1.." ; sleep 1
echo "STARTING CONVERSION"
sleep 1
for XSHOK_MOUNT_POINT in "${XSHOK_MOUNTS[@]}" ; do
echo "$XSHOK_MOUNT_POINT"
#check mountpiont exists and is a device
XSHOK_MOUNT_POINT_DEV=$(mount | grep -i "$XSHOK_MOUNT_POINT" | cut -d " " -f 1)
ret=$?
if [ $ret == 0 ] && [ "$XSHOK_MOUNT_POINT_DEV" != "" ] ; then
echo "Found partition, continuing"
echo "XSHOK_MOUNT_POINT_DEV=$XSHOK_MOUNT_POINT_DEV" #/dev/mapper/pve-data
else
echo "SKIPPING: $XSHOK_MOUNT_POINT not found"
break
fi
#Detect and install dependencies
if [ "$(command -v zpool)" == "" ] ; then
if [ "$(command -v apt-get)" != "" ] ; then
/usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::='--force-confdef' install zfsutils-linux
modprobe zfs
else
echo "ERROR: ZFS not installed"
exit 1
fi
fi
if [ "$(command -v zpool)" == "" ] ; then
echo "ERROR: ZFS not installed"
exit 1
fi
if [ "$(command -v tune2fs)" == "" ] ; then
echo "ERROR: tune2fs not installed"
exit 1
fi
if ! zpool status "$MY_ZFS_POOL" 2> /dev/null ; then
echo "ERROR: ZFS pool ${MY_ZFS_POOL} not found"
exit 1
fi
XSHOK_MOUNT_POINT_MD_RAID=${XSHOK_MOUNT_POINT_DEV/\/dev\//}
IFS=' ' read -r -a mddevarray <<< "$(grep "$XSHOK_MOUNT_POINT_MD_RAID :" /proc/mdstat | cut -d ' ' -f5- | xargs)"
if [ "${mddevarray[0]}" == "" ] ; then
echo "ERROR: no devices found for $XSHOK_MOUNT_POINT_DEV in /proc/mdstat"
#exit 1
fi
#check there is a minimum of 1 drives detected, not needed, but i rather have it.
if [ "${#mddevarray[@]}" -lt "1" ] ; then
echo "ERROR: less than 1 devices were detected"
#exit 1
fi
# remove [*] and /dev/ to each record
echo "Creating the device array"
for index in "${!mddevarray[@]}" ; do
tempmddevarraystring="${mddevarray[index]}"
mddevarray[$index]="/dev/${tempmddevarraystring%\[*\]}"
done
echo "Destroying MD (linux raid)"
echo umount -f "${XSHOK_MOUNT_POINT_DEV}"
umount -f "${XSHOK_MOUNT_POINT_DEV}"
echo mdadm --stop "${XSHOK_MOUNT_POINT_DEV}"
mdadm --stop "${XSHOK_MOUNT_POINT_DEV}"
echo mdadm --remove "${XSHOK_MOUNT_POINT_DEV}"
mdadm --remove "${XSHOK_MOUNT_POINT_DEV}"
echo "Cleaning up fstab / mounts"
grep -v "$XSHOK_MOUNT_POINT" /etc/fstab > /tmp/fstab.new && mv /tmp/fstab.new /etc/fstab
MY_MD_DEV_UUID_LIST=""
for MY_MD_DEV in "${mddevarray[@]}" ; do
echo "zeroing $MY_MD_DEV"
echo mdadm --zero-superblock "$MY_MD_DEV"
mdadm --zero-superblock "$MY_MD_DEV"
#MY_MD_DEV_UUID="$(uuidgen)"
#tune2fs "$MY_MD_DEV" -U "$MY_MD_DEV_UUID"
MY_MD_DEV_UUID="$(blkid | grep "$MY_MD_DEV" | cut -d= -f2 | xargs)"
MY_MD_DEV_UUID_LIST="${MY_MD_DEV_UUID_LIST} ${MY_MD_DEV_UUID}"
done
if [ "$XSHOK_MOUNT_POINT" == "/xshok/zfs-cache" ] ; then
echo "Adding ${mddevarray[*]} to ${MY_ZFS_POOL} as CACHE"
echo "$MY_MD_DEV_UUID_LIST"
zpool add ${MY_ZFS_POOL} cache "$MY_MD_DEV_UUID_LIST"
elif [ "$XSHOK_MOUNT_POINT" == "/xshok/zfs-slog" ] ; then
echo "Adding ${mddevarray[*]} to ${MY_ZFS_POOL} as SLOG"
echo "$MY_MD_DEV_UUID_LIST"
if [ "${#mddevarray[@]}" -eq "1" ] ; then
zpool add ${MY_ZFS_POOL} log "$MY_MD_DEV_UUID_LIST"
else
zpool add ${MY_ZFS_POOL} log mirror "$MY_MD_DEV_UUID_LIST"
fi
else
echo "SKIPPING: Nothing todo with the partions"
echo "${mddevarray[@]}"
echo "$MY_MD_DEV_UUID_LIST"
fi
done
zpool iostat -v "$MY_ZFS_POOL" -L -T d
#script Finish
echo -e '\033[1;33m Finished....please restart the server \033[0m'