2021-04-12 22:07:17 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-04-24 17:35:54 +02:00
|
|
|
###### CONFIG SECTION ######
|
|
|
|
|
2021-04-12 22:07:17 +02:00
|
|
|
# Define basic tools to install
|
2021-04-24 19:01:12 +02:00
|
|
|
TOOLS="sudo vim ifupdown2 net-tools dnsutils ethtool git curl unzip screen iftop lshw smartmontools nvme-cli lsscsi sysstat zfs-auto-snapshot htop mc rpl"
|
2021-04-12 22:07:17 +02:00
|
|
|
|
2021-04-24 17:35:54 +02:00
|
|
|
###### SYSTEM INFO AND INTERACTIVE CONFIGURATION SECTION ######
|
|
|
|
|
|
|
|
#### L1ARC SIZE CONFIGURATION ####
|
|
|
|
|
|
|
|
# get total size of all zpools
|
2021-04-24 20:39:58 +02:00
|
|
|
zpool list -o size -Hp | while read line; do SUM=$(($SUM+$line)); echo "ZPOOL_SIZE_SUM_BYTES=$SUM" > ./ZPOOL_SIZE_SUM_BYTES; done
|
|
|
|
source ./ZPOOL_SIZE_SUM_BYTES
|
2021-04-24 17:35:54 +02:00
|
|
|
|
|
|
|
# get information about available ram
|
|
|
|
MEM_TOTAL_BYTES=$(free -tb | tail -1 | cut -d ' ' -f3)
|
|
|
|
|
|
|
|
# get values if defaults are set
|
2021-04-24 20:39:58 +02:00
|
|
|
ARC_MAX_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 2))
|
|
|
|
ARC_MIN_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 32))
|
2021-04-24 17:35:54 +02:00
|
|
|
|
|
|
|
# get current settings
|
|
|
|
ARC_MIN_SET_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_min)
|
|
|
|
ARC_MAX_SET_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_max)
|
2021-04-12 22:07:17 +02:00
|
|
|
|
2021-04-24 17:35:54 +02:00
|
|
|
# calculate suggested l1arc sice
|
|
|
|
ZFS_ARC_MIN_BYTES=$(($ZPOOL_SIZE_SUM_BYTES / 4096))
|
|
|
|
ZFS_ARC_MAX_BYTES=$(($ZPOOL_SIZE_SUM_BYTES / 1024))
|
|
|
|
|
|
|
|
echo -e "######## CONFIGURE ZFS L1ARC SIZE ########\n"
|
|
|
|
echo "System Summary:"
|
2021-04-24 20:39:58 +02:00
|
|
|
echo -e "\tSystem Memory:\t\t$(($MEM_TOTAL_BYTES / 1024 / 1024))\tMB"
|
|
|
|
echo -e "\tZpool size (sum):\t$(($ZPOOL_SIZE_SUM_BYTES / 1024 / 1024))\tMB"
|
2021-04-24 17:35:54 +02:00
|
|
|
echo -e "Calculated l1arc if set to defaults:"
|
|
|
|
if [ $ARC_MIN_DEFAULT_BYTES -lt 33554432 ]; then
|
2021-04-24 20:39:58 +02:00
|
|
|
echo -e "\tDefault zfs_arc_min:\t32\tMB"
|
2021-04-24 17:35:54 +02:00
|
|
|
else
|
2021-04-24 20:39:58 +02:00
|
|
|
echo -e "\tDefault zfs_arc_min:\t$(($ARC_MIN_DEFAULT_BYTES / 1024 / 1024))\tMB"
|
2021-04-24 17:35:54 +02:00
|
|
|
fi
|
2021-04-24 20:39:58 +02:00
|
|
|
echo -e "\tDefault zfs_arc_max:\t$(($ARC_MAX_DEFAULT_BYTES / 1024 / 1024))\tMB"
|
2021-04-24 17:35:54 +02:00
|
|
|
echo -e "Current l1arc configuration:"
|
2021-04-24 20:39:58 +02:00
|
|
|
if [ $ARC_MIN_SET_BYTES > 0 ]; then
|
|
|
|
echo -e "\tCurrent zfs_arc_min:\t$(($ARC_MIN_SET_BYTES / 1024 / 1024))\tMB"
|
2021-04-24 17:35:54 +02:00
|
|
|
else
|
|
|
|
echo -e "\tCurrent zfs_arc_min:\t0"
|
|
|
|
fi
|
2021-04-24 20:39:58 +02:00
|
|
|
if [ $ARC_MAX_SET_BYTES > 0 ]; then
|
|
|
|
echo -e "\tCurrent zfs_arc_max:\t$(($ARC_MAX_SET_BYTES / 1024 / 1024))\tMB"
|
2021-04-24 17:35:54 +02:00
|
|
|
else
|
|
|
|
echo -e "\tCurrent zfs_arc_max:\t0"
|
|
|
|
fi
|
|
|
|
echo -e "Note: If your current values are 0, the calculated values above will apply."
|
|
|
|
echo ""
|
2021-04-24 20:39:58 +02:00
|
|
|
echo -e "The l1arc cache will be set relative to the size (sum) of your zpools by policy"
|
|
|
|
echo -e "zfs_arc_min:\t\t\t$(($ZFS_ARC_MIN_BYTES / 1024 / 1024))\tMB\t\t= 256 MB RAM per 1 TB ZFS storage"
|
|
|
|
echo -e "zfs_arc_max:\t\t\t$(($ZFS_ARC_MAX_BYTES / 1024 / 1024))\tMB\t\t= 1 GB RAM per 1 TB ZFS storage"
|
2021-04-24 17:35:54 +02:00
|
|
|
echo ""
|
|
|
|
RESULT=not_set
|
2021-04-24 20:39:58 +02:00
|
|
|
while [ "$(echo $RESULT | awk '{print tolower($0)}')" != "y" ] && [ "$(echo $RESULT | awk '{print tolower($0)}')" != "n" ] && [ "$(echo $RESULT | awk '{print tolower($0)}')" != "" ]; do
|
|
|
|
echo "If you want to adjust the values yourself type 'y', type 'n' to apply the values by script policy [y/N]?"
|
2021-04-24 17:35:54 +02:00
|
|
|
read
|
|
|
|
RESULT=${REPLY}
|
|
|
|
done
|
|
|
|
if [[ "$(echo $RESULT | awk '{print tolower($0)}')" == "y" ]]; then
|
|
|
|
echo "Please type in the desired value in MB for 'zfs_arc_min' [$(($ZFS_ARC_MIN_BYTES / 1024 / 1024))]:"
|
|
|
|
read
|
|
|
|
if [[ ${REPLY} -gt 0 ]]; then
|
2021-04-24 20:39:58 +02:00
|
|
|
ZFS_ARC_MIN_BYTES=$((${REPLY} * 1024 * 1024))
|
2021-04-24 17:35:54 +02:00
|
|
|
fi
|
|
|
|
echo "Please type in the desired value in MB for 'zfs_arc_max' [$(($ZFS_ARC_MAX_BYTES / 1024 / 1024))]:"
|
|
|
|
read
|
|
|
|
if [[ ${REPLY} -gt 0 ]]; then
|
2021-04-24 20:39:58 +02:00
|
|
|
ZFS_ARC_MAX_BYTES=$((${REPLY} * 1024 * 1024))
|
2021-04-24 17:35:54 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#### ZFS AUTO SNAPSHOT CONFIGURATION ####
|
|
|
|
|
|
|
|
# get information about zfs-auto-snapshot and ask for snapshot retention
|
2021-04-24 20:39:58 +02:00
|
|
|
declare -A auto_snap_keep=( ["frequent"]="8" ["hourly"]="48" ["daily"]="31" ["weekly"]="8" ["monthly"]="3" )
|
|
|
|
dpkg -l zfs-auto-snapshot > /dev/null
|
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "'zfs-auto-snapshot' already installed. Reading config..."
|
|
|
|
for interval in "${!auto_snap_keep[@]}"; do
|
2021-04-24 17:35:54 +02:00
|
|
|
if [[ "$interval" == "frequent" ]]; then
|
2021-04-24 20:39:58 +02:00
|
|
|
auto_snap_keep[$interval]=$(cat /etc/cron.d/zfs-auto-snapshot | grep keep | cut -d' ' -f19 | cut -d '=' -f2)
|
2021-04-24 17:35:54 +02:00
|
|
|
else
|
2021-04-24 20:39:58 +02:00
|
|
|
auto_snap_keep[$interval]=$(cat /etc/cron.$interval/zfs-auto-snapshot | grep keep | cut -d' ' -f6 | cut -d'=' -f2)
|
2021-04-24 17:35:54 +02:00
|
|
|
fi
|
|
|
|
done
|
2021-04-24 20:39:58 +02:00
|
|
|
else
|
|
|
|
echo "'zfs-auto-snapshot' not installed yet, using scrpit defaults..."
|
2021-04-24 17:35:54 +02:00
|
|
|
fi
|
|
|
|
echo -e "######## CONFIGURE ZFS AUTO SNAPSHOT ########\n"
|
2021-04-24 20:39:58 +02:00
|
|
|
for interval in "${!auto_snap_keep[@]}"; do
|
2021-04-24 17:35:54 +02:00
|
|
|
echo "Please set how many $interval snapshots to keep (current: keep=${auto_snap_keep[$interval]})"
|
|
|
|
read
|
|
|
|
if [ "${auto_snap_keep[$interval]}" != "${REPLY}" ]; then
|
2021-04-24 20:39:58 +02:00
|
|
|
auto_snap_keep[$interval]=${REPLY}
|
2021-04-24 17:35:54 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-04-24 20:39:58 +02:00
|
|
|
#### PVE CONF BACKUP CONFIGURATION ####
|
|
|
|
|
|
|
|
# Define target dataset for backup of /etc
|
|
|
|
# IMPORTANT NOTE: Don't type in the leading /, this will be set where needed
|
|
|
|
PVE_CONF_BACKUP_TARGET=rpool/pveconf
|
|
|
|
|
|
|
|
# Define timer for your backup cronjob (default: every 15 minutes)
|
|
|
|
PVE_CONF_BACKUP_CRON_TIMER="*/15 * * * *"
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-24 17:35:54 +02:00
|
|
|
###### INSTALLER SECTION ######
|
2021-04-12 22:07:17 +02:00
|
|
|
|
2021-04-22 15:19:46 +02:00
|
|
|
# disable pve-enterprise repo and add pve-no-subscription repo
|
|
|
|
mv /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak
|
2021-04-12 22:07:17 +02:00
|
|
|
echo "deb http://download.proxmox.com/debian/pve buster pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list
|
|
|
|
apt update
|
|
|
|
|
|
|
|
# update system and install basic tools
|
2021-04-24 12:05:36 +02:00
|
|
|
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq dist-upgrade
|
|
|
|
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq install $TOOLS
|
2021-04-12 22:07:17 +02:00
|
|
|
|
|
|
|
# configure zfs-auto-snapshot
|
2021-04-24 20:39:58 +02:00
|
|
|
for interval in "${!auto_snap_keep[@]}"; do
|
2021-04-24 17:35:54 +02:00
|
|
|
if [[ "$interval" == "frequent" ]]; then
|
|
|
|
CURRENT=$(cat /etc/cron.d/zfs-auto-snapshot | grep keep | cut -d' ' -f19 | cut -d '=' -f2)
|
|
|
|
if [[ "${auto_snap_keep[$interval]}" != "$CURRENT" ]]; then
|
|
|
|
rpl "keep=$CURRENT" "keep=${auto_snap_keep[$interval]}" /etc/cron.d/zfs-auto-snapshot
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
CURRENT=$(cat /etc/cron.$interval/zfs-auto-snapshot | grep keep | cut -d' ' -f6 | cut -d'=' -f2)
|
2021-04-24 20:39:58 +02:00
|
|
|
if [[ "${auto_snap_keep[$interval]}" != "$CURRENT" ]]; then
|
2021-04-24 17:35:54 +02:00
|
|
|
rpl "keep=$CURRENT" "keep=${auto_snap_keep[$interval]}" /etc/cron.$interval/zfs-auto-snapshot
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2021-04-12 22:07:17 +02:00
|
|
|
|
|
|
|
echo $ZFS_ARC_MIN_BYTES > /sys/module/zfs/parameters/zfs_arc_min
|
|
|
|
echo $ZFS_ARC_MAX_BYTES > /sys/module/zfs/parameters/zfs_arc_max
|
|
|
|
|
|
|
|
cat << EOF > /etc/modprobe.d/zfs.conf
|
|
|
|
options zfs zfs_arc_min=$ZFS_ARC_MIN_BYTES
|
|
|
|
options zfs zfs_arc_min=$ZFS_ARC_MAX_BYTES
|
|
|
|
EOF
|
|
|
|
update-initramfs -u -k all
|
2021-04-24 17:35:54 +02:00
|
|
|
|
|
|
|
# create backup jobs of /etc
|
|
|
|
zfs list $PVE_CONF_BACKUP_TARGET
|
2021-04-24 20:39:58 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
2021-04-24 17:35:54 +02:00
|
|
|
zfs create $PVE_CONF_BACKUP_TARGET
|
|
|
|
fi
|
|
|
|
|
2021-04-24 19:01:12 +02:00
|
|
|
echo "$PVE_CONF_BACKUP_CRON_TIMER root rsync -vhab --delete /etc /$PVE_CONF_BACKUP_TARGET > /$PVE_CONF_BACKUP_TARGET/pve-conf-backup.log" > /etc/cron.d/pve-conf-backup
|