Sunday, March 15, 2009

More swap with a swap file ...

There are situations when either you have a pre-installed Linux system or a new one, but forgot to set enough swap space for your needs or you recently have upgraded your hardware (like I have recently added an additional RAM on my machine :) ).

Now, to make the most of the hardware that you've got, you might consider to increase the swap space. What do you do now? Do you need to repartition and reinstall the system? Answer is NO! Linux offers you with fascinating swap utilities to make a real file and use it as swap space. The trick is to make a file and then tell the swapon program to use it.

Here's how to create, for example, a 64 megs swap file on your root partition (of course make sure you have at least 64 megs free):
dd if=/dev/zero of=/swapfile bs=1024 count=65536


This will make a 64 megs (about 67 millions bytes) file on your hard drive. You now need to initialize it:
mkswap /swapfile 65536

sync

And you can then add it to your swap pool:
swapon /swapfile


With that you have 64 megs of swap added. Don't forget to add the swapon command to your startup files so the command will be repeated at each reboot.

No comments: