X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=vps-addswap%2Finstall.sh;fp=vps-addswap%2Finstall.sh;h=f1f559f859ba2e40b96c4062fb363406f62256ff;hb=adbc9eafa00944e718345fc045429ea826730eab;hp=0000000000000000000000000000000000000000;hpb=42b2963ee042c4813783552ab762388a2f335948;p=webi-installers%2F.git diff --git a/vps-addswap/install.sh b/vps-addswap/install.sh new file mode 100644 index 0000000..f1f559f --- /dev/null +++ b/vps-addswap/install.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +{ + set -e + set -u + + default_size=2G + my_size=${1:-$default_size} + + # Allocate a swapfile + fallocate -l "$my_size" /var/swapfile + + # Only allow root to read it + # (this is not sufficient security for sensitive data) + chmod 0600 /var/swapfile + + # Activate the swap + mkswap /var/swapfile + swapon /var/swapfile + + # Cause swap to be activated on boot + echo '/var/swapfile none swap sw 0 0' | tee -a /etc/fstab + +}