Hi, Guest!
+

How to add swap on Debian Linux

05-05-2013 linux Roumen

Linux swaps allow a system to harness more memory than was originally physically available. However, swapping does have disadvantages, because hard disks have a much slower memory than RAM, your server performance may slow down considerably.

Before you proceed to set up a swap file, you need to check if any swap files have been enabled on the server by looking at the summary of swap usage.

swapon -s

An empty list will confirm that you have no swap files enabled.

After you know that you don't have a swap file enabled on your server, you can check how much space you have on the server with the "df" command. The swap file will take x2 your RAM, if your server have 256MB RAM, it will need swap file with size 512MB. To create it:

dd if=/dev/zero of=/swapfile bs=1024 count=512k

Finish up by activating the swap file:

mkswap /swapfile

You can ensure that the swap is permanent by adding it to the fstab file:

swapon /swapfile

Open up the file:

nano /etc/fstab

Paste in the following line:

/swapfile       none    swap    sw      0       0 

This is it, now you have successfully added a swap file to your server.