Files
shell/tools/make-swapfile.sh
2025-03-18 13:45:29 +08:00

32 lines
629 B
Bash
Executable File

#!/bin/bash
set -exo pipefail
# https://www.linode.com/docs/guides/how-to-increase-swap-space-in-ubuntu/
# https://help.ubuntu.com/community/SwapFaq
sudo swapon --show
free -h
df -h
if [ -f /swapfile ]; then
set +x
echo "Already exists"
exit 1
fi;
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
free -h
df -h
sudo cp /etc/fstab /etc/fstab.bak
echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=50
echo "vm.swappiness=50" | sudo tee -a /etc/fstab
sudo swapon --show