Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append script to create ZFS swap volume #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions proxmox-zfs-postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ if [[ "$(echo $RESULT | awk '{print tolower($0)}')" == "n" ]]; then
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 == "y" ]; then
read -p "Name for the swap dataset? Leave empty to use default 'swap'" swapfile_userinput_name
if [ x$swapfile_userinput_name == "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 ####

echo -e "######## CONFIGURE SWAPPINESS ########\n"
Expand Down Expand Up @@ -213,6 +237,19 @@ for interval in "${!auto_snap_keep[@]}"; do
fi
done


if [ $swapfile_userinput_bool == "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 "vm.swappiness=$SWAPPINESS" > /etc/sysctl.d/swappiness.conf
sysctl -w vm.swappiness=$SWAPPINESS
Expand Down