You normally don’t want your servers using swap space because of the performance hit that occurs but for some operations you just can’t get around it. I’ve covered how to create a swap file before but what the swap you’ve created isn’t large enough?

This process turns out to be easy but it’s hard to locate all the information on the Internet. Because you’re disabling the swap on a server you should make sure you have enough available RAM so your processes won’t crash due to a lack of RAM. I ran this process at a time with low load so there weren’t any problems.

As always when there’s a potential for damage, I take no responsibility for any loss of data/problems you may have.

Disable the Swap

root@server:~# swapoff -v /extraswap
swapoff on /extraswap

This process can take a long time as your data is brought back into RAM. I started to freak out the first time.

Recreate the Swap File

root@server:~# dd if=/dev/zero of=/extraswap bs=1M count=3024
3024+0 records in
3024+0 records out
3170893824 bytes (3.2 GB) copied, 20.3343 s, 156 MB/s

Format the File

root@server:~# mkswap /extraswap
Setting up swapspace version 1, size = 3096572 KiB
no label, UUID=f062d60b-643e-40bd-b012-9b8b666b5bb2

Turn the Swap On

root@server:~# swapon -a

Like this post? Don't forget to follow us on Twitter and Facebook for updates.