Update proxmox-zfs-postinstall.sh, add sections for creating a zfs swapfile volume

This commit is contained in:
Simon Hoffmann 2023-10-10 22:27:14 +02:00 committed by GitHub
parent ba1c8f854f
commit 4105a6b2d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,6 +94,30 @@ if [[ "$(echo $RESULT | awk '{print tolower($0)}')" == "n" ]]; then
fi fi
fi fi
#### Create Swapfile ####
echo -e "######## Configure Swapfile ########\n"
read -p "With the default PVE-root on ZFS installation, no swap is created. Do you want to create a swapfile/zfs swap volume dataset? (y/n)" swapfile_userinput_bool
if [ $swapfile_userinput_bool -eq "y" ]; then
read -p "Name for the swap dataset? Leave empty to use default 'swap'" swapfile_userinput_name
if [ x$swapfile_userinput_name -eq "x" ]; then
swapfile_name = "swap";
else
swapfile_name = $swapfile_userinput_name;
fi
read -p "Size for the swap volume in G, only numbers" swapfile_userinput_size
if echo "$swapfile_userinput_size" | grep -qE '^[0-9]+$'; then
swapfile_size = $swapfile_userinput_size;
else
echo "No valid input detected, falling back to 20G Swap Size";
swapfile_size = "20";
fi
else
echo "No swapfile will be created"
fi
#### SWAPPINESS #### #### SWAPPINESS ####
echo -e "######## CONFIGURE SWAPPINESS ########\n" echo -e "######## CONFIGURE SWAPPINESS ########\n"
@ -213,6 +237,19 @@ for interval in "${!auto_snap_keep[@]}"; do
fi fi
done done
if [ $swapfile_userinput_bool -eq "y" ]; then
echo "Creating swapfile"
zfs create -V ${swapfile_size}G -b $(getconf PAGESIZE) -o logbias=throughput -o sync=always -o primarycache=metadata -o com.sun:auto-snapshot=false rpool/$swapfile_name
echo "Formatting swapfile"
mkswap -f /dev/zvol/rpool/$swapfile_name
echo "Turning on swap"
swapon /dev/zvol/rpool/$swapfile_name
echo "Adding swapfile to fstab"
echo "/dev/zvol/rpool/$swapfile_name none swap discard 0 0" >> /etc/fstab
fi
echo "Configuring swappiness" echo "Configuring swappiness"
echo "vm.swappiness=$SWAPPINESS" > /etc/sysctl.d/swappiness.conf echo "vm.swappiness=$SWAPPINESS" > /etc/sysctl.d/swappiness.conf
sysctl -w vm.swappiness=$SWAPPINESS sysctl -w vm.swappiness=$SWAPPINESS