Add temporary swap

Categories General Info

While it would be ideal if every server had plenty of RAM, in the real world that does not happen. If for some reason you have a server with too little SWAP or you are hitting the max of the swap here is a quick hack which will create a 2Gb container file then use it for additional swap space on the server. To check the swap space used you can use free -m
Run the following from the command line to create the swap file

# dd if=/dev/zero of=/usr/swap-file bs=1024 count=2048000
# mkswap /usr/swap-file
# swapon /usr/swap-file
# swapon -s

Now add the following to the /etc/fstab file and you are done.

/usr/swap-file swap swap defaults 0 0

Leave a Reply

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