bakerkretzmar
12/10/2019 - 4:05 PM

swap.sh

# Check for existence/name of swapfile
ls -A /
sudo swapon --show

# Stop, resize, and restart:
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
sudo mkswap /swapfile
sudo swapon /swapfile

# If there isn't enough memory to do that, make a new one:
sudo fallocate -l 2G /swapfile2
sudo mkswap /swapfile2
sudo swapon /swapfile2
sudo swapoff /swapfile
sudo rm /swapfile
# Repeat so we end up with just 'swapfile' again
sudo fallocate -l 2G /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapoff /swapfile2
sudo rm /swapfile2

# Verify
sudo swapon -s