Creating a swap file

In linux, disk space that's used as memory storage is called swap. Typically you would setup a separate disk partition as a swap partition, but from time to time it is convenient to add swap to a running system. (creating an additional partition generally requires a reboot)

A swap file can be created with the following commands:

dd if=/dev/zero of=/extra-swap bs=1024 count=1048576 # create a 1Gb file
mkswap /extra-swap 1048576 # format the file as swap
swapon /extra-swap # start swap file

# add swap to fstab so it is automatically started
/extra-swap none swap sw 0 0

Walla, an additional 1GB of swap is now available. This can be confirmed by using the free command.