Quick way to add SWAP

Posted in: HELP! Guides |

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”.

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 and you are done.

/usr/swap-file swap swap defaults 0 0

Leave a Reply