forked from CasCas2/proxmox-hetzner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-hetzner-sata.sh
264 lines (243 loc) · 11 KB
/
install-hetzner-sata.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/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
#
# hetzner installation script for Proxmox
#
# License: BSD (Berkeley Software Distribution)
#
##############################################################################
#
# Assumptions:
# Run this script from the hetzner rescue system
# Operating system=Linux, Architecture=64 bit, Public key=*optional*
#
# Assumes 2 or 4 identical disks at /dev/sda and /dev/sdb,sdc,sdd,sde,sdf it ignores any extra disks which are not identical
# Will make sure the raid 1 use sda and the next identical sized disk, eg. sdc if sdb is not the same siza as sda
# software raid 1 (mirror) will be setup as well as LVM and will automatically detect and set the swap size
# If 4 identical disks are detected (sda,sdb,sdc,sdd) raid 10 will be used. (mirror and striped)
#
# SWAP partition size is adjusted according to available drive space
#
# Notes:
# will automatically run the install-post.sh script
# will automatically detect and use the latest debian install image
# ext3 boot partition is always created, as per Hetzner requirements
#
################################################################################
#
# ALL CONFIGURATION OPTIONS ARE LOCATED BELOW THIS MESSAGE
#
################################################################################
#set size of swap partition or leave blank for autoconfig, USE NUMBER ONLY, will be in gbytes, 0 to disable
MY_SWAP=""
#set size of cache partition or leave blank for autoconfig, USE NUMBER ONLY, will be in gbytes, 0 to disable
MY_CACHE=""
#set size of slog partition or leave blank for autoconfig, USE NUMBER ONLY, will be in gbytes, 0 to disable
MY_SLOG=""
#set size of boot partition or leave blank for autoconfig, will be in gbytes, 1GB or larger
MY_BOOT="1"
#set size of root partition, will be in gbytes, 10GB or larger
MY_ROOT="40"
#comment out to disable LVM and use a very simple partition setup of / and swap
USE_LVM="TRUE"
################################################################################
# Set the local
export LANG="en_US.UTF-8"
export LC_ALL="C"
installimage_bin="/root/.oldroot/nfs/install/installimage"
MY_HOSTNAME="$1"
if [ "$MY_HOSTNAME" == "" ]; then
echo "Please set a hostname"
echo "$0 host.name"
exit 1
fi
##### CONFIGURE RAID
# Detect discs for software raid and ensure sda and sd? are the identical size
# autoselects the second drive to raid with sda
# sda is always used, as sda is generally the primary boot disk
# disables raid if a suitable second disk is not found
if [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -eq $(awk '/sdb$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]]; then
MY_RAID_ENABLE="yes"
MY_RAID_SLAVE=",sdb"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -eq $(awk '/sdc$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]]; then
MY_RAID_ENABLE="yes"
MY_RAID_SLAVE=",sdc"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -eq $(awk '/sdd$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]]; then
MY_RAID_ENABLE="yes"
MY_RAID_SLAVE=",sdd"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -eq $(awk '/sde$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]]; then
MY_RAID_ENABLE="yes"
MY_RAID_SLAVE=",sde"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -eq $(awk '/sdf$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]]; then
MY_RAID_ENABLE="yes"
MY_RAID_SLAVE=",sdf"
else
MY_RAID_ENABLE="no"
MY_RAID_SLAVE=""
fi
#test for possible raid10, using 4 devices of equal size
if [ "$MY_RAID_ENABLE" == "yes" ]; then
if [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -eq $(awk '/sdb$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]] && [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -eq $(awk '/sdc$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]] && [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -eq $(awk '/sdd$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]] ; then
MY_RAID_LEVEL="10"
MY_RAID_SLAVE=",sdb,sdc,sdd"
else
MY_RAID_LEVEL="1"
fi
echo "RAID ENABLED"
echo "RAID Devices: sda${MY_RAID_SLAVE}"
echo "Set RAID level to ${MY_RAID_LEVEL}"
fi
# check for ram size
#if [[ $(( $(vmstat -s | grep -i "total memory" | xargs | cut -d" " -f 1) / 1024 / 1000)) -le "64" ]] ; then
##### CONFIGURE BOOT
if [[ $MY_BOOT -lt 1 ]] ; then
echo "error: MY_ROOT is too small, must be larger than 10 GB"
exit 1
elif [ "$MY_BOOT" == "" ] || [[ ! $MY_BOOT =~ ^[0-9]+$ ]] ; then
echo "error: MY_BOOT is Not a number, specify in GB"
exit 1
fi
##### CONFIGURE ROOT
if [[ $MY_ROOT -lt 10 ]] ; then
echo "error: MY_ROOT is too small, must be larger than 10 GB"
exit 1
elif [ "$MY_ROOT" == "" ] || [[ ! $MY_ROOT =~ ^[0-9]+$ ]] ; then
echo "error: MY_ROOT is Not a number, specify in GB"
exit 1
fi
#### CONFIGURE SWAP
# HDD more than 400gb = 64GB swap
# HDD more than 160gb = 32GB swap
# HDD less than 160gb = 16GB swap
if [ "$MY_SWAP" == "0" ] ; then
MY_SWAP=""
elif [ "$MY_SWAP" != "" ] && [[ ! $MY_SWAP =~ ^[0-9]+$ ]] ; then
echo "error: MY_SWAP is Not a number, specify in GB"
exit 1
else
echo "Detecting and setting optimal swap partition size"
if [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -gt "400" ]] ; then
MY_SWAP="64"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -gt "160" ]] ; then
MY_SWAP="32"
else
MY_SWAP="16"
fi
fi
#### CONFIGURE SLOG PARTITION
if [ "$MY_SLOG" == "0" ] ; then
MY_SLOG=""
elif [ "$MY_SLOG" != "" ] && [[ ! $MY_SLOG =~ ^[0-9]+$ ]] ; then
echo "error: MY_SLOG is Not a number, specify in GB"
exit 1
elif [ "$(cat /sys/block/sda/queue/rotational)" == "1" ] ; then
echo "HDD Detected, ignoring slog partition"
MY_SLOG=""
elif [ "$MY_RAID_LEVEL" == "10" ]; then
echo "SSD Detected, RAID 10 enabled, ignoring slog partition"
MY_SLOG=""
elif [ "$(cat /sys/block/sdb/queue/rotational)" == "1" ] || [ "$(cat /sys/block/sdc/queue/rotational)" == "1" ] || [ "$(cat /sys/block/sdd/queue/rotational)" == "1" ] || [ "$(cat /sys/block/sde/queue/rotational)" == "1" ] || [ "$(cat /sys/block/sdf/queue/rotational)" == "1" ] ; then
echo "HDD Detected with SSD, enabling slog partition"
#### CONFIGURE CACHE
# HDD more than 800gb = 120GB CACHE
# HDD more than 400gb = 60GB CACHE
# HDD more than 160gb = 30GB CACHE
# HDD less than 160gb = DISABLE CACHE
echo "Detecting and setting optimal slog partition size"
if [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -gt "800" ]] ; then
MY_SLOG="10"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -gt "400" ]] ; then
MY_SLOG="5"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -gt "160" ]] ; then
MY_SLOG="1"
else
MY_SLOG=""
fi
fi
#### CONFIGURE CACHE PARTITION
if [ "$MY_CACHE" == "0" ] ; then
MY_CACHE=""
elif [ "$MY_CACHE" != "" ] && [[ ! $MY_CACHE =~ ^[0-9]+$ ]] ; then
echo "error: ${MY_CACHE} is Not a number, specify in GB"
exit 1
elif [ "$(cat /sys/block/sda/queue/rotational)" == "1" ] ; then
echo "HDD Detected, ignoring cache partition"
MY_CACHE=""
elif [ "$MY_RAID_LEVEL" == "10" ]; then
echo "SSD Detected, RAID 10 enabled, ignoring cache partition"
MY_CACHE=""
elif [ "$(cat /sys/block/sdb/queue/rotational)" == "1" ] || [ "$(cat /sys/block/sdc/queue/rotational)" == "1" ] || [ "$(cat /sys/block/sdd/queue/rotational)" == "1" ] || [ "$(cat /sys/block/sde/queue/rotational)" == "1" ] || [ "$(cat /sys/block/sdf/queue/rotational)" == "1" ] ; then
echo "HDD Detected with SSD, enabling cache partition"
#### CONFIGURE CACHE
# HDD more than 800gb = 120GB CACHE
# HDD more than 400gb = 60GB CACHE
# HDD more than 160gb = 30GB CACHE
# HDD less than 160gb = DISABLE CACHE
echo "Detecting and setting optimal swap partition size"
if [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -gt "800" ]] ; then
MY_CACHE="120"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -gt "400" ]] ; then
MY_CACHE="60"
elif [[ $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) -gt "160" ]] ; then
MY_CACHE="30"
else
MY_CACHE=""
fi
fi
#### CHECK PARTITIONS WILL FIT ON DISK
if [[ $(( MY_BOOT + MY_ROOT + MY_SWAP + MY_CACHE + MY_SLOG + 1 )) -gt $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions) ]] ; then
echo "ERROR: Drive is too small"
exit 1
fi
echo "sda SIZE: $(awk '/sda$/{printf "%i", $(NF-1) / 1000 / 1000}' /proc/partitions)"
echo "BOOT: ${MY_BOOT}"
echo "ROOT: ${MY_ROOT}"
if [ "$MY_SWAP" != "" ]; then
echo "SWAP: ${MY_SWAP}"
MY_SWAP=",swap:swap:${MY_SWAP}G"
fi
if [ "$MY_CACHE" != "" ]; then
if [ "$MY_RAID_LEVEL" == "1" ]; then
#devide by 2 as the cache will be doubled (stripped)
MY_CACHE=$(( MY_CACHE / 2 ))
fi
echo "CACHE: ${MY_CACHE}"
MY_CACHE=",/xshok/zfs-cache:ext4:${MY_CACHE}G"
fi
if [ "$MY_SLOG" != "" ]; then
echo "SLOG: ${MY_SLOG}"
MY_SLOG=",/xshok/zfs-slog:ext4:${MY_SLOG}G"
fi
#wait 5 seconds
sleep 5
# Detect the latest installimage file to use
installimage_file=$(find /root/images/ -iname 'Debian-*-bullseye-amd64-base.tar.gz' | sort --version-sort --field-separator=- --key=2,2 -r | head -n1)
if [ ! -f $installimage_file ] ; then
echo "Error: Image file was not found: ${installimage_file}"
echo "Please log an issue on the github repo with the following"
ls -laFh root/images
exit 1
fi
#fetching post install
curl "https://raw.githubusercontent.com/CasCas2/proxmox-hetzner/master/hetzner-prox/proxmox7" --output /post-install
#Customising post install file
echo "wget https://raw.githubusercontent.com/CasCas2/proxmox-hetzner/master/install-post.sh -c -O install-post.sh && bash install-post.sh && rm install-post.sh" >> /post-install
if grep -q '#!/bin/bash' "/post-install"; then
chmod 777 /post-install
echo "Starting Installer with Install Image: ${installimage_file}"
if [ "$USE_LVM" == "TRUE" ]; then
echo "Using LVM"
$installimage_bin -a -i "$installimage_file" -g -s en -x /post-install -n "${MY_HOSTNAME}" -b grub -d "sda${MY_RAID_SLAVE}" -r "${MY_RAID_ENABLE}" -l "${MY_RAID_LEVEL}" -p "/boot:ext3:${MY_BOOT}G,/:ext4:${MY_ROOT}G${MY_SWAP}${MY_CACHE}${MY_SLOG},lvm:vg0:all" -v "vg0:data:/var/lib/vz:xfs:all"
else
$installimage_bin -a -i "$installimage_file" -g -s en -x /post-install -n "${MY_HOSTNAME}" -b grub -d "sda${MY_RAID_SLAVE}" -r "${MY_RAID_ENABLE}" -l "${MY_RAID_LEVEL}" -p "/boot:ext3:${MY_BOOT}G,/:ext4:${MY_ROOT}G${MY_SWAP}${MY_CACHE}${MY_SLOG},/var/lib/vz:xfs:all"
fi
else
echo "Failed to fetch post-install"
exit 1
fi