Saturday, November 29, 2008

How to increase SWAP space in linux

Adding more swap space is very easy in Linux, all you need to have is some free hard disk space. Say for some weird reason you need to increase your swap space by say 500MB, then this is how you can go about adding it.

Firstly, create a file of 500MB using 'dd'
dd if=/dev/zero of=/home/swapfile bs=1k count=500000
then set appropriate permissions for the file
chmod 600 swapfile
make it a swap file
mkswap swapfile
and finally activate it
swapon swapfile
That's it, you have just added 500MB of swap space. You can check the swap size using the 'free' command. In future if you want to remove the swap space, then do the following

turn swap off
swapoff swapfile
delete the file
rm swapfile


That's it.