I have good results on my Ubuntu 17.04 following the advice of Arian Acosta from the blogpost. One can substitute the 4G here sudo fallocate -l 4G /swapfile
with any amount of gigabytes you want. For example sudo fallocate -l 2G /swapfile
for TS.
Generally speaking, the recommended size for a swap file is 2X the amount of RAM, but you can make it as big as you need. Remember that this is not a substitute for memory because performance is much worse since things are stored in the disk.
I’ve created a simple bash script that increments the swap file to 4GB and tested it on Ubuntu 16.04.
This can be run line by line or a bash script, but I use it to make headless installations.
#!/bin/bash
echo "====== Current Swap ======"
sudo swapon -s
echo "====== Turning Off Swap ======"
sudo swapoff /swapfile
echo "====== Allocating 4GB Swap ======"
sudo fallocate -l 4G /swapfile
echo "====== Making Swap ======"
sudo mkswap /swapfile
echo "====== Setting Permissions to Root Only ======"
sudo chmod 600 /swapfile
echo "====== Turning On Swap ======"
sudo swapon /swapfile
echo "====== Current Swap ======"
sudo swapon -s
echo "====== Done! ======"
swapoff
, create a new /swapfile,mkswap
, andswapon -a
– heynnema Jun 21 '17 at 21:16swapoff
thendd
andmkswap
finallyswapon
. I thought you don't want to touch your file. – Ravexina Jun 21 '17 at 21:29