Jumat, 01 April 2011

Create a File Swap

How do I add more swap?

Swap is generally associated with a swap partition, perhaps because the user is prompted to create a swap partition at the time of installation. In fact, any file can be used as a swapping device, be it a partition or a conventional file. Although, to improve the responsiveness, it's recommended to have a good sized amount of RAM available. Swap can be added by adding a swap file. Keep in mind that when creating a swap file that it may not necessarily be using contiguous disk blocks (as a swap partition will), and this could have a negative impact on performance as disk access times may be longer and the more your system uses swap, the worse it will be. The Linux kernel also accesses swap disk block IO directly bypassing all caching, metadata and filesystem code, so a swap file should have no ill effect on the stability of your base filesystem.

Four-step Process to Add Swap

Creating a file the size you want.
Formatting that file to create a swapping device.
Adding the swap to the running system.
Making the change permanent.

For Adding a 512 MB swap

Creating a file for 512 MB size you want:

We will create a /mnt/512Mb.swap swap file and set the permissions so that users cannot read it directly.

sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512
sudo chmod 600 /mnt/512Mb.swap

Here count=512, means we want our file to contain 512 blocks of bs=1M, which means block size = 1 mebibyte (1 048 576 bytes). Be careful *not* to do this dd of=/mnt/512Mb.swap bs=1M seek=512 count=0 Though the file grows to 512Mb immediately, it will have holes that makes it unusable.

By default your swap file may be created world readable. We set the 600 mode permissions in order to prevent users from being able to read potentially sensitive information from the swap file.

Formatting that file to create a swapping device:

sudo mkswap /mnt/512Mb.swap

Adding the swap to the running system:

sudo swapon /mnt/512Mb.swap

The additional swap is now available and can be seen by "cat /proc/meminfo"

Making the change permanent:

Edit the /etc/fstab:

gksudo gedit /etc/fstab

Add this line at the end of the file:

/mnt/512Mb.swap none swap sw 0 0

Save. After the next reboot the swap will be used automatically.

Tidak ada komentar:

Posting Komentar

nyuwun komentar... . .

za.IPAN's Blog © 2008. Design by :Yanku Templates Sponsored by: Tutorial87 Commentcute