Creating an Optimised Ubuntu Swap Space with one simple script

A quick search on Google with throw up loads on swap files, if you want to read about what they are and how they work there is a good article over at Ubuntu help

If you want a good step by step setup guide explaining how to achieve each of the steps in the script manually head on over to the Digital Ocean setup article

Below is a script that automates all of the steps and results in everything being setup correctly.

Automated Swap File Setup Script

Create a file called swap and add the following to the file.

Upload it to your root folder /root/swap

Then simply run the file with this format:

Example (2G is enough usually):

The default path for the swap file is /swapfile. If you wish to change this, simple the file location (FILE MUST NOT EXIST) add it to the command:

based on and with thanks to CraftThatBlocks code

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.