make-swapfile

This commit is contained in:
2025-03-18 13:45:29 +08:00
parent 50bd28abe4
commit 8531543982

31
tools/make-swapfile.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/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