Showing posts with label Creating More Swap Space with Swapfile on RHEL. Show all posts
Showing posts with label Creating More Swap Space with Swapfile on RHEL. Show all posts

Tuesday, August 3, 2010

How to add more Swap Space on Red Hat Linux System if you are left with no free Hard Disk space to create a new partition for Swap

You installed a new Linux system, but forgot to set enough swap space for your needs. Do you need to repartition and reinstall? No, the swap utilities on Linux allow you to make a real file and use it as swap space even if you have no free space to make another swap partition.

The trick is to make a file and then tell the swapon program to use it. Here's how to create, for example, a 512 MB swap file on your root partition (of course make sure you have at least 512 MB free on the filesystem on which you are going to create it):

#dd if=/dev/zero of=/swapfile bs=1024 count=524288

This will make a 512 MB file on your hard drive. You now need to initialize it:

#mkswap /swapfile 524288
#sync

And you can then add it to your swap pool:

#swapon /swapfile

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