This can be a very handy function if we want to use a file, instead of a partition, and with modern filesystems the performance is almost on par with using a dedicated partition for your swap area.
1. Using dd lets make a zero’d file for the swap
dd if=/dev/zero of=/swapfile bs=1048576 count=1000This example would create a swapfile of 1 gig using a blocksize of a megabyte (1048576).
2. Make file as a swapfile
mkswp /swapfile3. Activate swapfile
swapon /swapfile4. Verify that our swapfile has been activated
swapon -sWe should see something like this in the list ..
Filename Type Size Used PriorityIf you want to have this a permanent solution, then adding the entry to fstab would probally be a better idea,
/swapfile file 9999992 0 -2
open up /etc/fstab in your favourite editor and add the following line.
/swapfile swap swap defaults 0 0










