From 92cf9d4457cf65e568a6bbbb71fc404d238db281 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 17:35:54 +0200 Subject: [PATCH 01/21] Complete rework, added pve-conf-backup --- install.sh | 146 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 128 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index 83cc2a6..9f36c92 100644 --- a/install.sh +++ b/install.sh @@ -1,18 +1,115 @@ #!/bin/bash +###### CONFIG SECTION ###### + # Define basic tools to install TOOLS="vim ifupdown2 net-tools dnsutils ethtool git curl unzip screen iftop lshw smartmontools nvme-cli lsscsi sysstat zfs-auto-snapshot htop mc rpl" -# Define zfs-auto-snapshot retention policy -SNAP_FREQUENT=8 -SNAP_HOURLY=48 -SNAP_DAILY=31 -SNAP_WEEKLY=8 -SNAP_MONTHLY=3 +# 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 zfs arcsize in Megabytes (MB) -ZFS_ARC_MIN=128 -ZFS_ARC_MAX=256 +# Define timer for your backup cronjob (default: every 15 minutes) +PVE_CONF_BACKUP_CRON_TIMER="*/15 * * * *" + +###### SYSTEM INFO AND INTERACTIVE CONFIGURATION SECTION ###### + +#### L1ARC SIZE CONFIGURATION #### + +# get total size of all zpools +ZPOOL_SIZE_SUM_BYTES=0 +zpool list -o size -Hp | while read size_per_pool; do + ZPOOL_SIZE_SUM_BYTES=$(($ZPOOL_SIZE_SUM_BYTES + $size_per_pool)) +done + +# get information about available ram +MEM_TOTAL_BYTES=$(free -tb | tail -1 | cut -d ' ' -f3) + +# get values if defaults are set +ARC_MAX_DEFAULT_BYTES=$((MEM_TOTAL / 2)) +ARC_MIN_DEFAULT_BYTES=$((MEM_TOTAL / 32)) + +# 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) + +# 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:" +echo -e "\tSystem Memory:\t$(($MEM_TOTAL_BYTES / 1024 / 1024)) MB" +echo -e "\tZpool size (sum):\t$(($ZPOOL_SIZE_SUM_BYTES / 1024 / 1024)) MB" +echo -e "Calculated l1arc if set to defaults:" +if [ $ARC_MIN_DEFAULT_BYTES -lt 33554432 ]; then + echo -e "\tDefault zfs_arc_min:\t32 MB" +else + echo -e "\tDefault zfs_arc_min:\t$(($ARC_MIN_DEFAULT_BYTES / 1024 / 1024)) MB" +fi +echo -e "\tDefault zfs_arc_max:\t$(($ARC_MAX_DEFAULT_BYTES / 1024 / 1024)) MB" +echo -e "Current l1arc configuration:" +if [ $ARC_MIN_SET_BYTES > 0]; then + echo -e "\tCurrent zfs_arc_min:\t$(($ARC_MIN_SET_BYTES / 1024 / 1024)) MB" +else + echo -e "\tCurrent zfs_arc_min:\t0" +fi +if [ $ARC_MAX_SET_BYTES > 0]; then + echo -e "\tCurrent zfs_arc_max:\t$(($ARC_MAX_SET_BYTES / 1024 / 1024)) MB" +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 "" +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 "zfs_arc_min=\t$(($ZFS_ARC_MIN_BYTES / 1024 / 1024)) MB" +echo "zfs_arc_max=\t$(($ZFS_ARC_MAX_BYTES / 1024 / 1024)) MB" +echo "" +RESULT=not_set +while [[ "$(echo $RESULT | awk '{print tolower($0)}')" != "y" ]] && [[ "$(echo $RESULT | awk '{print tolower($0)}')" != "n"]]; do + echo "You can now adjust the l1arc values. Change settings [y/N]?" + 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 + $ZFS_ARC_MIN_BYTES=$((${REPLY} * 1024 * 1024)) + 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 + $ZFS_ARC_MAX_BYTES=$((${REPLY} * 1024 * 1024)) + fi +fi + +#### ZFS AUTO SNAPSHOT CONFIGURATION #### + +# get information about zfs-auto-snapshot and ask for snapshot retention +dpkg -l zfs-auto-snapshot +declare -A auto_snap_keep +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 +else + for interval in "${auto_snap_keep[@]}"; do + if [[ "$interval" == "frequent" ]]; then + auto_snap_keep["$interval"]=$(cat /etc/cron.d/zfs-auto-snapshot | grep keep | cut -d' ' -f19 | cut -d '=' -f2) + else + auto_snap_keep["$interval"]=$(cat /etc/cron.$interval/zfs-auto-snapshot | grep keep | cut -d' ' -f6 | cut -d'=' -f2) + fi + done +fi +echo -e "######## CONFIGURE ZFS AUTO SNAPSHOT ########\n" +for interval in "${auto_snap_keep[@]}"; do + echo "Please set how many $interval snapshots to keep (current: keep=${auto_snap_keep[$interval]})" + read + if [ "${auto_snap_keep[$interval]}" != "${REPLY}" ]; then + auto_snap_keep["$interval"]=${REPLY} + fi +done + +###### INSTALLER SECTION ###### # 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 @@ -24,15 +121,19 @@ DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq dist-upgrade DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq install $TOOLS # configure zfs-auto-snapshot -rpl "keep=4" "keep=$SNAP_FREQUENT" /etc/cron.d/zfs-auto-snapshot -rpl "keep=24" "keep=$SNAP_HOURLY" /etc/cron.hourly/zfs-auto-snapshot -rpl "keep=31" "keep=$SNAP_DAILY" /etc/cron.hourly/zfs-auto-snapshot -rpl "keep=8" "keep=$SNAP_WEEKLY" /etc/cron.weekly/zfs-auto-snapshot -rpl "keep=8" "keep=$SNAP_MONTHLY" /etc/cron.monthly/zfs-auto-snapshot - -# set zfs_arc_limits -ZFS_ARC_MIN_BYTES=$(($ZFS_ARC_MIN*1024*1024)) -ZFS_ARC_MAX_BYTES=$(($ZFS_ARC_MAX*1024*1024)) +for interval in "${auto_snap_keep[@]}"; do + 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) + if [[ "${auto_snap_keep[$interval]}" != "$CURRENT"]]; then + rpl "keep=$CURRENT" "keep=${auto_snap_keep[$interval]}" /etc/cron.$interval/zfs-auto-snapshot + fi + fi +done echo $ZFS_ARC_MIN_BYTES > /sys/module/zfs/parameters/zfs_arc_min echo $ZFS_ARC_MAX_BYTES > /sys/module/zfs/parameters/zfs_arc_max @@ -42,3 +143,12 @@ options zfs zfs_arc_min=$ZFS_ARC_MIN_BYTES options zfs zfs_arc_min=$ZFS_ARC_MAX_BYTES EOF update-initramfs -u -k all + +# create backup jobs of /etc +zfs list $PVE_CONF_BACKUP_TARGET + +if [ $? -ne 0 ] + zfs create $PVE_CONF_BACKUP_TARGET +fi + +echo "$PVE_CONF_BACKUP_CRON_TIMER root rsync -rtvupo /etc /$PVE_CONF_BACKUP_TARGET" > /etc/cron.d/pve-conf-backup \ No newline at end of file From 18fab189f780a0a1464957690c5a3a0e1d152629 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 17:43:36 +0200 Subject: [PATCH 02/21] Updated README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9102fd2..d25352c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # proxmox-zfs-postinstall +`devel` branch is still under heavy development, so only use this script for testing. + This script installs and configures basic tools for running a Proxmox Server. Following settings are made: - Disable `pve-enterprise` repo @@ -8,3 +10,4 @@ Following settings are made: - Install basic tools: `vim ifupdown2 net-tools dnsutils ethtool git curl unzip screen iftop lshw smartmontools nvme-cli lsscsi sysstat zfs-auto-snapshot htop mc rpl` - Configure snapshot retention for `zfs-auto-snapshot` - Set limits for level 1 arc (`zfs_arc_min` and `zfs_arc_max`) +- Configure backup of `/etc` Folder \ No newline at end of file From c9406c46f9181a1e326963e0a18fa23475500b7c Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 19:01:12 +0200 Subject: [PATCH 03/21] Added sudo, changed rsync command --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 9f36c92..e14b861 100644 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ ###### CONFIG SECTION ###### # Define basic tools to install -TOOLS="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 @@ -151,4 +151,4 @@ if [ $? -ne 0 ] zfs create $PVE_CONF_BACKUP_TARGET fi -echo "$PVE_CONF_BACKUP_CRON_TIMER root rsync -rtvupo /etc /$PVE_CONF_BACKUP_TARGET" > /etc/cron.d/pve-conf-backup \ No newline at end of file +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 \ No newline at end of file From 01268655e7e9bd28d152d5fc27e9a66cda271cde Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 20:39:58 +0200 Subject: [PATCH 04/21] Multiple syntax errors fixed --- install.sh | 89 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/install.sh b/install.sh index e14b861..513dc2b 100644 --- a/install.sh +++ b/install.sh @@ -5,29 +5,20 @@ # 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" -# 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 ###### #### L1ARC SIZE CONFIGURATION #### # get total size of all zpools -ZPOOL_SIZE_SUM_BYTES=0 -zpool list -o size -Hp | while read size_per_pool; do - ZPOOL_SIZE_SUM_BYTES=$(($ZPOOL_SIZE_SUM_BYTES + $size_per_pool)) -done +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 # get information about available ram MEM_TOTAL_BYTES=$(free -tb | tail -1 | cut -d ' ' -f3) # get values if defaults are set -ARC_MAX_DEFAULT_BYTES=$((MEM_TOTAL / 2)) -ARC_MIN_DEFAULT_BYTES=$((MEM_TOTAL / 32)) +ARC_MAX_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 2)) +ARC_MIN_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 32)) # get current settings 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 "System Summary:" -echo -e "\tSystem Memory:\t$(($MEM_TOTAL_BYTES / 1024 / 1024)) MB" -echo -e "\tZpool size (sum):\t$(($ZPOOL_SIZE_SUM_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))\tMB" echo -e "Calculated l1arc if set to defaults:" 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 - 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 -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:" -if [ $ARC_MIN_SET_BYTES > 0]; then - echo -e "\tCurrent zfs_arc_min:\t$(($ARC_MIN_SET_BYTES / 1024 / 1024)) MB" +if [ $ARC_MIN_SET_BYTES > 0 ]; then + echo -e "\tCurrent zfs_arc_min:\t$(($ARC_MIN_SET_BYTES / 1024 / 1024))\tMB" else echo -e "\tCurrent zfs_arc_min:\t0" fi -if [ $ARC_MAX_SET_BYTES > 0]; then - echo -e "\tCurrent zfs_arc_max:\t$(($ARC_MAX_SET_BYTES / 1024 / 1024)) MB" +if [ $ARC_MAX_SET_BYTES > 0 ]; then + echo -e "\tCurrent zfs_arc_max:\t$(($ARC_MAX_SET_BYTES / 1024 / 1024))\tMB" 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 "" -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 "zfs_arc_min=\t$(($ZFS_ARC_MIN_BYTES / 1024 / 1024)) MB" -echo "zfs_arc_max=\t$(($ZFS_ARC_MAX_BYTES / 1024 / 1024)) MB" +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" echo "" RESULT=not_set -while [[ "$(echo $RESULT | awk '{print tolower($0)}')" != "y" ]] && [[ "$(echo $RESULT | awk '{print tolower($0)}')" != "n"]]; do - echo "You can now adjust the l1arc values. Change settings [y/N]?" +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]?" read RESULT=${REPLY} 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))]:" read if [[ ${REPLY} -gt 0 ]]; then - $ZFS_ARC_MIN_BYTES=$((${REPLY} * 1024 * 1024)) + ZFS_ARC_MIN_BYTES=$((${REPLY} * 1024 * 1024)) 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 - $ZFS_ARC_MAX_BYTES=$((${REPLY} * 1024 * 1024)) + ZFS_ARC_MAX_BYTES=$((${REPLY} * 1024 * 1024)) fi fi #### ZFS AUTO SNAPSHOT CONFIGURATION #### # get information about zfs-auto-snapshot and ask for snapshot retention -dpkg -l zfs-auto-snapshot -declare -A auto_snap_keep -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 -else - for interval in "${auto_snap_keep[@]}"; do +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 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 - 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 done +else + echo "'zfs-auto-snapshot' not installed yet, using scrpit defaults..." fi 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]})" read if [ "${auto_snap_keep[$interval]}" != "${REPLY}" ]; then - auto_snap_keep["$interval"]=${REPLY} + auto_snap_keep[$interval]=${REPLY} fi 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 ###### # 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 # configure zfs-auto-snapshot -for interval in "${auto_snap_keep[@]}"; do +for interval in "${!auto_snap_keep[@]}"; do 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 @@ -129,7 +133,7 @@ for interval in "${auto_snap_keep[@]}"; do fi else CURRENT=$(cat /etc/cron.$interval/zfs-auto-snapshot | grep keep | cut -d' ' -f6 | cut -d'=' -f2) - if [[ "${auto_snap_keep[$interval]}" != "$CURRENT"]]; then + if [[ "${auto_snap_keep[$interval]}" != "$CURRENT" ]]; then rpl "keep=$CURRENT" "keep=${auto_snap_keep[$interval]}" /etc/cron.$interval/zfs-auto-snapshot fi fi @@ -146,8 +150,7 @@ update-initramfs -u -k all # create backup jobs of /etc zfs list $PVE_CONF_BACKUP_TARGET - -if [ $? -ne 0 ] +if [ $? -ne 0 ]; then zfs create $PVE_CONF_BACKUP_TARGET fi From f6d252ad6ba7207cadb29fd024c8a5c98ea62c58 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 20:40:12 +0200 Subject: [PATCH 05/21] Created .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c63957 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +ZPOOL_SIZE_SUM_BYTES From 56bd17927ba566e32e5a22a94c8a1a38131d7155 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 22:00:22 +0200 Subject: [PATCH 06/21] Fixed setting auto-snapshot keep values --- install.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 513dc2b..e5a9264 100644 --- a/install.sh +++ b/install.sh @@ -12,6 +12,7 @@ TOOLS="sudo vim ifupdown2 net-tools dnsutils ethtool git curl unzip screen iftop # get total size of all zpools 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 +rm -f ./ZPOOL_SIZE_SUM_BYTES # get information about available ram MEM_TOTAL_BYTES=$(free -tb | tail -1 | cut -d ' ' -f3) @@ -40,12 +41,12 @@ else fi echo -e "\tDefault zfs_arc_max:\t$(($ARC_MAX_DEFAULT_BYTES / 1024 / 1024))\tMB" 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))\tMB" else echo -e "\tCurrent zfs_arc_min:\t0" 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))\tMB" else echo -e "\tCurrent zfs_arc_max:\t0" @@ -95,10 +96,12 @@ else fi echo -e "######## CONFIGURE ZFS AUTO SNAPSHOT ########\n" for interval in "${!auto_snap_keep[@]}"; do - echo "Please set how many $interval snapshots to keep (current: keep=${auto_snap_keep[$interval]})" - read - if [ "${auto_snap_keep[$interval]}" != "${REPLY}" ]; then - auto_snap_keep[$interval]=${REPLY} + read -p "Please set how many $interval snapshots to keep (current: keep=${auto_snap_keep[$interval]})" user_input + if echo "$user_input" | grep -qE '^[0-9]+$'; then + echo "Changing $interval from ${auto_snap_keep[$interval]} to $user_input" + auto_snap_keep[$interval]=$user_input + else + echo "No input - $interval unchanged." fi done From 2b3e039be539bf2e6cfc207dc8a52bda958d6c0d Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Sat, 24 Apr 2021 22:12:18 +0200 Subject: [PATCH 07/21] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d25352c..2be4251 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,6 @@ Following settings are made: - Add `pve-no-subscription` repo - Upgrade system to latest version - Install basic tools: `vim ifupdown2 net-tools dnsutils ethtool git curl unzip screen iftop lshw smartmontools nvme-cli lsscsi sysstat zfs-auto-snapshot htop mc rpl` -- Configure snapshot retention for `zfs-auto-snapshot` -- Set limits for level 1 arc (`zfs_arc_min` and `zfs_arc_max`) -- Configure backup of `/etc` Folder \ No newline at end of file +- Configure snapshot retention for `zfs-auto-snapshot` interactively +- Calculates limits for level 1 arc (`zfs_arc_min` and `zfs_arc_max`) and asks you to apply or to input your preferences +- Configure backup of `/etc` folder to new zfs dataset on `rpool/pveconf` From 363990b37340a08e16a25d2f1ea2193fdccef06d Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 22:45:22 +0200 Subject: [PATCH 08/21] Fixed detection of current arc sizes --- install.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index e5a9264..b1a8fd9 100644 --- a/install.sh +++ b/install.sh @@ -22,8 +22,8 @@ ARC_MAX_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 2)) ARC_MIN_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 32)) # 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) +ARC_MIN_CUR_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_min) +ARC_MAX_CUR_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_max) # calculate suggested l1arc sice ZFS_ARC_MIN_BYTES=$(($ZPOOL_SIZE_SUM_BYTES / 4096)) @@ -41,13 +41,13 @@ else fi echo -e "\tDefault zfs_arc_max:\t$(($ARC_MAX_DEFAULT_BYTES / 1024 / 1024))\tMB" echo -e "Current l1arc configuration:" -if [[ $ARC_MIN_SET_BYTES > 0 ]]; then - echo -e "\tCurrent zfs_arc_min:\t$(($ARC_MIN_SET_BYTES / 1024 / 1024))\tMB" +if [ $ARC_MIN_CUR_BYTES -gt 0 ]; then + echo -e "\tCurrent zfs_arc_min:\t$(($ARC_MIN_CUR_BYTES / 1024 / 1024))\tMB" else echo -e "\tCurrent zfs_arc_min:\t0" fi -if [[ $ARC_MAX_SET_BYTES > 0 ]]; then - echo -e "\tCurrent zfs_arc_max:\t$(($ARC_MAX_SET_BYTES / 1024 / 1024))\tMB" +if [ $ARC_MAX_CUR_BYTES -gt 0 ]; then + echo -e "\tCurrent zfs_arc_max:\t$(($ARC_MAX_CUR_BYTES / 1024 / 1024))\tMB" else echo -e "\tCurrent zfs_arc_max:\t0" fi From 701273ea91c3a81dea83e3310f3fb8c826f72c9c Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 23:01:44 +0200 Subject: [PATCH 09/21] Fixed total memory detection --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index b1a8fd9..b2ff209 100644 --- a/install.sh +++ b/install.sh @@ -15,7 +15,7 @@ source ./ZPOOL_SIZE_SUM_BYTES rm -f ./ZPOOL_SIZE_SUM_BYTES # get information about available ram -MEM_TOTAL_BYTES=$(free -tb | tail -1 | cut -d ' ' -f3) +MEM_TOTAL_BYTES=$(($(awk '/MemTotal/ {print $2}' /proc/meminfo) * 1024)) # get values if defaults are set ARC_MAX_DEFAULT_BYTES=$(($MEM_TOTAL_BYTES / 2)) From 9c048b1dc05a35787488ef360f2b529b4f946143 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Sat, 24 Apr 2021 23:31:10 +0200 Subject: [PATCH 10/21] Added lsb-release, check if pve --- install.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index b2ff209..e0f383d 100644 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ ###### CONFIG SECTION ###### # 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 lsb-release" ###### SYSTEM INFO AND INTERACTIVE CONFIGURATION SECTION ###### @@ -92,7 +92,7 @@ if [ $? -eq 0 ]; then fi done else - echo "'zfs-auto-snapshot' not installed yet, using scrpit defaults..." + echo "'zfs-auto-snapshot' not installed yet, using script defaults..." fi echo -e "######## CONFIGURE ZFS AUTO SNAPSHOT ########\n" for interval in "${!auto_snap_keep[@]}"; do @@ -119,8 +119,10 @@ PVE_CONF_BACKUP_CRON_TIMER="*/15 * * * *" ###### INSTALLER SECTION ###### # 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 -echo "deb http://download.proxmox.com/debian/pve buster pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list +if [[ "$(uname -r)" == *"-pve" ]]; then + mv /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak + echo "deb http://download.proxmox.com/debian/pve buster pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list +fi apt update # update system and install basic tools From 724447b02cd3704243cf5c6f3453d6f87b0ce1ed Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Sun, 25 Apr 2021 11:24:16 +0200 Subject: [PATCH 11/21] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 2be4251..a096e8c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # proxmox-zfs-postinstall -`devel` branch is still under heavy development, so only use this script for testing. - This script installs and configures basic tools for running a Proxmox Server. Following settings are made: - Disable `pve-enterprise` repo From b8e46f35bc1dbf0d35972be88e73e62337b22410 Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Sun, 25 Apr 2021 14:26:56 +0200 Subject: [PATCH 12/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a096e8c..00c2887 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Following settings are made: - Disable `pve-enterprise` repo - Add `pve-no-subscription` repo - Upgrade system to latest version -- Install basic tools: `vim ifupdown2 net-tools dnsutils ethtool git curl unzip screen iftop lshw smartmontools nvme-cli lsscsi sysstat zfs-auto-snapshot htop mc rpl` +- Install basic 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` - Configure snapshot retention for `zfs-auto-snapshot` interactively - Calculates limits for level 1 arc (`zfs_arc_min` and `zfs_arc_max`) and asks you to apply or to input your preferences - Configure backup of `/etc` folder to new zfs dataset on `rpool/pveconf` From 1b99df1e62ce318d6879fead6233b0c7486cffad Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Mon, 26 Apr 2021 19:04:50 +0200 Subject: [PATCH 13/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 00c2887..e349e1b 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,5 @@ Following settings are made: - Upgrade system to latest version - Install basic 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` - Configure snapshot retention for `zfs-auto-snapshot` interactively -- Calculates limits for level 1 arc (`zfs_arc_min` and `zfs_arc_max`) and asks you to apply or to input your preferences +- Calculates limits for level 1 arc (`zfs_arc_min` and `zfs_arc_max`) based on the your allover zpool storage - Configure backup of `/etc` folder to new zfs dataset on `rpool/pveconf` From 72a8029d0983bcab3b0eeca05f35bce3fd6c4246 Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Mon, 26 Apr 2021 19:05:26 +0200 Subject: [PATCH 14/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e349e1b..9b19134 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,5 @@ Following settings are made: - Upgrade system to latest version - Install basic 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` - Configure snapshot retention for `zfs-auto-snapshot` interactively -- Calculates limits for level 1 arc (`zfs_arc_min` and `zfs_arc_max`) based on the your allover zpool storage +- Calculates limits for level 1 arc (`zfs_arc_min` and `zfs_arc_max`) based on all configured zpools - Configure backup of `/etc` folder to new zfs dataset on `rpool/pveconf` From ce7974740505dd7963a65531eb1811bb3a85cb7e Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Mon, 26 Apr 2021 22:23:42 +0200 Subject: [PATCH 15/21] Renamed inastall.sh, small fixes --- install.sh => proxmox-zfs-postinstall.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename install.sh => proxmox-zfs-postinstall.sh (97%) diff --git a/install.sh b/proxmox-zfs-postinstall.sh similarity index 97% rename from install.sh rename to proxmox-zfs-postinstall.sh index e0f383d..4da9eda 100644 --- a/install.sh +++ b/proxmox-zfs-postinstall.sh @@ -111,8 +111,8 @@ done # 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 * * * *" +# Define timer for your backup cronjob (default: every 15 minutes fron 3 through 59) +PVE_CONF_BACKUP_CRON_TIMER="3/15 * * * *" @@ -154,9 +154,9 @@ EOF update-initramfs -u -k all # create backup jobs of /etc -zfs list $PVE_CONF_BACKUP_TARGET +zfs list $PVE_CONF_BACKUP_TARGET > /dev/null 2>&1 if [ $? -ne 0 ]; then zfs create $PVE_CONF_BACKUP_TARGET fi -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 \ No newline at end of file +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 From 6e63bb9b08f63e2048303a927dc653839c2ce294 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Wed, 28 Apr 2021 09:54:58 +0200 Subject: [PATCH 16/21] Replaced while by for loop, adjust rsync params --- proxmox-zfs-postinstall.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/proxmox-zfs-postinstall.sh b/proxmox-zfs-postinstall.sh index 4da9eda..36e5fed 100644 --- a/proxmox-zfs-postinstall.sh +++ b/proxmox-zfs-postinstall.sh @@ -10,9 +10,8 @@ TOOLS="sudo vim ifupdown2 net-tools dnsutils ethtool git curl unzip screen iftop #### L1ARC SIZE CONFIGURATION #### # get total size of all zpools -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 -rm -f ./ZPOOL_SIZE_SUM_BYTES +ZPOOL_SIZE_SUM_BYTES=0 +for line in $(zpool list -o size -Hp); do ZPOOL_SIZE_SUM_BYTES=$(($ZPOOL_SIZE_SUM_BYTES+$line)); done # get information about available ram MEM_TOTAL_BYTES=$(($(awk '/MemTotal/ {print $2}' /proc/meminfo) * 1024)) @@ -59,11 +58,11 @@ echo -e "zfs_arc_max:\t\t\t$(($ZFS_ARC_MAX_BYTES / 1024 / 1024))\tMB\t\t= 1 GB R echo "" RESULT=not_set 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]?" + echo "If you want to apply the values by script policy type 'y', type 'n' to adjust the values yourself [Y/n]?" read RESULT=${REPLY} done -if [[ "$(echo $RESULT | awk '{print tolower($0)}')" == "y" ]]; then +if [[ "$(echo $RESULT | awk '{print tolower($0)}')" == "n" ]]; 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 @@ -159,4 +158,4 @@ if [ $? -ne 0 ]; then zfs create $PVE_CONF_BACKUP_TARGET fi -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 +echo "$PVE_CONF_BACKUP_CRON_TIMER root rsync -va --delete /etc /$PVE_CONF_BACKUP_TARGET > /$PVE_CONF_BACKUP_TARGET/pve-conf-backup.log" > /etc/cron.d/pve-conf-backup From 54662fbb7765a6c4f8e24d3bbada0ce316c125bf Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Wed, 28 Apr 2021 14:21:05 +0200 Subject: [PATCH 17/21] Suppress outputs and generate messages --- proxmox-zfs-postinstall.sh | 39 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/proxmox-zfs-postinstall.sh b/proxmox-zfs-postinstall.sh index 36e5fed..75cd5b3 100644 --- a/proxmox-zfs-postinstall.sh +++ b/proxmox-zfs-postinstall.sh @@ -100,7 +100,7 @@ for interval in "${!auto_snap_keep[@]}"; do echo "Changing $interval from ${auto_snap_keep[$interval]} to $user_input" auto_snap_keep[$interval]=$user_input else - echo "No input - $interval unchanged." + echo "No input - $interval unchanged at ${auto_snap_keep[$interval]}." fi done @@ -119,30 +119,45 @@ PVE_CONF_BACKUP_CRON_TIMER="3/15 * * * *" # disable pve-enterprise repo and add pve-no-subscription repo if [[ "$(uname -r)" == *"-pve" ]]; then - mv /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak + echo "Deactivating pve-enterprise repository" + mv /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak > /dev/null 2>&1 + echo "Activating pve-no-subscription repository" echo "deb http://download.proxmox.com/debian/pve buster pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list fi -apt update +echo "Getting latest package lists" +apt update > /dev/null 2>&1 # update system and install basic tools -DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq dist-upgrade -DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq install $TOOLS +echo "Upgrading system to latest version - Depending on your version this could take a while..." +DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq dist-upgrade > /dev/null 2>&1 +echo "Installing toolset - Depending on your version this could take a while..." +DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq install $TOOLS > /dev/null 2>&1 # configure zfs-auto-snapshot for interval in "${!auto_snap_keep[@]}"; do + echo "Setting zfs-auto-snapchot retention: $interval = ${auto_snap_keep[$interval]}" 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 + rpl "keep=$CURRENT" "keep=${auto_snap_keep[$interval]}" /etc/cron.d/zfs-auto-snapshot > /dev/null 2>&1 fi else CURRENT=$(cat /etc/cron.$interval/zfs-auto-snapshot | grep keep | cut -d' ' -f6 | cut -d'=' -f2) if [[ "${auto_snap_keep[$interval]}" != "$CURRENT" ]]; then - rpl "keep=$CURRENT" "keep=${auto_snap_keep[$interval]}" /etc/cron.$interval/zfs-auto-snapshot + rpl "keep=$CURRENT" "keep=${auto_snap_keep[$interval]}" /etc/cron.$interval/zfs-auto-snapshot > /dev/null 2>&1 fi fi done +echo "Configuring pve-conf-backup" +# create backup jobs of /etc +zfs list $PVE_CONF_BACKUP_TARGET > /dev/null 2>&1 +if [ $? -ne 0 ]; then + zfs create $PVE_CONF_BACKUP_TARGET +fi +echo "$PVE_CONF_BACKUP_CRON_TIMER root rsync -va --delete /etc /$PVE_CONF_BACKUP_TARGET > /$PVE_CONF_BACKUP_TARGET/pve-conf-backup.log" > /etc/cron.d/pve-conf-backup + +echo "Adjusting ZFS level 1 arc" echo $ZFS_ARC_MIN_BYTES > /sys/module/zfs/parameters/zfs_arc_min echo $ZFS_ARC_MAX_BYTES > /sys/module/zfs/parameters/zfs_arc_max @@ -150,12 +165,8 @@ 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 -# create backup jobs of /etc -zfs list $PVE_CONF_BACKUP_TARGET > /dev/null 2>&1 -if [ $? -ne 0 ]; then - zfs create $PVE_CONF_BACKUP_TARGET -fi +echo "Updating initramfs - This will take some time..." +update-initramfs -u -k all > /dev/null 2>&1 -echo "$PVE_CONF_BACKUP_CRON_TIMER root rsync -va --delete /etc /$PVE_CONF_BACKUP_TARGET > /$PVE_CONF_BACKUP_TARGET/pve-conf-backup.log" > /etc/cron.d/pve-conf-backup +echo "Proxmox postinstallation finished!" \ No newline at end of file From 55051975d6fe21f5221b05e398e6d9d08eef1688 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Wed, 28 Apr 2021 14:46:24 +0200 Subject: [PATCH 18/21] Moved pveconf-backup conf vars to top --- proxmox-zfs-postinstall.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/proxmox-zfs-postinstall.sh b/proxmox-zfs-postinstall.sh index 75cd5b3..a0eebe6 100644 --- a/proxmox-zfs-postinstall.sh +++ b/proxmox-zfs-postinstall.sh @@ -5,6 +5,16 @@ # 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 lsb-release" +#### 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 fron 3 through 59) +PVE_CONF_BACKUP_CRON_TIMER="3/15 * * * *" + + ###### SYSTEM INFO AND INTERACTIVE CONFIGURATION SECTION ###### #### L1ARC SIZE CONFIGURATION #### @@ -104,17 +114,6 @@ for interval in "${!auto_snap_keep[@]}"; do fi 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 fron 3 through 59) -PVE_CONF_BACKUP_CRON_TIMER="3/15 * * * *" - - - ###### INSTALLER SECTION ###### # disable pve-enterprise repo and add pve-no-subscription repo @@ -135,7 +134,7 @@ DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -y -qq install $TOOL # configure zfs-auto-snapshot for interval in "${!auto_snap_keep[@]}"; do - echo "Setting zfs-auto-snapchot retention: $interval = ${auto_snap_keep[$interval]}" + echo "Setting zfs-auto-snapshot retention: $interval = ${auto_snap_keep[$interval]}" 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 From 78d4560cce3e694f4b281ff4019c57c0af5cf159 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Wed, 28 Apr 2021 23:29:35 +0200 Subject: [PATCH 19/21] Round up / off zfs arc sizes --- proxmox-zfs-postinstall.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/proxmox-zfs-postinstall.sh b/proxmox-zfs-postinstall.sh index a0eebe6..45f08eb 100644 --- a/proxmox-zfs-postinstall.sh +++ b/proxmox-zfs-postinstall.sh @@ -17,6 +17,16 @@ PVE_CONF_BACKUP_CRON_TIMER="3/15 * * * *" ###### SYSTEM INFO AND INTERACTIVE CONFIGURATION SECTION ###### +ROUND_FACTOR=512 + +roundup(){ + echo $(((($1 + $ROUND_FACTOR) / $ROUND_FACTOR) * $ROUND_FACTOR)) +} + +roundoff(){ + echo $((($1 / $ROUND_FACTOR) * $ROUND_FACTOR)) +} + #### L1ARC SIZE CONFIGURATION #### # get total size of all zpools @@ -35,8 +45,8 @@ ARC_MIN_CUR_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_min) ARC_MAX_CUR_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_max) # calculate suggested l1arc sice -ZFS_ARC_MIN_BYTES=$(($ZPOOL_SIZE_SUM_BYTES / 4096)) -ZFS_ARC_MAX_BYTES=$(($ZPOOL_SIZE_SUM_BYTES / 1024)) +ZFS_ARC_MIN_MEGABYTES=$(roundoff $(($ZPOOL_SIZE_SUM_BYTES / 2048 / 1024 / 1024))) +ZFS_ARC_MAX_MEGABYTES=$(roundup $(($ZPOOL_SIZE_SUM_BYTES / 1024 / 1024 / 1024))) echo -e "######## CONFIGURE ZFS L1ARC SIZE ########\n" echo "System Summary:" @@ -63,8 +73,8 @@ fi echo -e "Note: If your current values are 0, the calculated values above will apply." echo "" 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" +echo -e "zfs_arc_min:\t\t\t$(($ZFS_ARC_MIN_MEGABYTES))\tMB\t\t= 512 MB RAM per 1 TB ZFS storage (round off in 512 MB steps)" +echo -e "zfs_arc_max:\t\t\t$(($ZFS_ARC_MAX_MEGABYTES))\tMB\t\t= 1 GB RAM per 1 TB ZFS storage (round up in 512 MB steps)" echo "" RESULT=not_set while [ "$(echo $RESULT | awk '{print tolower($0)}')" != "y" ] && [ "$(echo $RESULT | awk '{print tolower($0)}')" != "n" ] && [ "$(echo $RESULT | awk '{print tolower($0)}')" != "" ]; do @@ -73,15 +83,15 @@ while [ "$(echo $RESULT | awk '{print tolower($0)}')" != "y" ] && [ "$(echo $RES RESULT=${REPLY} done if [[ "$(echo $RESULT | awk '{print tolower($0)}')" == "n" ]]; 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_MEGABYTES))]:" read if [[ ${REPLY} -gt 0 ]]; then - ZFS_ARC_MIN_BYTES=$((${REPLY} * 1024 * 1024)) + ZFS_ARC_MIN_MEGABYTES=$((${REPLY})) 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_MEGABYTES))]:" read if [[ ${REPLY} -gt 0 ]]; then - ZFS_ARC_MAX_BYTES=$((${REPLY} * 1024 * 1024)) + ZFS_ARC_MAX_MEGABYTES=$((${REPLY})) fi fi @@ -156,6 +166,9 @@ if [ $? -ne 0 ]; then fi echo "$PVE_CONF_BACKUP_CRON_TIMER root rsync -va --delete /etc /$PVE_CONF_BACKUP_TARGET > /$PVE_CONF_BACKUP_TARGET/pve-conf-backup.log" > /etc/cron.d/pve-conf-backup +ZFS_ARC_MIN_BYTES=$((ZFS_ARC_MIN_MEGABYTES * 1024 *1024)) +ZFS_ARC_MAX_BYTES=$((ZFS_ARC_MAX_MEGABYTES * 1024 *1024)) + echo "Adjusting ZFS level 1 arc" echo $ZFS_ARC_MIN_BYTES > /sys/module/zfs/parameters/zfs_arc_min echo $ZFS_ARC_MAX_BYTES > /sys/module/zfs/parameters/zfs_arc_max From 52fc06c66f0670f48262ae0d21ec4e3c5129080b Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Wed, 28 Apr 2021 23:39:01 +0200 Subject: [PATCH 20/21] Swapped ruond for arc min/max --- proxmox-zfs-postinstall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxmox-zfs-postinstall.sh b/proxmox-zfs-postinstall.sh index 45f08eb..07f2678 100644 --- a/proxmox-zfs-postinstall.sh +++ b/proxmox-zfs-postinstall.sh @@ -45,8 +45,8 @@ ARC_MIN_CUR_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_min) ARC_MAX_CUR_BYTES=$(cat /sys/module/zfs/parameters/zfs_arc_max) # calculate suggested l1arc sice -ZFS_ARC_MIN_MEGABYTES=$(roundoff $(($ZPOOL_SIZE_SUM_BYTES / 2048 / 1024 / 1024))) -ZFS_ARC_MAX_MEGABYTES=$(roundup $(($ZPOOL_SIZE_SUM_BYTES / 1024 / 1024 / 1024))) +ZFS_ARC_MIN_MEGABYTES=$(roundup $(($ZPOOL_SIZE_SUM_BYTES / 2048 / 1024 / 1024))) +ZFS_ARC_MAX_MEGABYTES=$(roundoff $(($ZPOOL_SIZE_SUM_BYTES / 1024 / 1024 / 1024))) echo -e "######## CONFIGURE ZFS L1ARC SIZE ########\n" echo "System Summary:" From 50387018a473db1720f3c9a3cf18b8eba9abcba6 Mon Sep 17 00:00:00 2001 From: thorstenspille Date: Fri, 30 Apr 2021 23:35:23 +0200 Subject: [PATCH 21/21] Added swappiness configuration --- proxmox-zfs-postinstall.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/proxmox-zfs-postinstall.sh b/proxmox-zfs-postinstall.sh index 07f2678..6465b2c 100644 --- a/proxmox-zfs-postinstall.sh +++ b/proxmox-zfs-postinstall.sh @@ -95,6 +95,19 @@ if [[ "$(echo $RESULT | awk '{print tolower($0)}')" == "n" ]]; then fi fi +#### SWAPPINESS #### + +echo -e "######## CONFIGURE SWAPPINESS ########\n" +SWAPPINESS=$(cat /proc/sys/vm/swappiness) +echo "The current swappiness is configured to '$SWAPPINESS %' of free memory until using swap." +read -p "If you want to change the swappiness, please type in the percentage as number (0 = diasbled):" user_input +if echo "$user_input" | grep -qE '^[0-9]+$'; then + echo "Changing swappiness from '$SWAPPINESS %' to '$user_input %'" + SWAPPINESS=$user_input +else + echo "No input - swappiness unchanged at '$SWAPPINESS %'." +fi + #### ZFS AUTO SNAPSHOT CONFIGURATION #### # get information about zfs-auto-snapshot and ask for snapshot retention @@ -158,6 +171,10 @@ for interval in "${!auto_snap_keep[@]}"; do fi done +echo "Configuring swappiness" +echo "vm.swappiness=$SWAPPINESS" > /etc/sysctl.d/swappiness.conf +sysctl -w vm.swappiness=$SWAPPINESS + echo "Configuring pve-conf-backup" # create backup jobs of /etc zfs list $PVE_CONF_BACKUP_TARGET > /dev/null 2>&1