The system uses swap space as type of “virtual memory” for when your physical memory begins to run low. It does this by using piece of disk storage to swap files in and out of memory (hence, the term swap). This capability can be useful on systems that don’t have large amounts of physical memory or when your system is running something that become more intensive.
There a formula that you can remember when creating your own swap space:
if MEM < 2GB then SWAP = MEM*2 else SWAP = MEM+2GB
For example, if I have 512MB of memory, I can create 1GB of swap. Easy, huh?
Let’s create a swap partition, but this time I will use the parted utility instead of fdisk.
Remember to verify that the partition is set up correctly by using print command.
Create Swap File
There’s another way to create your swap. It’s called Swap File. Before you start to create Swap file, please login as root.
As you can see, I created a 512MB Swap file (1024 * 512MB = 524288 block size). I verify that the swap space is activated or not by using “free -m” command. If you want to active the swap space until next reboot, you can edit file /etc/fstab as below:
echo /swapfile1 swap swap defaults 0 0 >> /etc/fstab
Have fun!