First, create an empty file, of the size you want.
dd if=/dev/zero of=/mnt/my_swap bs=1M count=2048
The above creates an empty file of size 2GB, called mnt/my_swap. To create a file of a different size, replace the 2048 with the size of swap file you require, in MB.
Next, format the file as swap space:
Then tell the operating system to begin using it:
Finally, to persist the change, and ensure the OS uses the new swap file on every boot, open /etc/fstab and add the following line:
/mnt/my_swap none swap sw 0 0
To open /etc/fstab, you can use gedit with this line:
Additionally, to check the current swap spaces in use by the system, you can use:
With thanks to DistroWatch Weekly, Issue 388, 17 January 2011 for this information!