6. January 2012 06:00
This is a quick guide to adding emergancy swap space to linux. Which is useful when you know a machine is going to run out memory. Or you need a lot of memory for a single task that cannot be completed without the extra memory.
Step 1
Login as root
Step 2
Create a new file of the size that you want to add using the following command. In this case 512 mbytes of space.
dd if=/dev/zero of=/extraswap1 bs=1024 count=512k
Step 3
Fix the permissions on the file so that only the creator can read / write to it.
chmod 0600 /extraswap1
Step 4
Turn it into a swap file and tell linux to turn on the extra space
mkswap /extraswap1
swapon /extraswap1
Step 5
If you want the swap to be enabled after the next reboot of the machine you will need to add the following line to /etc/fstab
/extraswap1 swap swap defaults 0 0
Finally
You can verify that it is working by either using free or by looking directly at the proc filesystem using cat /proc/swaps
f4835f36-6076-4a30-83e3-ca935d64c751|0|.0