I urgently needed Swap space but i hadn’t created a swap partition before. Then I Googled about the problem and found a useful solution which allowed me to add swap space without the need of creating swap partition.
1. First, create a large empty file:
Replace 1000 with the size of the swap file desired, in MB. You can also put the swap_file in a different location if desired.
2. Next, we’ll secure the swapspace, so ordinary users cannot read the contents (potential security breach):
sudo chmod 600 /swap_file
3. Then, turn it into swap space:
4. Next, turn it on:
5. To make it turn on at every bootup, open up /etc/fstab:
6. Add this line to the end of the file:
If u get Error swapon: Access denied at step 4 then there is some problem with your installation or you are usings a VPS. Most of the VPS providers disable this option. Contact them
Source: Ubuntu Forums