mirror of
https://github.com/bashclub/proxmox-zfs-postinstall.git
synced 2024-12-25 17:50:13 +01:00
Multiple syntax errors fixed
This commit is contained in:
parent
c9406c46f9
commit
01268655e7
83
install.sh
83
install.sh
@ -5,29 +5,20 @@
|
|||||||
# Define basic tools to install
|
# Define basic tools to install
|
||||||
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"
|
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"
|
||||||
|
|
||||||
# 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 * * * *"
|
|
||||||
|
|
||||||
###### SYSTEM INFO AND INTERACTIVE CONFIGURATION SECTION ######
|
###### SYSTEM INFO AND INTERACTIVE CONFIGURATION SECTION ######
|
||||||
|
|
||||||
#### L1ARC SIZE CONFIGURATION ####
|
#### L1ARC SIZE CONFIGURATION ####
|
||||||
|
|
||||||
# get total size of all zpools
|
# get total size of all zpools
|
||||||
ZPOOL_SIZE_SUM_BYTES=0
|
zpool list -o size -Hp | while read line; do SUM=$(($SUM+$line)); echo "ZPOOL_SIZE_SUM_BYTES=$SUM" > ./ZPOOL_SIZE_SUM_BYTES; done
|
||||||
zpool list -o size -Hp | while read size_per_pool; do
|
source ./ZPOOL_SIZE_SUM_BYTES
|
||||||
ZPOOL_SIZE_SUM_BYTES=$(($ZPOOL_SIZE_SUM_BYTES + $size_per_pool))
|
|
||||||
done
|
|
||||||
|
|
||||||
# get information about available ram
|
# get information about available ram
|
||||||
MEM_TOTAL_BYTES=$(free -tb | tail -1 | cut -d ' ' -f3)
|
MEM_TOTAL_BYTES=$(free -tb | tail -1 | cut -d ' ' -f3)
|
||||||
|
|
||||||
# get values if defaults are set
|
# get values if defaults are set
|
||||||
ARC_MAX_DEFAULT_BYTES=$((MEM_TOTAL / 2))
|
ARC_MAX_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 2))
|
||||||
ARC_MIN_DEFAULT_BYTES=$((MEM_TOTAL / 32))
|
ARC_MIN_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 32))
|
||||||
|
|
||||||
# get current settings
|
# get current settings
|
||||||
ARC_MIN_SET_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_min)
|
ARC_MIN_SET_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_min)
|
||||||
@ -39,35 +30,35 @@ ZFS_ARC_MAX_BYTES=$(($ZPOOL_SIZE_SUM_BYTES / 1024))
|
|||||||
|
|
||||||
echo -e "######## CONFIGURE ZFS L1ARC SIZE ########\n"
|
echo -e "######## CONFIGURE ZFS L1ARC SIZE ########\n"
|
||||||
echo "System Summary:"
|
echo "System Summary:"
|
||||||
echo -e "\tSystem Memory:\t$(($MEM_TOTAL_BYTES / 1024 / 1024)) MB"
|
echo -e "\tSystem Memory:\t\t$(($MEM_TOTAL_BYTES / 1024 / 1024))\tMB"
|
||||||
echo -e "\tZpool size (sum):\t$(($ZPOOL_SIZE_SUM_BYTES / 1024 / 1024)) MB"
|
echo -e "\tZpool size (sum):\t$(($ZPOOL_SIZE_SUM_BYTES / 1024 / 1024))\tMB"
|
||||||
echo -e "Calculated l1arc if set to defaults:"
|
echo -e "Calculated l1arc if set to defaults:"
|
||||||
if [ $ARC_MIN_DEFAULT_BYTES -lt 33554432 ]; then
|
if [ $ARC_MIN_DEFAULT_BYTES -lt 33554432 ]; then
|
||||||
echo -e "\tDefault zfs_arc_min:\t32 MB"
|
echo -e "\tDefault zfs_arc_min:\t32\tMB"
|
||||||
else
|
else
|
||||||
echo -e "\tDefault zfs_arc_min:\t$(($ARC_MIN_DEFAULT_BYTES / 1024 / 1024)) MB"
|
echo -e "\tDefault zfs_arc_min:\t$(($ARC_MIN_DEFAULT_BYTES / 1024 / 1024))\tMB"
|
||||||
fi
|
fi
|
||||||
echo -e "\tDefault zfs_arc_max:\t$(($ARC_MAX_DEFAULT_BYTES / 1024 / 1024)) MB"
|
echo -e "\tDefault zfs_arc_max:\t$(($ARC_MAX_DEFAULT_BYTES / 1024 / 1024))\tMB"
|
||||||
echo -e "Current l1arc configuration:"
|
echo -e "Current l1arc configuration:"
|
||||||
if [ $ARC_MIN_SET_BYTES > 0 ]; then
|
if [ $ARC_MIN_SET_BYTES > 0 ]; then
|
||||||
echo -e "\tCurrent zfs_arc_min:\t$(($ARC_MIN_SET_BYTES / 1024 / 1024)) MB"
|
echo -e "\tCurrent zfs_arc_min:\t$(($ARC_MIN_SET_BYTES / 1024 / 1024))\tMB"
|
||||||
else
|
else
|
||||||
echo -e "\tCurrent zfs_arc_min:\t0"
|
echo -e "\tCurrent zfs_arc_min:\t0"
|
||||||
fi
|
fi
|
||||||
if [ $ARC_MAX_SET_BYTES > 0 ]; then
|
if [ $ARC_MAX_SET_BYTES > 0 ]; then
|
||||||
echo -e "\tCurrent zfs_arc_max:\t$(($ARC_MAX_SET_BYTES / 1024 / 1024)) MB"
|
echo -e "\tCurrent zfs_arc_max:\t$(($ARC_MAX_SET_BYTES / 1024 / 1024))\tMB"
|
||||||
else
|
else
|
||||||
echo -e "\tCurrent zfs_arc_max:\t0"
|
echo -e "\tCurrent zfs_arc_max:\t0"
|
||||||
fi
|
fi
|
||||||
echo -e "Note: If your current values are 0, the calculated values above will apply."
|
echo -e "Note: If your current values are 0, the calculated values above will apply."
|
||||||
echo ""
|
echo ""
|
||||||
echo "The l1arc cache will be set relative to the size (sum) of your zpools by the policy 'zfs_arc_min = 256 MB / 1 TB' and 'zfs_arc_max = 1 GB / 1 TB'"
|
echo -e "The l1arc cache will be set relative to the size (sum) of your zpools by policy"
|
||||||
echo "zfs_arc_min=\t$(($ZFS_ARC_MIN_BYTES / 1024 / 1024)) MB"
|
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 "zfs_arc_max=\t$(($ZFS_ARC_MAX_BYTES / 1024 / 1024)) MB"
|
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"
|
||||||
echo ""
|
echo ""
|
||||||
RESULT=not_set
|
RESULT=not_set
|
||||||
while [[ "$(echo $RESULT | awk '{print tolower($0)}')" != "y" ]] && [[ "$(echo $RESULT | awk '{print tolower($0)}')" != "n"]]; do
|
while [ "$(echo $RESULT | awk '{print tolower($0)}')" != "y" ] && [ "$(echo $RESULT | awk '{print tolower($0)}')" != "n" ] && [ "$(echo $RESULT | awk '{print tolower($0)}')" != "" ]; do
|
||||||
echo "You can now adjust the l1arc values. Change settings [y/N]?"
|
echo "If you want to adjust the values yourself type 'y', type 'n' to apply the values by script policy [y/N]?"
|
||||||
read
|
read
|
||||||
RESULT=${REPLY}
|
RESULT=${REPLY}
|
||||||
done
|
done
|
||||||
@ -75,40 +66,53 @@ 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))]:"
|
echo "Please type in the desired value in MB for 'zfs_arc_min' [$(($ZFS_ARC_MIN_BYTES / 1024 / 1024))]:"
|
||||||
read
|
read
|
||||||
if [[ ${REPLY} -gt 0 ]]; then
|
if [[ ${REPLY} -gt 0 ]]; then
|
||||||
$ZFS_ARC_MIN_BYTES=$((${REPLY} * 1024 * 1024))
|
ZFS_ARC_MIN_BYTES=$((${REPLY} * 1024 * 1024))
|
||||||
fi
|
fi
|
||||||
echo "Please type in the desired value in MB for 'zfs_arc_max' [$(($ZFS_ARC_MAX_BYTES / 1024 / 1024))]:"
|
echo "Please type in the desired value in MB for 'zfs_arc_max' [$(($ZFS_ARC_MAX_BYTES / 1024 / 1024))]:"
|
||||||
read
|
read
|
||||||
if [[ ${REPLY} -gt 0 ]]; then
|
if [[ ${REPLY} -gt 0 ]]; then
|
||||||
$ZFS_ARC_MAX_BYTES=$((${REPLY} * 1024 * 1024))
|
ZFS_ARC_MAX_BYTES=$((${REPLY} * 1024 * 1024))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#### ZFS AUTO SNAPSHOT CONFIGURATION ####
|
#### ZFS AUTO SNAPSHOT CONFIGURATION ####
|
||||||
|
|
||||||
# get information about zfs-auto-snapshot and ask for snapshot retention
|
# get information about zfs-auto-snapshot and ask for snapshot retention
|
||||||
dpkg -l zfs-auto-snapshot
|
declare -A auto_snap_keep=( ["frequent"]="8" ["hourly"]="48" ["daily"]="31" ["weekly"]="8" ["monthly"]="3" )
|
||||||
declare -A auto_snap_keep
|
dpkg -l zfs-auto-snapshot > /dev/null
|
||||||
if [ $1 -ne 0 ]; then
|
|
||||||
auto_snap_keep["frequent"]=8 ; auto_snap_keep["hourly"]=48 ; auto_snap_keep["daily"]=31 ; auto_snap_keep["weekly"]=8 ; auto_snap_keep["monthly"]=3
|
if [ $? -eq 0 ]; then
|
||||||
else
|
echo "'zfs-auto-snapshot' already installed. Reading config..."
|
||||||
for interval in "${auto_snap_keep[@]}"; do
|
for interval in "${!auto_snap_keep[@]}"; do
|
||||||
if [[ "$interval" == "frequent" ]]; then
|
if [[ "$interval" == "frequent" ]]; then
|
||||||
auto_snap_keep["$interval"]=$(cat /etc/cron.d/zfs-auto-snapshot | grep keep | cut -d' ' -f19 | cut -d '=' -f2)
|
auto_snap_keep[$interval]=$(cat /etc/cron.d/zfs-auto-snapshot | grep keep | cut -d' ' -f19 | cut -d '=' -f2)
|
||||||
else
|
else
|
||||||
auto_snap_keep["$interval"]=$(cat /etc/cron.$interval/zfs-auto-snapshot | grep keep | cut -d' ' -f6 | cut -d'=' -f2)
|
auto_snap_keep[$interval]=$(cat /etc/cron.$interval/zfs-auto-snapshot | grep keep | cut -d' ' -f6 | cut -d'=' -f2)
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
else
|
||||||
|
echo "'zfs-auto-snapshot' not installed yet, using scrpit defaults..."
|
||||||
fi
|
fi
|
||||||
echo -e "######## CONFIGURE ZFS AUTO SNAPSHOT ########\n"
|
echo -e "######## CONFIGURE ZFS AUTO SNAPSHOT ########\n"
|
||||||
for interval in "${auto_snap_keep[@]}"; do
|
for interval in "${!auto_snap_keep[@]}"; do
|
||||||
echo "Please set how many $interval snapshots to keep (current: keep=${auto_snap_keep[$interval]})"
|
echo "Please set how many $interval snapshots to keep (current: keep=${auto_snap_keep[$interval]})"
|
||||||
read
|
read
|
||||||
if [ "${auto_snap_keep[$interval]}" != "${REPLY}" ]; then
|
if [ "${auto_snap_keep[$interval]}" != "${REPLY}" ]; then
|
||||||
auto_snap_keep["$interval"]=${REPLY}
|
auto_snap_keep[$interval]=${REPLY}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
#### 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 * * * *"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###### INSTALLER SECTION ######
|
###### INSTALLER SECTION ######
|
||||||
|
|
||||||
# disable pve-enterprise repo and add pve-no-subscription repo
|
# disable pve-enterprise repo and add pve-no-subscription repo
|
||||||
@ -121,7 +125,7 @@ DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq dist-upgrade
|
|||||||
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq install $TOOLS
|
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq install $TOOLS
|
||||||
|
|
||||||
# configure zfs-auto-snapshot
|
# configure zfs-auto-snapshot
|
||||||
for interval in "${auto_snap_keep[@]}"; do
|
for interval in "${!auto_snap_keep[@]}"; do
|
||||||
if [[ "$interval" == "frequent" ]]; then
|
if [[ "$interval" == "frequent" ]]; then
|
||||||
CURRENT=$(cat /etc/cron.d/zfs-auto-snapshot | grep keep | cut -d' ' -f19 | cut -d '=' -f2)
|
CURRENT=$(cat /etc/cron.d/zfs-auto-snapshot | grep keep | cut -d' ' -f19 | cut -d '=' -f2)
|
||||||
if [[ "${auto_snap_keep[$interval]}" != "$CURRENT" ]]; then
|
if [[ "${auto_snap_keep[$interval]}" != "$CURRENT" ]]; then
|
||||||
@ -146,8 +150,7 @@ update-initramfs -u -k all
|
|||||||
|
|
||||||
# create backup jobs of /etc
|
# create backup jobs of /etc
|
||||||
zfs list $PVE_CONF_BACKUP_TARGET
|
zfs list $PVE_CONF_BACKUP_TARGET
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
if [ $? -ne 0 ]
|
|
||||||
zfs create $PVE_CONF_BACKUP_TARGET
|
zfs create $PVE_CONF_BACKUP_TARGET
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user