These are the procedures I followed for Ubuntu 14.04 LTS but should work with other Debian distros.
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo swapon -s
Once you’ve done this you could make this permanent by editing the /etc/fstab file:
/swapfile none swap sw 0 0
If you’re using CentOS 7, Patrick in comments points out:
- The fallocate failed if you did not use ‘sudo’.
- the ‘swapon’ command failed on the root xfs, moved swap to ext works fine.
Thank you for this very helpful posting.
On a GC CentOS 7 VM:
1) The fallocate failed if you did not use ‘sudo’.
2) the ‘swapon’ command failed on the root xfs, moved swap to ext works fine.
It would be an interesting experiment to add two separate disks for swap, a small 2G SSD and a regular disk with remaining swap size requirement with SSD-swap of higher priority.
Thanks for the tip Patrick! I’ve included into the main post.
can you paste the command when using centos7
Thanks, clear simple explanations, works fine! I’m running on the tiniest instance so just 1G.
Glad I could help!