Saturday, August 15, 2009

Modifying Swap file size

Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system from 1024 MB to 2048 MB, but there is only 2048 MB of swap space. It might be advantageous to increase the amount of swap space to 3072 MB if you perform memory-intense operations or run applications that require a large amount of memory.

You have two options: add a swap partition or add a swap file. It is recommended that you add a swap partition, but that can be difficult if you do not have any free space available.

The example below assumes you don’t have an additional free space available to create a partition so we will be adding a swap file to enable more swap space

To add a swap file:

Determine the size of the new swap file in megabytes and multiple by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536.

Here we want to add additional 1024 MB to increase the swap space to 3072 from 2048

1.At a shell prompt as root, type the following command with count being equal to the desired block size:

dd if=/dev/zero of=/swapfile bs=1048576 count=1024

2.Setup the swap file with the command:

mkswap /swapfile

3.To enable the swap file immediately but not automatically at boot time:

swapon /swapfile

4.To enable it at boot time, edit /etc/fstab to include:

Echo “/swapfile swap swap defaults 0 0” >> /etc/fstab

The next time the system boots, it enables the new swap file.

5.After adding the new swap file and enabling it, you can verify it is enabled by the following commands

# cat /proc/swaps

# free –m


To Remove a swap file

1.At a shell prompt as root, execute the following command to disable the swap file (where /swapfile is the swap file):

swapoff /swapfile

2.Remove its entry from /etc/fstab

3.Remove the actual file:

rm /swapfile

If you want to disable an additionally added swap partition use the swapoff on that partition and then remove the fstab entries

for eq:

swapoff /dev/hdb3

No comments:

Post a Comment