Linux needs swap space or virtual memory to expand the real memory (RAM), and believe me it won’t work as expected all the time if there is no sufficient swap space. Swap space usually is setup as a separate partition which is set during installation or later by the system administrator. But sometimes you need to create extra space for virtual memory for any purpose (Oracle installation for example). But if you don’t want to mess up with your hard disk, here is a simple way to create a file which serves as a swap partition. Execute the following commands as root user in a folder in as partition which has enough disk space
dd if=/dev/zero of=swap.swp bs=1024k count=1024 mkswap swap.swp swapon swap.swp
The first line created a file called swap.swp from /dev/zero (fill the file with zeros), with 1024 sectors 1024KB each, which makes 1GB file. Then in the second line tells Linux to format, or prepare, the file as swap. In the next line, turn on the swap space included in the file and adds it to current virtual memory.